mirror of
https://github.com/mapnik/mapnik.git
synced 2025-12-08 20:13:09 +00:00
start reporting geometry type in geojson plugin
This commit is contained in:
parent
f334085079
commit
f5cf5aa09d
@ -42,6 +42,7 @@
|
||||
#include <mapnik/debug.hpp>
|
||||
#include <mapnik/proj_transform.hpp>
|
||||
#include <mapnik/projection.hpp>
|
||||
#include <mapnik/util/geometry_to_ds_type.hpp>
|
||||
#include <mapnik/json/feature_collection_parser.hpp>
|
||||
|
||||
using mapnik::datasource;
|
||||
@ -123,8 +124,7 @@ void geojson_datasource::bind() const
|
||||
bool result = p.parse(begin,end, features_);
|
||||
if (!result)
|
||||
{
|
||||
MAPNIK_LOG_WARN(geojson) << "geojson_datasource: Failed parse GeoJSON file " << file_;
|
||||
return;
|
||||
throw mapnik::datasource_exception("geojson_datasource: Failed parse GeoJSON file '" + file_ + "'");
|
||||
}
|
||||
|
||||
bool first = true;
|
||||
@ -162,7 +162,24 @@ const char * geojson_datasource::name()
|
||||
|
||||
boost::optional<mapnik::datasource::geometry_t> geojson_datasource::get_geometry_type() const
|
||||
{
|
||||
return boost::optional<mapnik::datasource::geometry_t>();
|
||||
boost::optional<mapnik::datasource::geometry_t> result;
|
||||
int multi_type = 0;
|
||||
unsigned num_features = features_.size();
|
||||
for (unsigned i = 0; i < num_features && i < 5; ++i)
|
||||
{
|
||||
mapnik::util::to_ds_type(features_[i]->paths(),result);
|
||||
if (result)
|
||||
{
|
||||
int type = static_cast<int>(*result);
|
||||
if (multi_type > 0 && multi_type != type)
|
||||
{
|
||||
result.reset(mapnik::datasource::Collection);
|
||||
return result;
|
||||
}
|
||||
multi_type = type;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
mapnik::datasource::datasource_t geojson_datasource::type() const
|
||||
@ -203,5 +220,6 @@ mapnik::featureset_ptr geojson_datasource::features(mapnik::query const& q) cons
|
||||
mapnik::featureset_ptr geojson_datasource::features_at_point(mapnik::coord2d const& pt) const
|
||||
{
|
||||
if (!is_bound_) bind();
|
||||
throw mapnik::datasource_exception("GeoJSON Plugin: features_at_point is not supported yet");
|
||||
return mapnik::featureset_ptr();
|
||||
}
|
||||
|
||||
@ -14,16 +14,19 @@ def setup():
|
||||
if 'geojson' in mapnik.DatasourceCache.instance().plugin_names():
|
||||
|
||||
def test_geojson_init():
|
||||
s = mapnik.Datasource(type='geojson',file='../data/json/escaped.json')
|
||||
e = s.envelope()
|
||||
ds = mapnik.Datasource(type='geojson',file='../data/json/escaped.json')
|
||||
e = ds.envelope()
|
||||
assert_almost_equal(e.minx, -81.705583, places=7)
|
||||
assert_almost_equal(e.miny, 41.480573, places=6)
|
||||
assert_almost_equal(e.maxx, -81.705583, places=5)
|
||||
assert_almost_equal(e.maxy, 41.480573, places=3)
|
||||
|
||||
def test_geojson_properties():
|
||||
s = mapnik.Datasource(type='geojson',file='../data/json/escaped.json')
|
||||
f = s.features_at_point(s.envelope().center()).features[0]
|
||||
ds = mapnik.Datasource(type='geojson',file='../data/json/escaped.json')
|
||||
f = ds.features_at_point(s.envelope().center()).features[0]
|
||||
|
||||
desc = ds.describe()
|
||||
eq_(desc['geometry_type'],mapnik.DataGeometryType.Point)
|
||||
|
||||
eq_(f['name'], u'test')
|
||||
eq_(f['description'], u'Test: \u005C')
|
||||
@ -34,8 +37,11 @@ if 'geojson' in mapnik.DatasourceCache.instance().plugin_names():
|
||||
eq_(f['NOM_FR'], u'Québec')
|
||||
|
||||
def test_geojson_properties():
|
||||
s = mapnik.Datasource(type='geojson',file='../data/json/escaped.json')
|
||||
f = s.all_features()[0]
|
||||
ds = mapnik.Datasource(type='geojson',file='../data/json/escaped.json')
|
||||
f = ds.all_features()[0]
|
||||
|
||||
desc = ds.describe()
|
||||
eq_(desc['geometry_type'],mapnik.DataGeometryType.Point)
|
||||
|
||||
eq_(f['name'], u'Test')
|
||||
eq_(f['int'], 1)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user