39737c5f1d
Conflicts: .travis.yml CHANGELOG.md bindings/python/build.py include/mapnik/feature_style_processor_context.hpp include/mapnik/feature_style_processor_impl.hpp include/mapnik/json/feature_collection_grammar.hpp include/mapnik/json/feature_collection_parser.hpp include/mapnik/json/feature_generator_grammar.hpp include/mapnik/json/feature_parser.hpp include/mapnik/json/geojson_generator.hpp include/mapnik/json/geometry_generator_grammar.hpp include/mapnik/json/geometry_parser.hpp plugins/input/gdal/gdal_featureset.cpp plugins/input/geojson/geojson_datasource.cpp plugins/input/occi/occi_featureset.cpp plugins/input/osm/osm_featureset.cpp plugins/input/postgis/build.py plugins/input/postgis/connection.hpp src/agg/agg_renderer.cpp src/build.py src/cairo_context.cpp src/datasource_cache.cpp src/grid/process_line_symbolizer.cpp src/grid/process_polygon_pattern_symbolizer.cpp src/grid/process_polygon_symbolizer.cpp src/grid/process_text_symbolizer.cpp src/json/feature_grammar.cpp tests/cpp_tests/fontset_runtime_test.cpp tests/visual_tests/images/collision-600-400-1.0-agg-reference.png tests/visual_tests/images/image-filters-multi-blur-512-512-1.0-agg-reference.png tests/visual_tests/images/image-filters-multi-blur-512-512-2.0-agg-reference.png tests/visual_tests/images/image-filters-multi-blur-inflate-512-512-1.0-agg-reference.png tests/visual_tests/images/image-filters-multi-blur-inflate-512-512-2.0-agg-reference.png tests/visual_tests/images/lines-1-400-400-2.0-agg-reference.png tests/visual_tests/images/lines-1-600-600-1.0-agg-reference.png tests/visual_tests/images/lines-1-600-600-2.0-agg-reference.png tests/visual_tests/images/lines-2-200-200-1.0-agg-reference.png tests/visual_tests/images/lines-2-400-400-1.0-cairo-reference.png tests/visual_tests/images/lines-2-400-400-2.0-agg-reference.png tests/visual_tests/images/lines-2-600-600-2.0-agg-reference.png tests/visual_tests/images/lines-2-800-800-2.0-agg-reference.png tests/visual_tests/images/lines-3-400-400-2.0-agg-reference.png tests/visual_tests/images/lines-3-600-600-1.0-agg-reference.png tests/visual_tests/images/lines-3-600-600-2.0-agg-reference.png tests/visual_tests/images/lines-5-200-200-1.0-agg-reference.png tests/visual_tests/images/lines-5-200-200-2.0-agg-reference.png tests/visual_tests/images/lines-5-400-400-1.0-agg-reference.png tests/visual_tests/images/lines-5-400-400-2.0-agg-reference.png tests/visual_tests/images/lines-5-600-600-1.0-agg-reference.png tests/visual_tests/images/lines-5-600-600-2.0-agg-reference.png tests/visual_tests/images/lines-5-800-800-1.0-agg-reference.png tests/visual_tests/images/lines-5-800-800-2.0-agg-reference.png tests/visual_tests/images/lines-6-200-200-1.0-agg-reference.png tests/visual_tests/images/lines-6-200-200-2.0-agg-reference.png tests/visual_tests/images/lines-6-400-400-1.0-agg-reference.png tests/visual_tests/images/lines-6-600-600-1.0-agg-reference.png tests/visual_tests/images/lines-6-600-600-2.0-agg-reference.png tests/visual_tests/images/lines-6-800-800-1.0-agg-reference.png tests/visual_tests/images/lines-6-800-800-2.0-agg-reference.png tests/visual_tests/images/lines-shield-600-600-2.0-agg-reference.png tests/visual_tests/images/lines-shield-600-600-2.0-cairo-reference.png tests/visual_tests/images/shield-on-polygon-600-400-1.0-agg-reference.png tests/visual_tests/images/shield-on-polygon-600-400-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-1-490-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-1-495-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-1-495-100-2.0-cairo-reference.png tests/visual_tests/images/shieldsymbolizer-1-497-100-1.0-cairo-reference.png tests/visual_tests/images/shieldsymbolizer-1-497-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-1-497-100-2.0-cairo-reference.png tests/visual_tests/images/shieldsymbolizer-1-498-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-1-499-100-1.0-cairo-reference.png tests/visual_tests/images/shieldsymbolizer-1-499-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-1-499-100-2.0-cairo-reference.png tests/visual_tests/images/shieldsymbolizer-1-500-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-1-501-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-1-502-100-1.0-cairo-reference.png tests/visual_tests/images/shieldsymbolizer-1-502-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-1-505-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-1-505-100-2.0-cairo-reference.png tests/visual_tests/images/shieldsymbolizer-1-510-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-3-490-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-3-495-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-3-497-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-3-498-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-3-499-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-3-500-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-3-501-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-3-502-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-3-505-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-3-510-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-4-490-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-4-495-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-4-497-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-4-498-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-4-499-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-4-500-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-4-501-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-4-502-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-4-505-100-2.0-agg-reference.png tests/visual_tests/images/shieldsymbolizer-4-510-100-2.0-agg-reference.png tests/visual_tests/test.py
128 lines
4.6 KiB
C++
128 lines
4.6 KiB
C++
|
|
/*****************************************************************************
|
|
*
|
|
* This file is part of Mapnik (c++ mapping toolkit)
|
|
*
|
|
* Copyright (C) 2011 Artem Pavlenko
|
|
*
|
|
* This library is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
* License as published by the Free Software Foundation; either
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
*
|
|
* This library is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
* License along with this library; if not, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
*
|
|
*****************************************************************************/
|
|
|
|
// mapnik
|
|
#include <mapnik/std.hpp>
|
|
#include <mapnik/geometry.hpp>
|
|
#include <mapnik/feature.hpp>
|
|
#include <mapnik/feature_factory.hpp>
|
|
#include <mapnik/debug.hpp>
|
|
#include <mapnik/unicode.hpp>
|
|
|
|
// boost
|
|
|
|
#include "osm_featureset.hpp"
|
|
|
|
using mapnik::feature_ptr;
|
|
using mapnik::geometry_type;
|
|
using mapnik::feature_factory;
|
|
|
|
template <typename filterT>
|
|
osm_featureset<filterT>::osm_featureset(const filterT& filter,
|
|
osm_dataset* dataset,
|
|
const std::set<std::string>&
|
|
attribute_names,
|
|
std::string const& encoding)
|
|
: filter_(filter),
|
|
query_ext_(),
|
|
tr_(new transcoder(encoding)),
|
|
dataset_ (dataset),
|
|
attribute_names_ (attribute_names),
|
|
ctx_(std::make_shared<mapnik::context_type>())
|
|
{
|
|
dataset_->rewind();
|
|
}
|
|
|
|
template <typename filterT>
|
|
feature_ptr osm_featureset<filterT>::next()
|
|
{
|
|
feature_ptr feature;
|
|
|
|
osm_item* cur_item = dataset_->next_item();
|
|
if (!cur_item) return feature_ptr();
|
|
if (dataset_->current_item_is_node())
|
|
{
|
|
feature = feature_factory::create(ctx_, cur_item->id);
|
|
double lat = static_cast<osm_node*>(cur_item)->lat;
|
|
double lon = static_cast<osm_node*>(cur_item)->lon;
|
|
std::unique_ptr<geometry_type> point = std::make_unique<geometry_type>(mapnik::geometry_type::types::Point);
|
|
point->move_to(lon, lat);
|
|
feature->add_geometry(point.release());
|
|
}
|
|
else if (dataset_->current_item_is_way())
|
|
{
|
|
// Loop until we find a feature which passes the filter
|
|
while (cur_item)
|
|
{
|
|
bounds b = static_cast<osm_way*>(cur_item)->get_bounds();
|
|
if (filter_.pass(box2d<double>(b.w, b.s, b.e, b.n))
|
|
&&
|
|
static_cast<osm_way*>(cur_item)->nodes.size()) break;
|
|
cur_item = dataset_->next_item();
|
|
}
|
|
|
|
if (!cur_item) return feature_ptr();
|
|
feature = feature_factory::create(ctx_, cur_item->id);
|
|
mapnik::geometry_type::types geom_type = mapnik::geometry_type::types::LineString;
|
|
if (static_cast<osm_way*>(cur_item)->is_polygon())
|
|
{
|
|
geom_type = mapnik::geometry_type::types::Polygon;
|
|
}
|
|
std::unique_ptr<geometry_type> geom = std::make_unique<geometry_type>(geom_type);
|
|
|
|
geom->move_to(static_cast<osm_way*>(cur_item)->nodes[0]->lon,
|
|
static_cast<osm_way*>(cur_item)->nodes[0]->lat);
|
|
|
|
for (unsigned int count = 1;
|
|
count < static_cast<osm_way*>(cur_item)->nodes.size();
|
|
count++)
|
|
{
|
|
geom->line_to(static_cast<osm_way*>(cur_item)->nodes[count]->lon,
|
|
static_cast<osm_way*>(cur_item)->nodes[count]->lat);
|
|
}
|
|
feature->add_geometry(geom.release());
|
|
}
|
|
else
|
|
{
|
|
MAPNIK_LOG_ERROR(osm_featureset) << "Current item is neither node nor way.\n";
|
|
}
|
|
|
|
std::set<std::string>::const_iterator itr = attribute_names_.begin();
|
|
std::set<std::string>::const_iterator end = attribute_names_.end();
|
|
std::map<std::string,std::string>::iterator end_keyvals = cur_item->keyvals.end();
|
|
for (; itr != end; itr++)
|
|
{
|
|
std::map<std::string,std::string>::iterator i = cur_item->keyvals.find(*itr);
|
|
if (i != end_keyvals)
|
|
{
|
|
feature->put_new(i->first, tr_->transcode(i->second.c_str()));
|
|
}
|
|
}
|
|
return feature;
|
|
}
|
|
|
|
template <typename filterT>
|
|
osm_featureset<filterT>::~osm_featureset() {}
|
|
|
|
template class osm_featureset<mapnik::filter_in_box>;
|
|
template class osm_featureset<mapnik::filter_at_point>;
|