update osm plugin to new geometry

This commit is contained in:
Dane Springmeyer 2015-03-22 15:46:27 -07:00
parent 7fae024e32
commit dca44f799b
2 changed files with 33 additions and 18 deletions

View file

@ -22,7 +22,7 @@
// mapnik
#include <mapnik/make_unique.hpp>
#include <mapnik/geometry.hpp>
#include <mapnik/geometry_impl.hpp>
#include <mapnik/feature.hpp>
#include <mapnik/feature_factory.hpp>
#include <mapnik/debug.hpp>
@ -33,7 +33,6 @@
#include "osm_featureset.hpp"
using mapnik::feature_ptr;
using mapnik::geometry_type;
using mapnik::feature_factory;
template <typename filterT>
@ -64,9 +63,7 @@ feature_ptr osm_featureset<filterT>::next()
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::new_geometry::geometry_types::Point);
point->move_to(lon, lat);
feature->add_geometry(point.release());
feature->set_geometry(mapnik::new_geometry::point(lon,lat));
}
else if (dataset_->current_item_is_way())
{
@ -82,24 +79,32 @@ feature_ptr osm_featureset<filterT>::next()
if (!cur_item) return feature_ptr();
feature = feature_factory::create(ctx_, cur_item->id);
mapnik::geometry_type::types geom_type = mapnik::new_geometry::geometry_types::LineString;
if (static_cast<osm_way*>(cur_item)->is_polygon())
{
geom_type = mapnik::new_geometry::geometry_types::Polygon;
mapnik::new_geometry::linear_ring ring;
for (unsigned int count = 0;
count < static_cast<osm_way*>(cur_item)->nodes.size();
count++)
{
ring.add_coord(static_cast<osm_way*>(cur_item)->nodes[count]->lon,
static_cast<osm_way*>(cur_item)->nodes[count]->lat);
}
mapnik::new_geometry::polygon geom;
geom.set_exterior_ring(std::move(ring));
feature->set_geometry(std::move(geom));
}
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++)
else
{
geom->line_to(static_cast<osm_way*>(cur_item)->nodes[count]->lon,
static_cast<osm_way*>(cur_item)->nodes[count]->lat);
mapnik::new_geometry::line_string geom;
for (unsigned int count = 0;
count < static_cast<osm_way*>(cur_item)->nodes.size();
count++)
{
geom.add_coord(static_cast<osm_way*>(cur_item)->nodes[count]->lon,
static_cast<osm_way*>(cur_item)->nodes[count]->lat);
}
feature->set_geometry(std::move(geom));
}
feature->add_geometry(geom.release());
}
else
{

View file

@ -41,11 +41,21 @@ if 'osm' in mapnik.DatasourceCache.plugin_names():
eq_(ds.field_types(),['str', 'str', 'str', 'str'])
fs = ds.featureset()
feat = fs.next()
eq_(feat.to_geojson(),'{"type":"Feature","id":890,"geometry":{"type":"Point","coordinates":[-61.7960248,17.1415874]},"properties":{}}')
eq_(feat.id(),4294968186)
eq_(feat['bigint'], None)
feat = fs.next()
eq_(feat['bigint'],'9223372036854775807')
def test_reading_ways():
ds = mapnik.Osm(file='../data/osm/ways.osm')
eq_(len(ds.fields()),0)
eq_(ds.fields(),[])
eq_(ds.field_types(),[])
feat = ds.all_features()[4]
eq_(feat.to_geojson(),'{"type":"Feature","id":1,"geometry":{"type":"LineString","coordinates":[[0,2],[0,-2]]},"properties":{}}')
eq_(feat.id(),1)
if __name__ == "__main__":
setup()