diff --git a/plugins/input/geojson/geojson_datasource.cpp b/plugins/input/geojson/geojson_datasource.cpp index 70e86ec50..27c6973c9 100644 --- a/plugins/input/geojson/geojson_datasource.cpp +++ b/plugins/input/geojson/geojson_datasource.cpp @@ -42,6 +42,7 @@ #include #include #include +#include #include 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 geojson_datasource::get_geometry_type() const { - return boost::optional(); + boost::optional 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(*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(); } diff --git a/tests/python_tests/geojson_plugin_test.py b/tests/python_tests/geojson_plugin_test.py index f13b83f3f..0002a8cdf 100644 --- a/tests/python_tests/geojson_plugin_test.py +++ b/tests/python_tests/geojson_plugin_test.py @@ -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)