Debian Codegraph @

src/imageclasses/VectorOgr.h

raw symbols SCIP
1 /**********************************************************************
2 VectorOgr.h: class to hold OGR features, typically read with readNextFeature
3 Author(s): [email protected]
4 Copyright (C) 2016-2024 European Union (Joint Research Centre)
5
6 This file is part of jiplib.
7
8 jiplib is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 jiplib is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with jiplib. If not, see <https://www.gnu.org/licenses/>.
20 ***********************************************************************/
21 #ifndef _VECTOROGR_H_
22 #define _VECTOROGR_H_
23
24 #include <iostream>
25 #include <fstream>
26 #include <sstream>
27 #include <memory>
28 #include "algorithms/ConfusionMatrix.h"
29 #include "algorithms/StatFactory.h"
30 #include "apps/AppFactory.h"
31 #include "ogr_feature.h"
32 #include "ogrsf_frmts.h"
33 #include "imageclasses/Jim.h"
34 #include "cpl_string.h"
35
36 /* enum OGR_DATA_ACCESS { READ_ONLY = 0, UPDATE = 1, WRITE = 3}; */
37 enum JOIN_METHOD { INNER = 0, OUTER_LEFT = 1, OUTER_RIGHT = 2, OUTER_FULL = 3};
38
39 class Jim;
40 class VectorOgr : public std::enable_shared_from_this<VectorOgr>
41 {
42 public:
43 ///Default constructor
44 VectorOgr(void);
45 ///constructor from filename (for reading)
46 VectorOgr(const std::string& filename, const std::vector<std::string>& layernames=std::vector<std::string>(), bool noread=false, const std::vector<std::string>& ooptions=std::vector<std::string>()){
47 open(filename,layernames,noread,ooptions);
48 }
49 ///constructor from filename (for reading or writing)
50 VectorOgr(app::AppFactory &app) : m_gds(NULL), m_access(GDAL_OF_READONLY){m_filename.clear();open(app);}
51 ///Copy constructor
52 VectorOgr(VectorOgr& other, app::AppFactory &app);
53 ///Copy constructor
54 /* VectorOgr(VectorOgr& other, const std::string& filename, const std::string& imageType, char** options=NULL, bool copyData=true); */
55 ///Destructor
56 ~VectorOgr(void);
57 ///perform a deep copy, including layers and features (if copyData is true)
58 OGRErr copy(VectorOgr& other, app::AppFactory &app);
59 ///assignment operator
60 /* VectorOgr& operator=(VectorOgr& other); */
61 ///Create new shared pointer to VectorOgr object
62 /**
63 *
64 * @return shared pointer to new VectorOgr object
65 */
66 static std::shared_ptr<VectorOgr> createVector() {
67 return(std::make_shared<VectorOgr>());
68 };
69 static std::shared_ptr<VectorOgr> createVector(const std::string& filename, const std::vector<std::string>& layernames=std::vector<std::string>()) {
70 std::shared_ptr<VectorOgr> pVector=std::make_shared<VectorOgr>(filename,layernames);
71 return(pVector);
72 };
73 static std::shared_ptr<VectorOgr> createVector(app::AppFactory &app){
74 std::shared_ptr<VectorOgr> pVector=std::make_shared<VectorOgr>(app);
75 return(pVector);
76 };
77 static std::shared_ptr<VectorOgr> createVector(VectorOgr& other,app::AppFactory &app){
78 std::shared_ptr<VectorOgr> pVector=std::make_shared<VectorOgr>(other,app);
79 return(pVector);
80 };
81 static OGRwkbGeometryType string2geotype(const std::string &typeString){
82 //initialize selMap
83 std::map<std::string,OGRwkbGeometryType> typeMap;
84 typeMap["wkbUnknown"] = wkbUnknown;
85 typeMap["wkbPoint"] = wkbPoint;
86 typeMap["wkbLineString"] = wkbLineString;
87 typeMap["wkbPolygon"] = wkbPolygon;
88 typeMap["wkbMultiPoint"] = wkbMultiPoint;
89 typeMap["wkbMultiLineString"] = wkbMultiLineString;
90 typeMap["wkbMultiPolygon"] = wkbMultiPolygon;
91 typeMap["wkbGeometryCollection"] = wkbGeometryCollection;
92 typeMap["wkbCircularString"] = wkbCircularString;
93 typeMap["wkbCompoundCurve"] = wkbCompoundCurve;
94 typeMap["wkbCurvePolygon"] = wkbCurvePolygon;
95 typeMap["wkbMultiCurve"] = wkbMultiCurve;
96 typeMap["wkbMultiSurface"] = wkbMultiSurface;
97 typeMap["wkbCurve"] = wkbCurve;
98 typeMap["wkbSurface"] = wkbSurface;
99 typeMap["wkbPolyhedralSurface"] = wkbPolyhedralSurface;
100 typeMap["wkbTIN"] = wkbTIN;
101 typeMap["wkbTriangle"] = wkbTriangle;
102 typeMap["wkbNone"] = wkbNone;
103 typeMap["wkbLinearRing"] = wkbLinearRing;
104 typeMap["wkbCircularStringZ"] = wkbCircularStringZ;
105 typeMap["wkbCompoundCurveZ"] = wkbCompoundCurveZ;
106 typeMap["wkbCurvePolygonZ"] = wkbCurvePolygonZ;
107 typeMap["wkbMultiCurveZ"] = wkbMultiCurveZ;
108 typeMap["wkbMultiSurfaceZ"] = wkbMultiSurfaceZ;
109 typeMap["wkbCurveZ"] = wkbCurveZ;
110 typeMap["wkbSurfaceZ"] = wkbSurfaceZ;
111 typeMap["wkbPolyhedralSurfaceZ"] = wkbPolyhedralSurfaceZ;
112 typeMap["wkbTINZ"] = wkbTINZ;
113 typeMap["wkbTriangleZ"] = wkbTriangleZ;
114 typeMap["wkbPointM"] = wkbPointM;
115 typeMap["wkbLineStringM"] = wkbLineStringM;
116 typeMap["wkbPolygonM"] = wkbPolygonM;
117 typeMap["wkbMultiPointM"] = wkbMultiPointM;
118 typeMap["wkbMultiLineStringM"] = wkbMultiLineStringM;
119 typeMap["wkbMultiPolygonM"] = wkbMultiPolygonM;
120 typeMap["wkbGeometryCollectionM"] = wkbGeometryCollectionM;
121 typeMap["wkbCircularStringM"] = wkbCircularStringM;
122 typeMap["wkbCompoundCurveM"] = wkbCompoundCurveM;
123 typeMap["wkbCurvePolygonM"] = wkbCurvePolygonM;
124 typeMap["wkbMultiCurveM"] = wkbMultiCurveM;
125 typeMap["wkbMultiSurfaceM"] = wkbMultiSurfaceM;
126 typeMap["wkbCurveM"] = wkbCurveM;
127 typeMap["wkbSurfaceM"] = wkbSurfaceM;
128 typeMap["wkbPolyhedralSurfaceM"] = wkbPolyhedralSurfaceM;
129 typeMap["wkbTINM"] = wkbTINM;
130 typeMap["wkbTriangleM"] = wkbTriangleM;
131 typeMap["wkbPointZM"] = wkbPointZM;
132 typeMap["wkbLineStringZM"] = wkbLineStringZM;
133 typeMap["wkbPolygonZM"] = wkbPolygonZM;
134 typeMap["wkbMultiPointZM"] = wkbMultiPointZM;
135 typeMap["wkbMultiLineStringZM"] = wkbMultiLineStringZM;
136 typeMap["wkbMultiPolygonZM"] = wkbMultiPolygonZM;
137 typeMap["wkbGeometryCollectionZM"] = wkbGeometryCollectionZM;
138 typeMap["wkbCircularStringZM"] = wkbCircularStringZM;
139 typeMap["wkbCompoundCurveZM"] = wkbCompoundCurveZM;
140 typeMap["wkbCurvePolygonZM"] = wkbCurvePolygonZM;
141 typeMap["wkbMultiCurveZM"] = wkbMultiCurveZM;
142 typeMap["wkbMultiSurfaceZM"] = wkbMultiSurfaceZM;
143 typeMap["wkbCurveZM"] = wkbCurveZM;
144 typeMap["wkbSurfaceZM"] = wkbSurfaceZM;
145 typeMap["wkbPolyhedralSurfaceZM"] = wkbPolyhedralSurfaceZM;
146 typeMap["wkbTINZM"] = wkbTINZM;
147 typeMap["wkbTriangleZM"] = wkbTriangleZM;
148 typeMap["wkbPoint25D"] = wkbPoint25D;
149 typeMap["wkbLineString25D"] = wkbLineString25D;
150 typeMap["wkbPolygon25D"] = wkbPolygon25D;
151 typeMap["wkbMultiPoint25D"] = wkbMultiPoint25D;
152 typeMap["wkbMultiLineString25D"] = wkbMultiLineString25D;
153 typeMap["wkbMultiPolygon25D"] = wkbMultiPolygon25D;
154 typeMap["wkbGeometryCollection25D"] = wkbGeometryCollection25D;
155 if(typeMap.count(typeString))
156 return(typeMap[typeString]);
157 else
158 return(wkbUnknown);
159 }
160
161 static JOIN_METHOD string2method(const std::string &method){
162 //initialize selMap
163 std::map<std::string,JOIN_METHOD> methodMap;
164 methodMap["INNER"] = INNER;
165 methodMap["inner"] = INNER;
166 methodMap["OUTER_LEFT"] = OUTER_LEFT;
167 methodMap["outer_left"] = OUTER_LEFT;
168 methodMap["OUTER_RIGHT"] = OUTER_RIGHT;
169 methodMap["outer_right"] = OUTER_RIGHT;
170 methodMap["OUTER_FULL"] = OUTER_FULL;
171 methodMap["outer_full"] = OUTER_FULL;
172 if(methodMap.count(method))
173 return(methodMap[method]);
174 else
175 return(INNER);
176 }
177 ///destroy all features in object
178 void destroyAll();
179 void destroyEmptyFeatures(size_t ilayer=0);
180 bool isEmpty(size_t ilayer=0);
181 void destroyFeatures(size_t ilayer=0);
182 ///open using a copy
183 //OGRErr open(const VectorOgr& vectorOgr, const std::string& layername=std::string());
184 ///open a GDAL vector dataset for writing with layers to be pushed later
185 OGRErr open(const std::string& filename, const std::string& imageType, unsigned int access=GDAL_OF_UPDATE);
186 ///open a GDAL vector dataset for reading
187 OGRErr open(const std::string& filename, const std::vector<std::string>& layernames=std::vector<std::string>(), bool noread=false, const std::vector<std::string>& ooptions=std::vector<std::string>());
188 //open a GDAL vector dataset for writing
189 OGRErr open(const std::string& filename, const std::vector<std::string>& layernames, const std::string& imageType, const OGRwkbGeometryType& geometryType, OGRSpatialReference* theSRS=NULL, char** options=NULL);
190 //open a GDAL vector dataset for writing
191 OGRErr open(const std::string& filename, const std::vector<std::string>& layernames, const std::string& imageType, const OGRwkbGeometryType& geometryType, const std::string& theProjection, char** options=NULL);
192 //open a GDAL vector dataset for writing
193 OGRErr open(const std::string& filename, const std::vector<std::string>& layernames, const std::string& imageType, const std::string& geometryType=std::string(), const std::string& theProjection=std::string(), char** options=NULL);
194 ///open a GDAL vector dataset using AppFactory argument, used for reading and writing
195 OGRErr open(app::AppFactory& app);
196 ///register driver and create GDAL dataset
197 void setCodec(const std::string& filename, const std::string& imageType);
198 ///close a GDAL vector dataset
199 void close(void);
200 ///get projection
201 std::string getProjection(size_t ilayer=0) const;
202 ///get the spatial reference based on the projection
203 const OGRSpatialReference getSpatialRef(size_t ilayer=0) const{
204 OGRSpatialReference thisSpatialRef(getProjection(ilayer).c_str());
205 return thisSpatialRef;
206 }
207 ///Get the filename of this dataset
208 std::string getFileName() const {return m_filename;};
209 ///Create a layer
210 OGRErr pushLayer(const std::string& layername, const OGRSpatialReference* theSRS, const OGRwkbGeometryType& geometryType=wkbUnknown, char** papszOptions=NULL);
211 ///Create a layer
212 OGRErr pushLayer(const std::string& layername, const std::string& theProjection=std::string(), const OGRwkbGeometryType& geometryType=wkbUnknown, char** papszOptions=NULL);
213 ///Create a layer
214 OGRErr pushLayer(const std::string& layername, const std::string& theProjection, const std::string& geometryType, char** papszOptions=NULL);
215 ///clear all features, releasing memory from heap
216 //OGRErr reset();
217 std::shared_ptr<VectorOgr> intersect(OGRPolygon *pGeom, app::AppFactory& app);
218 std::shared_ptr<VectorOgr> intersect(const Jim& aJim, app::AppFactory& app);
219 OGRErr intersect(OGRPolygon *pGeom, VectorOgr& ogrWriter, app::AppFactory& app);
220 OGRErr intersect(const Jim& aJim, VectorOgr& ogrWriter, app::AppFactory& app);
221 std::shared_ptr<VectorOgr> convexHull(app::AppFactory& app);
222 OGRErr convexHull(VectorOgr& ogrWriter, app::AppFactory& app);
223 ///get access mode
224 unsigned int getAccess(){return m_access;};
225 ///set access mode
226 OGRErr setAccess(unsigned int theAccess){m_access=theAccess; return(OGRERR_NONE);};
227 ///set access mode using a string argument
228 OGRErr setAccess(std::string accessString){
229 if(accessString=="GDAL_OF_READONLY"){
230 m_access=GDAL_OF_READONLY;
231 }
232 if(accessString=="GDAL_OF_UPDATE"){
233 m_access=GDAL_OF_UPDATE;
234 }
235 return(OGRERR_NONE);
236 }
237 ///get number of layers
238 size_t getGDSLayerCount() const {
239 if(m_gds)
240 return(m_gds->GetLayerCount());
241 else
242 return(0);
243 };
244 size_t getLayerCount() const {
245 return(m_layer.size());
246 /* if(m_gds) */
247 /* return(m_gds->GetLayerCount()); */
248 /* else */
249 /* return(0); */
250 };
251 std::string getLayerName(size_t ilayer=0) const {if(getLayer(ilayer)) return(getLayer(ilayer)->GetName());else return(std::string());};
252 #if GDAL_VERSION_MAJOR < 2
253 //Get a pointer to the GDAL dataset
254 OGRDataSource* getDataset(){return m_gds;};
255 #else
256 //Get a pointer to the GDAL dataset
257 GDALDataset* getDataset(){return m_gds;};
258 #endif
259 ///get layer
260 OGRLayer* getLayer(size_t ilayer=0) {if(m_layer.size()>ilayer) return(m_layer[ilayer]);else return(0);};
261 ///get layer const version
262 OGRLayer* getLayer(size_t ilayer=0) const {if(m_layer.size()>ilayer) return(m_layer[ilayer]);else return(0);};
263 ///get layer by name
264 OGRLayer* getLayer(std::string layername) {
265 for(size_t ilayer=0;ilayer<getGDSLayerCount();++ilayer){
266 std::string currentLayername=getLayer(ilayer)->GetName();
267 if(currentLayername==layername)
268 return(m_layer[ilayer]);
269 else
270 continue;
271 }
272 return(0);
273 }
274 ///get layer by name const version
275 OGRLayer* getLayer(std::string layername) const {
276 for(size_t ilayer=0;ilayer<getGDSLayerCount();++ilayer){
277 std::string currentLayername=getLayer(ilayer)->GetName();
278 if(currentLayername==layername)
279 return(m_layer[ilayer]);
280 else
281 continue;
282 }
283 return(0);
284 }
285 ///get layers
286 std::vector<OGRLayer*> getLayers(const std::vector<std::string>& layernames=std::vector<std::string>()){
287 if(layernames.size()){
288 std::vector<OGRLayer*> layers;
289 for(size_t ilayer=0;ilayer<getGDSLayerCount();++ilayer){
290 std::string currentLayername=getLayer(ilayer)->GetName();
291 std::vector<std::string>::const_iterator it=find(layernames.begin(),layernames.end(),currentLayername);
292 if(it==layernames.end())
293 continue;
294 else
295 layers.push_back(getLayer(ilayer));
296 }
297 return(layers);
298 }
299 else
300 return(m_layer);
301 };
302 ///get layers const version
303 std::vector<OGRLayer*> getLayers(const std::vector<std::string>& layernames=std::vector<std::string>()) const {
304 if(layernames.size()){
305 std::vector<OGRLayer*> layers;
306 for(size_t ilayer=0;ilayer<getGDSLayerCount();++ilayer){
307 std::string currentLayername=getLayer(ilayer)->GetName();
308 std::vector<std::string>::const_iterator it=find(layernames.begin(),layernames.end(),currentLayername);
309 if(it==layernames.end())
310 continue;
311 else
312 layers.push_back(getLayer(ilayer));
313 }
314 return(layers);
315 }
316 else
317 return(m_layer);
318 };
319 ///get geometry type
320 OGRwkbGeometryType getGeometryType(size_t ilayer=0) {return(m_layer[ilayer]->GetGeomType());};
321 ///get number of features over all layers
322 size_t getFeatureCount() const {
323 size_t nfeatures=0;
324 for(size_t ilayer=0;ilayer<getLayerCount();++ilayer)
325 nfeatures+=getFeatureCount(ilayer);
326 return(nfeatures);
327 };
328 ///get number of features
329 size_t getFeatureCount(size_t ilayer) const {
330 if(m_features.size()<=ilayer){
331 std::ostringstream errorStream;
332 errorStream << "Error: m_features not initialized for layer " << ilayer << std::endl;
333 std::cerr << errorStream.str() << std::endl;
334 throw(errorStream.str());
335 }
336 return(m_features[ilayer].size());
337 };
338 ///create field
339 OGRErr createField(const std::string& fieldname, const OGRFieldType& fieldType,size_t ilayer=0);
340 ///create field
341 OGRErr createField(OGRFieldDefn* poField,size_t ilayer=0);
342 ///copy fields from other VectorOgr instance
343 OGRErr copyFields(const VectorOgr& vectorOgr,const std::vector<std::string>& fieldnames=std::vector<std::string>(),size_t fromLayer=0, size_t toLayer=0);
344 ///write all features (default to m_gds dataset already defined when opened, but optionally to another filename
345 OGRErr write(const std::string& filename=std::string());
346 ///write all features to a new vector dataset
347 //void write(const std::string& filename, const std::string& layername, const::std::string& imageType="SQLite", char** papszOptions=NULL);
348 ///copy all features from existing VectorOgr and write to vector dataset
349 /* void write(VectorOgr& vectorOgr, const std::string& filename, const std::string& layername, const::std::string& imageType="SQLite", char** papszOptions=NULL); */
350 ///Get geographical extent upper left and lower right corners over all layers
351 bool getExtent(double& ulx, double& uly, double& lrx, double& lry, OGRCoordinateTransformation *poCT=0) const;
352 ///Get geographical extent upper left and lower right corners for specific layer
353 bool getExtent(double& ulx, double& uly, double& lrx, double& lry, size_t ilayer, OGRCoordinateTransformation *poCT=0) const;
354 bool getExtent(OGRPolygon *bbPolygon, size_t ilayer, OGRCoordinateTransformation *poCT=0) const;
355 ///Get geographical extent upper left and lower right corners
356 /* void getExtent(std::vector<double> &bbvector, size_t ilayer=0, OGRCoordinateTransformation *poCT=0) const; */
357 /* void getExtent(OGRPolygon *bbPolygon, size_t ilayer=0, OGRCoordinateTransformation *poCT=0) const; */
358 void getBoundingBox(double& ulx, double& uly, double& lrx, double& lry, OGRCoordinateTransformation *poCT=0) const{getExtent(ulx,uly,lrx,lry,poCT);};
359 void getBoundingBox(double& ulx, double& uly, double& lrx, double& lry, size_t ilayer, OGRCoordinateTransformation *poCT=0) const{getExtent(ulx,uly,lrx,lry,ilayer,poCT);};
360 /* void getBoundingBox(std::vector<double> &bbvector, size_t ilayer=0, OGRCoordinateTransformation *poCT=0) const{getExtent(bbvector,ilayer,poCT);}; */
361 void getBoundingBox(OGRPolygon *bbPolygon, size_t ilayer=0, OGRCoordinateTransformation *poCT=0) const{getExtent(bbPolygon,ilayer,poCT);};
362 ///Get Upper left corner in x over all layers
363 double getUlx(OGRCoordinateTransformation *poCT=0) const{double ulx,uly,lrx,lry;getExtent(ulx,uly,lrx,lry,poCT);return(ulx);};
364 ///Get Upper left corner in y over all layers
365 double getUly(OGRCoordinateTransformation *poCT=0) const{double ulx,uly,lrx,lry;getExtent(ulx,uly,lrx,lry,poCT);return(uly);};
366 ///Get lower right corner in x over all layers
367 double getLrx(OGRCoordinateTransformation *poCT=0) const{double ulx,uly,lrx,lry;getExtent(ulx,uly,lrx,lry,poCT);return(lrx);};
368 ///Get lower right corner in y over all layers
369 double getLry(OGRCoordinateTransformation *poCT=0) const{double ulx,uly,lrx,lry;getExtent(ulx,uly,lrx,lry,poCT);return(lry);};
370 ///Get Upper left corner in x
371 double getUlx(size_t ilayer, OGRCoordinateTransformation *poCT=0) const{double ulx,uly,lrx,lry;getExtent(ulx,uly,lrx,lry,ilayer,poCT);return(ulx);};
372 ///Get Upper left corner in y
373 double getUly(size_t ilayer, OGRCoordinateTransformation *poCT=0) const{double ulx,uly,lrx,lry;getExtent(ulx,uly,lrx,lry,ilayer,poCT);return(uly);};
374 ///Get lower right corner in x
375 double getLrx(size_t ilayer, OGRCoordinateTransformation *poCT=0) const{double ulx,uly,lrx,lry;getExtent(ulx,uly,lrx,lry,ilayer,poCT);return(lrx);};
376 ///Get lower right corner in y
377 double getLry(size_t ilayer, OGRCoordinateTransformation *poCT=0) const{double ulx,uly,lrx,lry;getExtent(ulx,uly,lrx,lry,ilayer,poCT);return(lry);};
378 ///resize features
379 OGRErr resize(size_t theSize, size_t ilayer=0){
380 m_features[ilayer].resize(theSize);
381 return(OGRERR_NONE);
382 };
383 ///create a new feature
384 OGRFeature* createFeature(size_t ilayer=0){OGRFeature* newFeature=OGRFeature::CreateFeature(getLayer(ilayer)->GetLayerDefn());return(newFeature);};
385 ///push feature to the object
386 OGRErr pushFeature(OGRFeature *poFeature,size_t ilayer=0);
387 ///set feature to the object
388 OGRErr setFeature(unsigned int index, OGRFeature *poFeature,size_t ilayer=0);
389 ///Assignment operator
390 /* VectorOgr& operator=(VectorOgr& other); */
391 ///Set rectangular spatial filter (warning: mind order, unlike GDAL I do not use minX, minY, maxX, maxY!!!)
392 OGRErr setSpatialFilterRect(double ulx, double uly, double lrx, double lry, size_t ilayer=0){m_layer[ilayer]->SetSpatialFilterRect(ulx,lry,lrx,uly);return(OGRERR_NONE);};
393 ///Set spatial filter
394 OGRErr setSpatialFilter(OGRGeometry* spatialFilter=NULL, size_t ilayer=0){m_layer[ilayer]->SetSpatialFilter(spatialFilter);return(OGRERR_NONE);};
395 ///Set attribute filter
396 OGRErr setAttributeFilter(const std::string& attributeFilter, size_t ilayer=0){if(attributeFilter.size()) m_layer[ilayer]->SetAttributeFilter(attributeFilter.c_str());else m_layer[ilayer]->SetAttributeFilter(NULL);return(OGRERR_NONE);};
397 ///clone feature. The newly created feature is owned by the caller, and will have it's own reference to the OGRFeatureDefn.
398 OGRFeature* cloneFeature(unsigned int index, size_t ilayer=0);
399 ///get feature reference (feature should not be deleted)
400 OGRFeature* getFeatureRef(unsigned int index,size_t ilayer=0);
401 ///Get field definitions in vector
402 OGRErr getFields(std::vector<OGRFieldDefn*>& fields, size_t ilayer=0) const;
403 ///Get field names in vector
404 void getFieldNames(std::vector<std::string>& fields, size_t layer=0) const;
405 ///prepare dataset for writing, e.g., register driver
406 //OGRErr createDS(const std::string& filename, const std::string& imageType, DATA_ACCESS theAccess=WRITE);
407 OGRErr addPoint(double x, double y, const std::map<std::string,double>& pointAttributes, std::string fieldName, int theId, size_t ilayer=0);
408 OGRErr addPoint(double x, double y, const std::map<std::string,double>& pointAttributes, size_t ilayer=0);
409 size_t serialize(std::vector<unsigned char> &vbytes);
410 void dumpOgr(app::AppFactory& app);
411 std::shared_ptr<VectorOgr> merge(VectorOgr &ogrReader, app::AppFactory& app);
412 void merge(VectorOgr &ogrReader, VectorOgr &ogrWriter,app::AppFactory& app);
413 /* void append(VectorOgr &ogrReader); */
414 ///joins two VectorOgr based on key value
415 std::shared_ptr<VectorOgr> join(VectorOgr &ogrReader, app::AppFactory& app);
416 ///joins two VectorOgr based on key value
417 OGRErr join(VectorOgr &ogrReader, VectorOgr &ogrWriter, app::AppFactory& app);
418 ///sort features by label and store in map
419 OGRErr sortByLabel(std::map<std::string,Vector2d<float> > &mapPixels, const std::string& label="label", const std::vector<std::string>& bandNames=std::vector<std::string>());
420 ///train classifier
421 void train(app::AppFactory& app);
422 ///train in memory without writing to file
423 std::string trainMem(app::AppFactory& app);
424 ///classify
425 std::shared_ptr<VectorOgr> classify(app::AppFactory& app);
426 ///classify
427 void classify(VectorOgr& ogrWriter, app::AppFactory& app);
428 //getShared from this
429 std::shared_ptr<VectorOgr> getShared(){return(std::dynamic_pointer_cast<VectorOgr>(shared_from_this()));};
430 ///overload output stream operator
431 friend std::ostream& operator<<(std::ostream& theOstream, VectorOgr& theVector);
432 ///static function to transform geometry based on OGRCoordinateTransformation
433 static bool transform(OGRGeometry *pGeom, OGRCoordinateTransformation *poCT);
434 ///static function to transform geometry based on OGRCoordinateTransformation
435 static bool transform(OGREnvelope *pEnv, OGRCoordinateTransformation *poCT);
436 /* bool transform(OGRGeometry *pGeom, const std::string& outputProj4); */
437 /* ///function for coordinate transform based on EPSG codes */
438 /* bool transform(OGRGeometry *pGeom, int outputEPSG); */
439 ///function for coordinate transform based on OGRSpatialReference
440 /* ///static function for coordinate transform based on proj4 parameters */
441 /* bool transform(OGRGeometry *pGeom, const std::string& inputProj4, const std::string& outputProj4); */
442 /* ///static function for coordinate transform based on EPSG codes */
443 /* static bool transform(OGRGeometry *pGeom, int inputEPSG, int outputEPSG); */
444 /* ///static function for coordinate transform based on OGRSpatialReference */
445 /* static bool transform(OGRGeometry *pGeom, OGRSpatialReference *sourceSRS, OGRSpatialReference *targetSRS); */
446 /* ///static function for coordinate transform of a vector of points based on OGRSpatialReference */
447 /* static bool transform(std::vector<double> &xvector, std::vector<double> &yvector, OGRSpatialReference *sourceSRS, OGRSpatialReference *targetSRS); */
448 /* static OGRErr join(VectorOgr &ogrReader1, VectorOgr &ogrReader2, VectorOgr &ogrWriter, app::AppFactory& app); */
449 unsigned int readFeatures();
450 unsigned int readFeatures(size_t ilayer);
451 private:
452 ///train SVM classifier
453 std::string trainSVM(app::AppFactory& app);
454 ///classify SVM
455 std::shared_ptr<VectorOgr> classifySVM(app::AppFactory& app);
456 ///classify SVM
457 void classifySVM(VectorOgr& ogrWriter, app::AppFactory& app);
458 ///train ANN classifier
459 std::string trainANN(app::AppFactory& app);
460 ///classify ANN
461 std::shared_ptr<VectorOgr> classifyANN(app::AppFactory& app);
462 ///classify ANN
463 void classifyANN(VectorOgr& ogrWriter, app::AppFactory& app);
464 ///read all features from an OGR dataset, attribute filter and spatial filter optionally
465 std::string m_filename;
466 unsigned int m_access;
467 /* std::string m_projection; */
468 std::vector<OGRLayer*> m_layer;
469 ///instance of the GDAL dataset
470 #if GDAL_VERSION_MAJOR < 2
471 OGRDataSource *m_gds;
472 #else
473 GDALDataset *m_gds;
474 #endif
475
476 ///vector containing all features in memory
477 std::vector<std::vector<OGRFeature*> > m_features;
478 };
479
480 /* static std::shared_ptr<VectorOgr> createVector(){return VectorOgr::createVector();}; */
481 /* static std::shared_ptr<VectorOgr> createVector(const std::string& filename){return(VectorOgr::createVector(filename));}; */
482 /* static std::shared_ptr<VectorOgr> createVector(app::AppFactory &app){return(VectorOgr::createVector(app));}; */
483 /* static std::shared_ptr<VectorOgr> createVector(VectorOgr& other,app::AppFactory &app){return(VectorOgr::createVector(other,app));}; */
484 #endif // _VECTOROGR_H_