ToolMap
Loading...
Searching...
No Matches
tmgisdatavector.h
1/***************************************************************************
2 tmgisdatavector.h
3 Super class for dealing with vector GIS data
4 -------------------
5 copyright : (C) 2007 CREALP Lucien Schreiber
6 ***************************************************************************/
7
8/***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16
17// comment doxygen
18
19#ifndef _TM_GISDATAVECTOR_H_
20#define _TM_GISDATAVECTOR_H_
21
22// For compilers that support precompilation, includes "wx/wx.h".
23#include <wx/wxprec.h>
24
25// Include wxWidgets' headers
26#ifndef WX_PRECOMP
27#include <wx/wx.h>
28#endif
29
30#include "tmgisdata.h"
31
32// Number of formats reserved for rasters
33const int tmGISVECTOR_OFFSET = 4;
34
35enum tmGISDATA_VECTOR_TYPES {
36 tmGIS_VECTOR_SHAPEFILE = tmGISVECTOR_OFFSET,
37 tmGIS_VECTOR_MYSQL // should allways been put as last item
38};
39
40static wxString tmGISDATA_VECTOR_TYPE_WILDCARDS[] = {wxTRANSLATE("Esri's shapefiles (*.shp)|*.shp"),
41 wxTRANSLATE("MySQL geometric table (*.MYD)|*.MYD")};
42
43static wxString tmGISDATA_VECTOR_TYPE_EXTENSION[] = {
44 _T("*.shp"),
45 _T("*.mysql"),
46};
47
48class tmGISDataVector : public tmGISData {
49 private:
50 // inserting private function
51 bool ComputeLineLineIntersection(OGRLineString* line, OGRLineString* intersection, const wxArrayInt& vertexindex,
52 OGRMultiPoint& resultpos);
53
54 bool SplitLinesAtVertex(OGRLineString* line, const wxArrayInt& splitpos, OGRMultiLineString& splitedline);
55
56 OGRLineString* GetLineWithIntersection(OGRLineString* line, OGRLineString* intersection,
57 wxArrayInt& insertedvertex);
58
59 OGRLineString* GetLineWithIntersection(OGRLineString* line, OGRMultiLineString* multiline,
60 wxArrayInt& intertedvertex);
61
62 protected:
63 virtual wxString GetTableName(TOC_GENERIC_NAME type) {
64 return wxEmptyString;
65 }
66
67 // GEOS functions
68 bool CheckGEOSIntersection(GEOSGeom* rect, GEOSGeom* object);
69
70 bool CheckGEOSCrosses(GEOSGeom* g1, GEOSGeom* g2);
71
72 GEOSGeom CreateGEOSGeometry(OGRGeometry* geom);
73
74 GEOSGeom CreateGEOSGeometry(const tmRealRect& rect);
75
76 // Intersection for snapping
77 bool GetVertexIntersection(OGRGeometry* geometry, OGRGeometry* buffer, wxArrayRealPoints& points);
78
79 bool GetBeginEndInterseciton(OGRGeometry* geometry, OGRGeometry* buffer, wxArrayRealPoints& points);
80
81 static OGRGeometry* SafeCreateFromGEOS(GEOSGeom geom);
82
83 static OGRGeometry* SafeBuffer(OGRGeometry* ogrgeom, int size);
84
85 static OGRGeometry* SafeIntersection(OGRGeometry* geom1, OGRGeometry* geom2);
86
87 static OGRGeometry* SafeUnion(OGRGeometry* union1, OGRGeometry* line);
88
89 static OGRGeometry* CreateOGRGeometry(const wxRealPoint& pt);
90
91 public:
92 // ctor, dtor
94
96
97 // static functions
98 static void InitGISDriversVector();
99
100 static wxString GetAllVectorGISFormatsWildcards();
101
102 static tmGISDataVector* CreateGISVectorBasedOnType(const int& gis_format_index);
103
104 static tmGISDataVector* CreateGISVectorBasedOnExt(const wxString& extension);
105
106 static OGRGeometry* CreateOGRGeometry(const tmRealRect& rect);
107
108 OGRLineString* InsertVertex(OGRGeometry* pointbuffer, wxRealPoint ptclicked, OGRLineString* line,
109 int& inseredvertex);
110
111 OGRLineString* InsertVertexMultiple(OGRLineString* line, OGRMultiPoint* vertex, const wxArrayInt& point_pos);
112
113 // gis function
114 virtual TM_GIS_SPATIAL_TYPES GetSpatialType() {
115 return LAYER_SPATIAL_UNKNOWN;
116 }
117
118 // virtual function for getting data & drawing
119 virtual bool SetSpatialFilter(tmRealRect filter, int type) {
120 return FALSE;
121 }
122
123 virtual bool SetAttributeFilter(const wxString& query) {
124 return FALSE;
125 }
126
127 virtual wxRealPoint* GetNextDataLine(int& nbvertex, long& oid, bool& isOver) {
128 return nullptr;
129 }
130
131 virtual OGRFeature* GetNextFeature() {
132 return nullptr;
133 }
134
135 virtual bool ResetReading() {
136 return false;
137 }
138
139 virtual wxRealPoint* GetNextDataPoint(long& oid, bool& isOver) {
140 return nullptr;
141 }
142
143 virtual int GetNextDataPolygonInfo(long& oid) {
144 return -1;
145 }
146
147 virtual wxRealPoint* GetNextDataPolygon(int currentring, int& nbvertex) {
148 return nullptr;
149 }
150
151 virtual OGRFeature* GetFeatureByOID(long oid) {
152 return nullptr;
153 }
154
155 virtual long AddGeometry(OGRGeometry* Geom, const long& oid, int layertype = wxNOT_FOUND) {
156 return -1;
157 }
158
159 virtual bool UpdateGeometry(OGRGeometry* geom, const long& oid) {
160 return false;
161 }
162
163 virtual bool SplitGeometry(OGRGeometryCollection* gCol, const long& oid, wxArrayLong& AddedIds, int layertype);
164
165 virtual OGRGeometryCollection* GetGeometryColByOID(wxArrayLong* OIDs) {
166 return nullptr;
167 }
168
169 virtual void CloseGeometry() {
170 ;
171 }
172
173 // iterate geometries (MySQL and OGR)
174 virtual OGRGeometry* GetNextGeometry(bool restart, long& oid) {
175 oid = wxNOT_FOUND;
176 return nullptr;
177 }
178
179 virtual bool DeleteFile(const wxString& layername) {
180 return false;
181 }
182
183 // counting
184 virtual int GetCount() {
185 return -1;
186 }
187
188 // fields functions
189 virtual int GetFieldsCount() {
190 return -1;
191 }
192
193 virtual bool GetFieldsName(wxArrayString& Fields, long oid = wxNOT_FOUND) {
194 return false;
195 }
196
197 virtual bool GetFieldsValue(wxArrayString& values, long oid) {
198 return false;
199 }
200
201 // Metadata
202 wxString GetFieldsMetadata();
203
204 // transformations
205 bool CutLineAtVertex(long oid, const wxRealPoint& clickedpt, int searchRadius, int layertype);
206
207 // OGRLineString * line1, OGRGeometry * pointbuffer,
208 // wxRealPoint ptclicked, OGRLineString & lineresult1,
209 // OGRLineString & lineresult2);
210 bool CutLineGeometry(OGRLineString* line1, OGRLineString* line2, OGRMultiLineString& res1,
211 OGRMultiLineString& res2);
212
213 bool CutLineMultiple(OGRLineString* linetocut, OGRMultiLineString* cutlines, OGRMultiLineString& results);
214
215 // merging
216 bool LinesMerge(OGRMultiLineString* linetomerge, OGRGeometry** linemerged);
217
218 // Searching
219 virtual wxArrayLong* SearchIntersectingGeometry(OGRGeometry* intersectinggeom) {
220 return nullptr;
221 }
222
223 virtual int IsRaster() {
224 return 0;
225 }
226};
227
228#endif
Definition tmgisdatavector.h:48
bool CheckGEOSIntersection(GEOSGeom *rect, GEOSGeom *object)
Compute real GEOS intersection (not bounding box)
Definition tmgisdatavector.cpp:104
bool CutLineMultiple(OGRLineString *linetocut, OGRMultiLineString *cutlines, OGRMultiLineString &results)
Cut one line with multiple line.
Definition tmgisdatavector.cpp:585
static OGRGeometry * SafeIntersection(OGRGeometry *geom1, OGRGeometry *geom2)
Compute intersection.
Definition tmgisdatavector.cpp:368
static OGRGeometry * SafeUnion(OGRGeometry *union1, OGRGeometry *line)
Compute Union.
Definition tmgisdatavector.cpp:407
bool GetBeginEndInterseciton(OGRGeometry *geometry, OGRGeometry *buffer, wxArrayRealPoints &points)
Search if a Begin/End vertex intersect the passed geometry.
Definition tmgisdatavector.cpp:269
bool CheckGEOSCrosses(GEOSGeom *g1, GEOSGeom *g2)
Check for crossing (not bounding box)
Definition tmgisdatavector.cpp:121
bool CutLineGeometry(OGRLineString *line1, OGRLineString *line2, OGRMultiLineString &res1, OGRMultiLineString &res2)
Cut two lines where they intesects.
Definition tmgisdatavector.cpp:542
bool GetVertexIntersection(OGRGeometry *geometry, OGRGeometry *buffer, wxArrayRealPoints &points)
Search if a vertex intersect the passed geometry.
Definition tmgisdatavector.cpp:200
wxString GetFieldsMetadata()
Formating fields info into html string.
Definition tmgisdatavector.cpp:67
virtual bool SplitGeometry(OGRGeometryCollection *gCol, const long &oid, wxArrayLong &AddedIds, int layertype)
Save splitted geometry to file.
Definition tmgisdatavector.cpp:786
static OGRGeometry * SafeCreateFromGEOS(GEOSGeom geom)
Safe conversion function.
Definition tmgisdatavector.cpp:307
bool CutLineAtVertex(long oid, const wxRealPoint &clickedpt, int searchRadius, int layertype)
Cut line in two at specified point.
Definition tmgisdatavector.cpp:453
GEOSGeom CreateGEOSGeometry(OGRGeometry *geom)
Create a GEOS geometry.
Definition tmgisdatavector.cpp:141
OGRLineString * InsertVertexMultiple(OGRLineString *line, OGRMultiPoint *vertex, const wxArrayInt &point_pos)
Insert multiple vertex into line.
Definition tmgisdatavector.cpp:950
OGRLineString * InsertVertex(OGRGeometry *pointbuffer, wxRealPoint ptclicked, OGRLineString *line, int &inseredvertex)
Insert a vertex in a passed line.
Definition tmgisdatavector.cpp:893
bool LinesMerge(OGRMultiLineString *linetomerge, OGRGeometry **linemerged)
Merge lines.
Definition tmgisdatavector.cpp:989
Main class for dealing with GIS data.
Definition tmgisdata.h:48
Class representing real rectangle.
Definition tmgisscale.h:44