+ability to choose ogr layer by index number
This commit is contained in:
parent
0706b4fbaa
commit
7e2a2aab5a
3 changed files with 36 additions and 6 deletions
|
@ -14,6 +14,8 @@ For a complete change history, see the SVN log.
|
|||
Mapnik Trunk
|
||||
------------
|
||||
|
||||
- Added support for choosing OGR layer by index number using 'layer_by_index' parameter (r1904)
|
||||
|
||||
- Added support for reading jpeg images (in addition to png/tiff) for image symbolizers (#518)
|
||||
|
||||
- Made libjpeg dependency optional at compile time and added mapnik2.has_jpeg() method to check for support in python (#545).
|
||||
|
|
|
@ -493,9 +493,10 @@ def Ogr(**keywords):
|
|||
|
||||
Required keyword arguments:
|
||||
file -- path to OGR supported dataset
|
||||
layer -- layer to use within datasource
|
||||
layer -- name of layer to use within datasource (optional if layer_by_index is used)
|
||||
|
||||
Optional keyword arguments:
|
||||
layer_by_index -- choose layer by index number instead of by layer name.
|
||||
base -- path prefix (default None)
|
||||
encoding -- file encoding (default 'utf-8')
|
||||
multiple_geometries -- boolean, direct the Mapnik wkb reader to interpret as multigeometries (default False)
|
||||
|
|
|
@ -67,6 +67,8 @@ ogr_datasource::ogr_datasource(parameters const& params)
|
|||
boost::optional<std::string> file = params.get<std::string>("file");
|
||||
if (!file) throw datasource_exception("missing <file> parameter");
|
||||
|
||||
boost::optional<unsigned> layer_idx = params.get<unsigned>("layer_by_index");
|
||||
|
||||
multiple_geometries_ = *params_.get<mapnik::boolean>("multiple_geometries",false);
|
||||
|
||||
boost::optional<std::string> base = params.get<std::string>("base");
|
||||
|
@ -88,7 +90,30 @@ ogr_datasource::ogr_datasource(parameters const& params)
|
|||
}
|
||||
|
||||
// initialize layer
|
||||
|
||||
boost::optional<std::string> layer = params.get<std::string>("layer");
|
||||
|
||||
if (layer_idx && !layer)
|
||||
{
|
||||
OGRLayer *ogr_layer = dataset_->GetLayer(*layer_idx);
|
||||
if (ogr_layer)
|
||||
{
|
||||
OGRFeatureDefn* def = ogr_layer->GetLayerDefn();
|
||||
if (def != 0) {
|
||||
layerName_ = def->GetName();
|
||||
layer_ = ogr_layer;
|
||||
}
|
||||
/*else
|
||||
{
|
||||
throw datasource_exception("No layers found!");
|
||||
}*/
|
||||
}
|
||||
/*else
|
||||
{
|
||||
throw datasource_exception("No layers found!");
|
||||
}*/
|
||||
}
|
||||
|
||||
if (!layer)
|
||||
{
|
||||
std::string s ("missing <layer> parameter, available layers are: ");
|
||||
|
@ -107,10 +132,12 @@ ogr_datasource::ogr_datasource(parameters const& params)
|
|||
}
|
||||
throw datasource_exception(s);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
layerName_ = *layer;
|
||||
layer_ = dataset_->GetLayerByName (layerName_.c_str());
|
||||
if (! layer_) throw datasource_exception("cannot find <layer> in dataset");
|
||||
}
|
||||
|
||||
// initialize envelope
|
||||
OGREnvelope envelope;
|
||||
|
|
Loading…
Reference in a new issue