1 /*========================================================================= 2 3 Program: Visualization Toolkit 4 Module: vtkGDALVectorReader.h 5 6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 7 All rights reserved. 8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 9 10 This software is distributed WITHOUT ANY WARRANTY; without even 11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 12 PURPOSE. See the above copyright notice for more information. 13 14 =========================================================================*/ 15 /** 16 * @class vtkGDALVectorReader 17 * @brief Read vector file formats using GDAL. 18 * 19 * vtkGDALVectorReader is a source object that reads vector files and uses 20 * GDAL as the underlying library for the task. GDAL is required for this 21 * reader. The output of the reader is a vtkMultiBlockDataSet 22 * 23 * This filter uses the ActiveLayer member to only load entries from the 24 * specified layer (when ActiveLayer >= 0). 25 * 26 * @sa 27 * vtkMultiBlockDataSet 28 */ 29 30 #ifndef vtkGDALVectorReader_h 31 #define vtkGDALVectorReader_h 32 33 #include "vtkMultiBlockDataSetAlgorithm.h" 34 #include "vtkIOGDALModule.h" // For export macro 35 36 #include <map> // STL required. 37 38 class VTKIOGDAL_EXPORT vtkGDALVectorReader : public vtkMultiBlockDataSetAlgorithm 39 { 40 public: 41 static vtkGDALVectorReader* New(); 42 void PrintSelf( ostream& os, vtkIndent indent ) override; 43 vtkTypeMacro(vtkGDALVectorReader,vtkMultiBlockDataSetAlgorithm); 44 45 vtkSetStringMacro(FileName); 46 vtkGetStringMacro(FileName); 47 48 /** 49 * Return number of layers. 50 */ 51 int GetNumberOfLayers(); 52 53 /** 54 * Given a index return layer type (eg point, line, polygon). 55 */ 56 int GetLayerType(int layerIndex=0); 57 58 /** 59 * Given a layer index return number of features (shapes). 60 */ 61 int GetFeatureCount(int layerIndex=0); 62 63 /** 64 * Return the active layer type (eg point, line, polygon). 65 */ 66 int GetActiveLayerType(); 67 68 /** 69 * Return the number of features in the active layer (shapes). 70 */ 71 int GetActiveLayerFeatureCount(); 72 73 //@{ 74 /** 75 * Set and Get the active layer. 76 * If ActiveLayer is less than 0 (the default is -1), then all 77 * layers are read. Otherwise, only the specified layer is read. 78 */ 79 vtkSetMacro(ActiveLayer,int); 80 vtkGetMacro(ActiveLayer,int); 81 //@} 82 83 //@{ 84 /** 85 * Set and Get whether features are appended to a single 86 * vtkPolyData. Turning the option on is useful when a shapefile has 87 * a number of features which could otherwise lead to a huge 88 * multiblock structure. 89 */ 90 vtkSetMacro(AppendFeatures, int); 91 vtkGetMacro(AppendFeatures, int); 92 vtkBooleanMacro(AppendFeatures, int); 93 //@} 94 95 /** 96 * Return projection string belonging to each layer in WKT format. 97 */ 98 std::map<int, std::string> GetLayersProjection(); 99 100 /** 101 * Return projection string belonging to a layer in WKT format. 102 */ 103 const char* GetLayerProjection(int layerIndex); 104 105 /** 106 * Return projection string belonging to a layer in PROJ.4 format 107 * 108 * \note The returned string has to be deleted (via delete[]) by the 109 * calling program. 110 */ 111 const char* GetLayerProjectionAsProj4(int layerIndex); 112 113 //@{ 114 /** 115 * Set/get whether feature IDs should be generated. 116 * Some GDAL primitives (e.g., a polygon with a hole 117 * in its interior) are represented by multiple VTK 118 * cells. If you wish to identify the primitive 119 * responsible for a VTK cell, turn this on. It is 120 * off by default for backwards compatibility. 121 * The array of feature IDs will be the active 122 * cell-data pedigree IDs. 123 */ 124 vtkSetMacro(AddFeatureIds,int); 125 vtkGetMacro(AddFeatureIds,int); 126 vtkBooleanMacro(AddFeatureIds,int); 127 //@} 128 129 protected: 130 vtkGDALVectorReader(); 131 ~vtkGDALVectorReader() override; 132 133 int RequestInformation( vtkInformation*, vtkInformationVector**, vtkInformationVector* ) override; 134 int RequestData( vtkInformation*, vtkInformationVector**, vtkInformationVector* ) override; 135 136 int InitializeInternal(); 137 138 /// The name of the file that will be opened on the next call to RequestData() 139 char* FileName; 140 141 int ActiveLayer; 142 int AppendFeatures; 143 int AddFeatureIds; 144 145 class Internal; 146 147 /// Private per-file metadata 148 vtkGDALVectorReader::Internal* Implementation; 149 150 /// Global variable indicating whether the OGR library has been registered yet or not. 151 static int OGRRegistered; 152 153 /// Mapping of layer to projection. 154 std::map<int, std::string> LayersProjection; 155 156 private: 157 vtkGDALVectorReader(const vtkGDALVectorReader&) = delete; 158 void operator=(const vtkGDALVectorReader&) = delete; 159 }; 160 161 #endif // vtkGDALVectorReader_h 162