Commit c343d16a authored by Aashish Chaudhary's avatar Aashish Chaudhary Committed by Code Review
Browse files

Merge topic 'gdal-active-layer' into master

8e5b524b Shapefiles: If active layer specified, load only it.
parents 723a4691 8e5b524b
......@@ -46,6 +46,20 @@ int TestGDALVectorReader(int argc, char** argv)
vtkNew<vtkGDALVectorReader> reader;
reader->SetFileName(vectorFileName);
delete [] vectorFileName;
// Test layer information helpers
reader->UpdateInformation();
int nl = reader->GetNumberOfLayers();
for (int i = 0; i < nl; ++i)
{
reader->SetActiveLayer(i);
cout
<< "Layer " << i
<< " Type " << reader->GetActiveLayerType()
<< " FeatureCount " << reader->GetActiveLayerFeatureCount()
<< "\n";
}
reader->SetActiveLayer(0); // Read only layer 0, which is the only layer.
reader->Update();
// We need a renderer
......
......@@ -298,6 +298,7 @@ vtkGDALVectorReader::vtkGDALVectorReader()
{
this->FileName = 0;
this->Implementation = 0;
this->ActiveLayer = -1;
this->SetNumberOfInputPorts( 0 );
......@@ -408,13 +409,17 @@ int vtkGDALVectorReader::GetFeatureCount(int layerIndex)
// -----------------------------------------------------------------------------
int vtkGDALVectorReader::GetActiveLayerType()
{
return this->GetLayerType(ActiveLayer);
return
this->ActiveLayer < 0 || this->ActiveLayer >= this->GetNumberOfLayers() ?
-1 : this->GetLayerType(this->ActiveLayer);
}
// -----------------------------------------------------------------------------
int vtkGDALVectorReader::GetActiveLayerFeatureCount()
{
return this->GetFeatureCount(ActiveLayer);
return
this->ActiveLayer < 0 || this->ActiveLayer >= this->GetNumberOfLayers() ?
0 : this->GetFeatureCount(this->ActiveLayer);
}
// -----------------------------------------------------------------------------
......@@ -492,7 +497,13 @@ int vtkGDALVectorReader::RequestData( vtkInformation* request,
vtkGDALVectorReader::Internal* p = this->Implementation;
for ( int layerIdx = 0; layerIdx < p->Source->GetLayerCount(); ++layerIdx )
int lastLayer = p->Source->GetLayerCount() - 1;
int startLayer =
this->ActiveLayer < 0 || this->ActiveLayer >= lastLayer ?
0 : this->ActiveLayer;
int endLayer = this->ActiveLayer < 0 || this->ActiveLayer >= lastLayer ?
lastLayer : this->ActiveLayer;
for ( int layerIdx = startLayer; layerIdx <= endLayer; ++layerIdx )
{
OGRLayer* layer = p->Source->GetLayer( layerIdx );
if ( ! layer )
......
......@@ -17,7 +17,10 @@
// vtkGDALVectorReader is a source object that reads vector files and uses
// GDAL as the underlying library for the task. GDAL is required for this
// reader. The output of the reader is a vtkMultiBlockDataSet
//
// This filter uses the ActiveLayer member to only load entries from the
// specified layer (when ActiveLayer >= 0).
//
// .SECTION See Also
// vtkMultiBlockDataSet
......@@ -60,7 +63,9 @@ public:
int GetActiveLayerFeatureCount();
// Description:
// Set and Get the active layer
// Set and Get the active layer.
// If ActiveLayer is less than 0 (the default is -1), then all
// layers are read. Otherwise, only the specified layer is read.
vtkSetMacro(ActiveLayer,int);
vtkGetMacro(ActiveLayer,int);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment