diff --git a/plugins/input/ogr/ogr_datasource.cpp b/plugins/input/ogr/ogr_datasource.cpp index ca7c6975a..61dad3920 100644 --- a/plugins/input/ogr/ogr_datasource.cpp +++ b/plugins/input/ogr/ogr_datasource.cpp @@ -254,7 +254,7 @@ void ogr_datasource::init(mapnik::parameters const& params) OGRLayer* layer = layer_.layer(); // initialize envelope - boost::optional ext = params.get("extent"); + boost::optional ext = params.get("extent"); if (ext && !ext->empty()) { extent_.from_string(*ext); @@ -265,9 +265,16 @@ void ogr_datasource::init(mapnik::parameters const& params) OGRErr e = layer->GetExtent(&envelope); if (e == OGRERR_FAILURE) { - std::ostringstream s; - s << "OGR Plugin: Extent missing for layer '" << layer->GetName() << "'. Use paramater to define a custom extent value."; - throw datasource_exception(s.str()); + if (layer->GetFeatureCount() == 0) + { + MAPNIK_LOG_ERROR(ogr) << "could not determine extent, layer '" << layer->GetName() << "' appears to have no features"; + } + else + { + std::ostringstream s; + s << "OGR Plugin: Cannot determine extent for layer '" << layer->GetName() << "'. Please provide a manual extent string (minx,miny,maxx,maxy)."; + throw datasource_exception(s.str()); + } } extent_.init(envelope.MinX, envelope.MinY, envelope.MaxX, envelope.MaxY); } diff --git a/tests/data/gpx/empty.gpx b/tests/data/gpx/empty.gpx new file mode 100644 index 000000000..dd03718e2 --- /dev/null +++ b/tests/data/gpx/empty.gpx @@ -0,0 +1,9 @@ + + +Empty GPX + + + 0 + + + \ No newline at end of file diff --git a/tests/python_tests/ogr_test.py b/tests/python_tests/ogr_test.py index 9720b9eec..eeb4acb25 100644 --- a/tests/python_tests/ogr_test.py +++ b/tests/python_tests/ogr_test.py @@ -63,6 +63,26 @@ if 'ogr' in mapnik.DatasourceCache.plugin_names(): eq_(e.maxx,1) eq_(e.maxy,1) + def test_ogr_reading_gpx_waypoint(): + ds = mapnik.Ogr(file='../data/gpx/empty.gpx',layer='waypoints') + e = ds.envelope() + eq_(e.minx,-122) + eq_(e.miny,48) + eq_(e.maxx,-122) + eq_(e.maxy,48) + + def test_ogr_empty_data_should_not_throw(): + default_logging_severity = mapnik.logger.get_severity() + mapnik.logger.set_severity(mapnik.severity_type.None) + # use logger to silence expected warnings + for layer in ['routes', 'tracks', 'route_points', 'track_points']: + ds = mapnik.Ogr(file='../data/gpx/empty.gpx',layer=layer) + e = ds.envelope() + eq_(e.minx,0) + eq_(e.miny,0) + eq_(e.maxx,0) + eq_(e.maxy,0) + mapnik.logger.set_severity(default_logging_severity) # disabled because OGR prints an annoying error: ERROR 1: Invalid Point object. Missing 'coordinates' member. #def test_handling_of_null_features():