don't throw for OGR layers with no features - refs #2260 #2352 #2354

This commit is contained in:
Dane Springmeyer 2014-08-15 19:48:27 -07:00
parent 422f3bd8b0
commit 0be6c2d7e1
3 changed files with 40 additions and 4 deletions

View file

@ -264,11 +264,18 @@ void ogr_datasource::init(mapnik::parameters const& params)
OGREnvelope envelope; OGREnvelope envelope;
OGRErr e = layer->GetExtent(&envelope); OGRErr e = layer->GetExtent(&envelope);
if (e == OGRERR_FAILURE) if (e == OGRERR_FAILURE)
{
if (layer->GetFeatureCount() == 0)
{
MAPNIK_LOG_ERROR(ogr) << "could not determine extent, layer '" << layer->GetName() << "' appears to have no features";
}
else
{ {
std::ostringstream s; std::ostringstream s;
s << "OGR Plugin: Extent missing for layer '" << layer->GetName() << "'. Use <extent> paramater to define a custom extent value."; 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()); throw datasource_exception(s.str());
} }
}
extent_.init(envelope.MinX, envelope.MinY, envelope.MaxX, envelope.MaxY); extent_.init(envelope.MinX, envelope.MinY, envelope.MaxX, envelope.MaxY);
} }

9
tests/data/gpx/empty.gpx Normal file
View file

@ -0,0 +1,9 @@
<?xml version="1.0" standalone="yes"?>
<gpx version="1.0">
<name>Empty GPX</name>
<desc></desc>
<wpt lat="48" lon="-122">
<ele>0</ele>
<time>2001-11-28T21:06:52Z</time>
</wpt>
</gpx>

View file

@ -63,6 +63,26 @@ if 'ogr' in mapnik.DatasourceCache.plugin_names():
eq_(e.maxx,1) eq_(e.maxx,1)
eq_(e.maxy,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. # disabled because OGR prints an annoying error: ERROR 1: Invalid Point object. Missing 'coordinates' member.
#def test_handling_of_null_features(): #def test_handling_of_null_features():