Merge pull request #2350 from kernelsanders/2.3.x
Add optional extent parameter to OGR datasource plugin
This commit is contained in:
commit
9d74adb871
2 changed files with 22 additions and 4 deletions
|
@ -254,9 +254,17 @@ void ogr_datasource::init(mapnik::parameters const& params)
|
|||
OGRLayer* layer = layer_.layer();
|
||||
|
||||
// initialize envelope
|
||||
OGREnvelope envelope;
|
||||
layer->GetExtent(&envelope);
|
||||
extent_.init(envelope.MinX, envelope.MinY, envelope.MaxX, envelope.MaxY);
|
||||
boost::optional<std::string> ext = params.get<std::string>("extent");
|
||||
if (ext && !ext->empty())
|
||||
{
|
||||
extent_.from_string(*ext);
|
||||
}
|
||||
else
|
||||
{
|
||||
OGREnvelope envelope;
|
||||
layer->GetExtent(&envelope);
|
||||
extent_.init(envelope.MinX, envelope.MinY, envelope.MaxX, envelope.MaxY);
|
||||
}
|
||||
|
||||
// scan for index file
|
||||
// TODO - layer names don't match dataset name, so this will break for
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from nose.tools import *
|
||||
|
@ -54,6 +54,16 @@ if 'ogr' in mapnik.DatasourceCache.plugin_names():
|
|||
query.add_property_name('bogus')
|
||||
fs = ds.features(query)
|
||||
|
||||
# OGR plugin extent parameter
|
||||
def test_ogr_extent_parameter():
|
||||
ds = mapnik.Ogr(file='../data/shp/world_merc.shp',layer_by_index=0,extent='-1,-1,1,1')
|
||||
e = ds.envelope()
|
||||
eq_(e.minx,-1)
|
||||
eq_(e.miny,-1)
|
||||
eq_(e.maxx,1)
|
||||
eq_(e.maxy,1)
|
||||
|
||||
|
||||
# disabled because OGR prints an annoying error: ERROR 1: Invalid Point object. Missing 'coordinates' member.
|
||||
#def test_handling_of_null_features():
|
||||
# ds = mapnik.Ogr(file='../data/json/null_feature.geojson',layer_by_index=0)
|
||||
|
|
Loading…
Add table
Reference in a new issue