Version: 0.6.0
gdalinh.h
1 /******************************************************************************
2  * Project: wxGIS
3  * Purpose: inherited from gdal and ogr classes.
4  * Author: Dmitry Baryshnikov (aka Bishop), polimax@mail.ru
5  ******************************************************************************
6 * Copyright (C) 2012-2014 Dmitry Baryshnikov
7 *
8 * This program 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 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
20  ****************************************************************************/
21 
22 #pragma once
23 
24 #include "wxgis/datasource/datasource.h"
25 
26 #undef LT_OBJDIR
27 #include "gdal_priv.h"
28 #include "ogrsf_frmts.h"
29 
30 #if GDAL_VERSION_NUM >= 2000000
31  #define OGRCompatibleDataSource GDALDataset
32  #define OGRCompatibleClose(x) GDALClose(x)
33  #define OGRCompatibleDriver GDALDriver
34  #define GetOGRCompatibleDriverByName(x) GetGDALDriverManager()->GetDriverByName( x )
35  #define CreateOGRCompatibleDataSource(path, options) Create( path, 0, 0, 0, GDT_Unknown, options );
36  #define GetOGRCompatibleDriverName GetDescription
37  #define GetOGRCompatibleDatasourceName GetDriverName
38 #else
39  #define OGRCompatibleDataSource OGRDataSource
40  #define OGRCompatibleClose(x) OGRDataSource::DestroyDataSource(x)
41  #define OGRCompatibleDriver OGRSFDriver
42  #define GetOGRCompatibleDriverByName(x) dynamic_cast<OGRSFDriver*>(OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(x))
43  #define CreateOGRCompatibleDataSource(path, options) CreateDataSource( path, options )
44  #define GetOGRCompatibleDriverName GetName
45  #define GetOGRCompatibleDatasourceName GetName
46 #endif // GDAL_VERSION_NUM
47 
48 #define wxGISEQUAL(a,b) ( (const char*)a == NULL ? 0 : EQUAL(a,b) )
49 
57 class WXDLLIMPEXP_GIS_DS wxGISSpatialReference : public wxObject
58 {
59  DECLARE_CLASS(wxGISSpatialReference)
60 public:
61  wxGISSpatialReference(OGRSpatialReference *poSRS = NULL);
62  wxGISSpatialReference(const wxString &sWKT);
63  bool IsOk() const;
64 
65  bool operator == ( const wxGISSpatialReference& obj ) const;
66  bool operator != (const wxGISSpatialReference& obj) const { return !(*this == obj); };
67  operator OGRSpatialReference*() const;
68  OGRSpatialReference* Clone(void) const;
69  OGRSpatialReference* operator->(void) const;
70  bool IsSame(const wxGISSpatialReference& SpatialReference) const;
71  wxString ExportAsWKT() const;
72  wxString GetName();
73 protected:
74  virtual wxObjectRefData *CreateRefData() const;
75  virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const;
76 protected:
77  wxString m_sName;
78 };
79 
80 extern WXDLLIMPEXP_DATA_GIS_DS(wxGISSpatialReference) wxNullSpatialReference;
81 
82 
90 class wxGISSpatialReferenceRefData : public wxObjectRefData
91 {
92  friend class wxGISSpatialReference;
93 public:
94  wxGISSpatialReferenceRefData(OGRSpatialReference *poSRS = NULL);
95  virtual ~wxGISSpatialReferenceRefData(void);
97  bool operator == (const wxGISSpatialReferenceRefData& data) const;
98  virtual void Validate();
99  virtual bool IsValid(void) const;
100 protected:
101  OGRSpatialReference *m_poSRS;
102  bool m_bIsValid;
103 };
104 
105 class WXDLLIMPEXP_GIS_DS wxGISGeometry;
106 WX_DECLARE_USER_EXPORTED_OBJARRAY(wxGISGeometry, wxGISGeometryArray, WXDLLIMPEXP_GIS_DS);
107 class WXDLLIMPEXP_GIS_DS wxGISFeature;
108 WX_DECLARE_USER_EXPORTED_OBJARRAY(wxGISFeature, wxGISFeatureArray, WXDLLIMPEXP_GIS_DS);
109 
117 class WXDLLIMPEXP_GIS_DS wxGISFeature : public wxObject
118 {
119  DECLARE_CLASS(wxGISFeature)
120 public:
121  wxGISFeature(OGRFeature *poFeature = NULL, const wxFontEncoding &oEncoding = wxLocale::GetSystemEncoding(), bool bRecodeToSystem = false);
122 
123  bool IsOk() const;
124 
125  bool operator == ( const wxGISFeature& obj ) const;
126  bool operator != (const wxGISFeature& obj) const { return !(*this == obj); };
127  operator OGRFeature*() const;
128 
129  //get
130  const char* GetFieldAsChar(int nField) const;
131  OGRField* GetRawField(int nField) const;
132  wxString GetFieldAsString(int nField) const;
133  wxString GetFieldAsString(const wxString &sFieldName) const;
134  wxDateTime GetFieldAsDateTime(int nField) const;
135  wxDateTime GetFieldAsDateTime(const wxString &sFieldName) const;
136  double GetFieldAsDouble(int nField) const;
137  double GetFieldAsDouble (const wxString &sFieldName) const;
138  wxArrayString GetFieldAsStringList(int nField) const;
139  wxArrayString GetFieldAsStringList(const wxString &sFieldName) const;
140  wxArrayDouble GetFieldAsDoubleList(int nIndex) const;
141  wxArrayDouble GetFieldAsDoubleList(const wxString &sFieldName) const;
142  wxArrayInt GetFieldAsIntegerList(int nIndex) const;
143  wxArrayInt GetFieldAsIntegerList(const wxString &sFieldName) const;
144  wxGISGeometry GetGeometry(void) const;
145  int GetFieldAsInteger(int nIndex) const;
146  int GetFieldAsInteger(const wxString &sFieldName) const;
147 
148  int GetFieldIndex(const wxString &sFieldName) const;
149  wxString GetFieldName(int nIndex) const;
150  int GetFieldCount(void) const;
151  long GetFID(void) const;
152  //set
153  OGRErr SetFID(long nFID);
154  void SetField(int nIndex, int nValue);
155  void SetField(int nIndex, OGRField* psField);
156  void SetField(int nIndex, double dfValue);
157  void SetField(int nIndex, const wxString &sValue);
158  void SetField(int nIndex, const char* pszStr);
159  void SetField (int nIndex, const wxArrayInt &anValues);
160  void SetField (int nIndex, const wxArrayDouble &adfValues);
161  void SetField(int nIndex, const wxArrayString &asValues);
162  void SetField(int nIndex, const wxDateTime &dt);
163  void SetField(const wxString &sFieldName, int nValue);
164  void SetField(const wxString &sFieldName, double dfValue);
165  void SetField(const wxString &sFieldName, const wxString &sValue);
166  void SetField (const wxString &sFieldName, const wxArrayInt &anValues);
167  void SetField (const wxString &sFieldName, const wxArrayDouble &adfValues);
168  void SetField(const wxString &sFieldName, const wxArrayString &asValues);
169  void SetField(int nIndex, int nYear, int nMonth, int nDay, int nHour = 0, int nMinute = 0, int nSecond = 0, int nTZFlag = 0);
170  void SetField(const wxString &sFieldName, int nYear, int nMonth, int nDay, int nHour = 0, int nMinute = 0, int nSecond = 0, int nTZFlag = 0);
171  OGRErr SetGeometry(const wxGISGeometry &Geom);
172  OGRErr SetGeometryDirectly(const wxGISGeometry &Geom);
173  void SetStyleString(const wxString &sStyle);
174  void StealGeometry(void);
175  void SetEncoding(const wxFontEncoding &eEnc, bool bRecodeToSystem = false);
176 protected:
177  inline wxString EncodeString(const char* psz, wxFontEncoding oEncoding) const
178  {
179  if (strlen(psz) > 0)
180  {
181  if (oEncoding <= wxFONTENCODING_DEFAULT)
182  {
183  return wxString(psz, wxConvLocal);
184  }
185  else if (oEncoding == wxFONTENCODING_UTF8)
186  {
187  return wxString::FromUTF8(psz);
188  }
189  else if (oEncoding == wxFONTENCODING_UTF7)
190  {
191  return wxString(psz, wxConvUTF7);
192  }
193  else if (oEncoding == wxFONTENCODING_UTF16)
194  {
195  return wxString(psz, wxMBConvUTF16());
196  }
197  else if (oEncoding == wxFONTENCODING_UTF32)
198  {
199  return wxString(psz, wxMBConvUTF32());
200  }
201  else if (oEncoding == wxFONTENCODING_ISO8859_1)
202  {
203  return wxString(psz, wxConvISO8859_1);
204  }
205  else if (wxLocale::GetSystemEncoding() == oEncoding)
206  {
207  return wxString(psz, wxConvLocal);
208  }
209  else
210  {
211  wxString sOut = wxString(psz, wxCSConv(oEncoding));
212  if (sOut.IsEmpty())
213  {
214  sOut = wxString(psz, wxConvLocal);
215  }
216  return sOut;
217  }
218  }
219  return wxEmptyString;
220  };
221 
222  inline const char* EncodeString(const wxString &sStr, wxFontEncoding oEncoding) const
223  {
224  if (!sStr.IsEmpty())
225  {
226  if (oEncoding <= wxFONTENCODING_DEFAULT)
227  {
228  return sStr.mb_str(wxConvLocal);
229  }
230  else if (oEncoding == wxFONTENCODING_UTF8)
231  {
232  return sStr.mb_str(wxConvUTF8);
233  }
234  else if (oEncoding == wxFONTENCODING_UTF7)
235  {
236  return sStr.mb_str(wxConvUTF7);
237  }
238  else if (oEncoding == wxFONTENCODING_UTF16)
239  {
240  return sStr.mb_str(wxMBConvUTF16());
241  }
242  else if (oEncoding == wxFONTENCODING_UTF32)
243  {
244  return sStr.mb_str(wxMBConvUTF32());
245  }
246  else if (oEncoding == wxFONTENCODING_ISO8859_1)
247  {
248  return sStr.mb_str(wxConvISO8859_1);
249  }
250  else if (wxLocale::GetSystemEncoding() == oEncoding)
251  {
252  return sStr.mb_str(wxConvLocal);
253  }
254  else
255  {
256  const char* pszOut = sStr.mb_str(wxCSConv(oEncoding));
257  if (strlen(pszOut) == 0)
258  {
259  pszOut = sStr.mb_str(wxConvLocal);
260  }
261  return pszOut;
262  }
263  }
264  return NULL;
265  };
266 
267 
268 
269  int GetFieldAsDateTime(int nIndex, int *pnYear, int *pnMonth, int *pnDay, int *pnHour, int *pnMinute, int *pnSecond, int *pnTZFlag) const;
270  void SetField(int nIndex, char **papszValues);
271  OGRErr SetGeometry(OGRGeometry* pGeom);
272 protected:
273  virtual wxObjectRefData *CreateRefData() const;
274  virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const;
275 };
276 
284 class wxGISFeatureRefData : public wxObjectRefData
285 {
286  friend class wxGISFeature;
287 public:
288  wxGISFeatureRefData(OGRFeature *poFeature = NULL, const wxFontEncoding &oEncoding = wxLocale::GetSystemEncoding(), bool bRecodeToSystem = false)
289  {
290  m_poFeature = poFeature;
291  m_oEncoding = oEncoding;
292  m_bRecodeToSystem = bRecodeToSystem;
293  }
294 
295  virtual ~wxGISFeatureRefData(void)
296  {
297  if(m_poFeature)
298  OGRFeature::DestroyFeature(m_poFeature);
299  }
300 
302  : wxObjectRefData()
303  {
304  m_poFeature = data.m_poFeature;
305  m_oEncoding = data.m_oEncoding;
306  m_bRecodeToSystem = data.m_bRecodeToSystem;
307  }
308 
309  bool operator == (const wxGISFeatureRefData& data) const
310  {
311  return m_poFeature == data.m_poFeature;
312  }
313 
314  void SetEncoding(const wxFontEncoding &eEnc, bool bRecodeToSystem = false)
315  {
316  m_oEncoding = eEnc;
317  m_bRecodeToSystem = bRecodeToSystem;
318  }
319 
320 protected:
321  OGRFeature *m_poFeature;
322  wxFontEncoding m_oEncoding;
323  bool m_bRecodeToSystem;
324 };
325 
333 class WXDLLIMPEXP_GIS_DS wxGISGeometry : public wxObject
334 {
335  DECLARE_CLASS(wxGISGeometry)
336 public:
337  wxGISGeometry(OGRGeometry *poGeom = NULL, bool bOwnGeom = true);
338 
339  bool IsOk() const;
340 
341  bool operator == ( const wxGISGeometry& obj ) const;
342  bool operator != (const wxGISGeometry& obj) const { return !(*this == obj); };
343  operator OGRGeometry*() const;
344 
345  OGREnvelope GetEnvelope(void) const;
346  OGRGeometry* Copy(void) const;
347  OGRGeometry* Steal(void);
348  OGRPoint* GetCentroid(void);
349  wxGISSpatialReference GetSpatialReference() const;
350  void SetSpatialReference(const wxGISSpatialReference &SpaRef);
351 
352  wxGISGeometry Intersection(const wxGISGeometry &Geom) const;
353  wxGISGeometry UnionCascaded() const;
354  wxGISGeometry Union(const wxGISGeometry &Geom) const;
355  bool Intersects(const wxGISGeometry &Geom) const;
356  wxGISGeometry Buffer(double dfBuff, int nQuadSegs = 30) const;
357  bool Project(const wxGISSpatialReference &SpaRef);
358  bool Project(OGRCoordinateTransformation* const poCT);
359  OGRwkbGeometryType GetType() const;
360  wxGISGeometry Clone() const;
361 protected:
362  virtual wxObjectRefData *CreateRefData() const;
363  virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const;
364 };
365 
373 class wxGISGeometryRefData : public wxObjectRefData
374 {
375  friend class wxGISGeometry;
376 public:
377  wxGISGeometryRefData(OGRGeometry *poGeom = NULL, bool bOwnGeom = true)
378  {
379  m_poGeom = poGeom;
380  m_bOwnGeom = bOwnGeom;
381  }
382 
383  virtual ~wxGISGeometryRefData(void)
384  {
385  if (m_bOwnGeom && NULL != m_poGeom)
386  OGRGeometryFactory::destroyGeometry(m_poGeom);
387  }
388 
390  : wxObjectRefData()
391  {
392  m_poGeom = data.m_poGeom;
393  m_bOwnGeom = data.m_bOwnGeom;
394  }
395 
396  bool operator == (const wxGISGeometryRefData& data) const
397  {
398  return m_poGeom == data.m_poGeom;
399  }
400 
401 protected:
402  OGRGeometry *m_poGeom;
403  bool m_bOwnGeom;
404 };
405 
406 extern WXDLLIMPEXP_DATA_GIS_DS(wxGISGeometry) wxNullGeometry;
Definition: gdalinh.h:373
Definition: gdalinh.h:333
Definition: gdalinh.h:117
Definition: gdalinh.h:284
Definition: gdalinh.h:90
Definition: gdalinh.h:57