/***************************************************************************** * * 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 * *****************************************************************************/ // stl #include // mapnik #include #include #include "osm_featureset.hpp" using mapnik::Feature; using mapnik::feature_ptr; using mapnik::geometry_type; using mapnik::feature_factory; template osm_featureset::osm_featureset(const filterT& filter, osm_dataset* dataset, const std::set& attribute_names, std::string const& encoding) : filter_(filter), query_ext_(), tr_(new transcoder(encoding)), feature_id_(1), dataset_ (dataset), attribute_names_ (attribute_names), ctx_(boost::make_shared()) { dataset_->rewind(); } template feature_ptr osm_featureset::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_,feature_id_); ++feature_id_; double lat = static_cast(cur_item)->lat; double lon = static_cast(cur_item)->lon; geometry_type* point = new geometry_type(mapnik::Point); point->move_to(lon, lat); feature->add_geometry(point); } else if (dataset_->current_item_is_way()) { // Loop until we find a feature which passes the filter while (cur_item) { bounds b = static_cast(cur_item)->get_bounds(); if (filter_.pass(box2d(b.w, b.s, b.e, b.n))) break; cur_item = dataset_->next_item(); } if (!cur_item) return feature_ptr(); if (static_cast(cur_item)->nodes.size()) { feature = feature_factory::create(ctx_,feature_id_); ++feature_id_; geometry_type* geom; if (static_cast(cur_item)->is_polygon()) { geom = new geometry_type(mapnik::Polygon); } else { geom = new geometry_type(mapnik::LineString); } geom->move_to(static_cast(cur_item)->nodes[0]->lon, static_cast(cur_item)->nodes[0]->lat); for (unsigned int count = 1; count < static_cast(cur_item)->nodes.size(); count++) { geom->line_to(static_cast(cur_item)->nodes[count]->lon, static_cast(cur_item)->nodes[count]->lat); } feature->add_geometry(geom); } } std::set::const_iterator itr = attribute_names_.begin(); std::set::const_iterator end = attribute_names_.end(); std::map::iterator end_keyvals = cur_item->keyvals.end(); for (; itr != end; itr++) { std::map::iterator i = cur_item->keyvals.find(*itr); if (i != end_keyvals) { feature->put_new(i->first,tr_->transcode(i->second.c_str())); } else { feature->put_new(*itr, ""); } } return feature; } template osm_featureset::~osm_featureset() {} template class osm_featureset; template class osm_featureset;