gooderp18绿色标准版
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

848 rindas
36KB

  1. /******************************************************************************
  2. * $Id: ogr_feature.h b1bcc1fb9ead43f093fa78f7126e332a51d2701a 2019-01-11 15:55:15 +0100 Even Rouault $
  3. *
  4. * Project: OpenGIS Simple Features Reference Implementation
  5. * Purpose: Class for representing a whole feature, and layer schemas.
  6. * Author: Frank Warmerdam, warmerdam@pobox.com
  7. *
  8. ******************************************************************************
  9. * Copyright (c) 1999, Les Technologies SoftMap Inc.
  10. * Copyright (c) 2008-2013, Even Rouault <even dot rouault at mines-paris dot org>
  11. *
  12. * Permission is hereby granted, free of charge, to any person obtaining a
  13. * copy of this software and associated documentation files (the "Software"),
  14. * to deal in the Software without restriction, including without limitation
  15. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  16. * and/or sell copies of the Software, and to permit persons to whom the
  17. * Software is furnished to do so, subject to the following conditions:
  18. *
  19. * The above copyright notice and this permission notice shall be included
  20. * in all copies or substantial portions of the Software.
  21. *
  22. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  23. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  24. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  25. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  26. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  27. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  28. * DEALINGS IN THE SOFTWARE.
  29. ****************************************************************************/
  30. #ifndef OGR_FEATURE_H_INCLUDED
  31. #define OGR_FEATURE_H_INCLUDED
  32. #include "cpl_atomic_ops.h"
  33. #include "ogr_featurestyle.h"
  34. #include "ogr_geometry.h"
  35. #include <exception>
  36. #include <memory>
  37. #include <string>
  38. #include <vector>
  39. /**
  40. * \file ogr_feature.h
  41. *
  42. * Simple feature classes.
  43. */
  44. #ifndef DEFINE_OGRFeatureH
  45. /*! @cond Doxygen_Suppress */
  46. #define DEFINE_OGRFeatureH
  47. /*! @endcond */
  48. #ifdef DEBUG
  49. typedef struct OGRFieldDefnHS *OGRFieldDefnH;
  50. typedef struct OGRFeatureDefnHS *OGRFeatureDefnH;
  51. typedef struct OGRFeatureHS *OGRFeatureH;
  52. typedef struct OGRStyleTableHS *OGRStyleTableH;
  53. #else
  54. /** Opaque type for a field definition (OGRFieldDefn) */
  55. typedef void *OGRFieldDefnH;
  56. /** Opaque type for a feature definition (OGRFeatureDefn) */
  57. typedef void *OGRFeatureDefnH;
  58. /** Opaque type for a feature (OGRFeature) */
  59. typedef void *OGRFeatureH;
  60. /** Opaque type for a style table (OGRStyleTable) */
  61. typedef void *OGRStyleTableH;
  62. #endif
  63. /** Opaque type for a geometry field definition (OGRGeomFieldDefn) */
  64. typedef struct OGRGeomFieldDefnHS *OGRGeomFieldDefnH;
  65. #endif /* DEFINE_OGRFeatureH */
  66. class OGRStyleTable;
  67. /************************************************************************/
  68. /* OGRFieldDefn */
  69. /************************************************************************/
  70. /**
  71. * Definition of an attribute of an OGRFeatureDefn. A field is described by :
  72. * <ul>
  73. * <li>a name. See SetName() / GetNameRef()</li>
  74. * <li>a type: OFTString, OFTInteger, OFTReal, ... See SetType() / GetType()</li>
  75. * <li>a subtype (optional): OFSTBoolean, ... See SetSubType() / GetSubType()</li>
  76. * <li>a width (optional): maximal number of characters. See SetWidth() / GetWidth()</li>
  77. * <li>a precision (optional): number of digits after decimal point. See SetPrecision() / GetPrecision()</li>
  78. * <li>a NOT NULL constraint (optional). See SetNullable() / IsNullable()</li>
  79. * <li>a default value (optional). See SetDefault() / GetDefault()</li>
  80. * <li>a boolean to indicate whether it should be ignored when retrieving features. See SetIgnored() / IsIgnored()</li>
  81. * </ul>
  82. */
  83. class CPL_DLL OGRFieldDefn
  84. {
  85. private:
  86. char *pszName;
  87. OGRFieldType eType;
  88. OGRJustification eJustify;
  89. int nWidth; // Zero is variable.
  90. int nPrecision;
  91. char *pszDefault;
  92. int bIgnore;
  93. OGRFieldSubType eSubType;
  94. int bNullable;
  95. public:
  96. OGRFieldDefn( const char *, OGRFieldType );
  97. explicit OGRFieldDefn( const OGRFieldDefn * );
  98. ~OGRFieldDefn();
  99. void SetName( const char * );
  100. const char *GetNameRef() const { return pszName; }
  101. OGRFieldType GetType() const { return eType; }
  102. void SetType( OGRFieldType eTypeIn );
  103. static const char *GetFieldTypeName( OGRFieldType );
  104. OGRFieldSubType GetSubType() const { return eSubType; }
  105. void SetSubType( OGRFieldSubType eSubTypeIn );
  106. static const char *GetFieldSubTypeName( OGRFieldSubType );
  107. OGRJustification GetJustify() const { return eJustify; }
  108. void SetJustify( OGRJustification eJustifyIn )
  109. { eJustify = eJustifyIn; }
  110. int GetWidth() const { return nWidth; }
  111. void SetWidth( int nWidthIn ) { nWidth = MAX(0,nWidthIn); }
  112. int GetPrecision() const { return nPrecision; }
  113. void SetPrecision( int nPrecisionIn )
  114. { nPrecision = nPrecisionIn; }
  115. void Set( const char *, OGRFieldType, int = 0, int = 0,
  116. OGRJustification = OJUndefined );
  117. void SetDefault( const char* );
  118. const char *GetDefault() const;
  119. int IsDefaultDriverSpecific() const;
  120. int IsIgnored() const { return bIgnore; }
  121. void SetIgnored( int bIgnoreIn ) { bIgnore = bIgnoreIn; }
  122. int IsNullable() const { return bNullable; }
  123. void SetNullable( int bNullableIn ) { bNullable = bNullableIn; }
  124. int IsSame( const OGRFieldDefn * ) const;
  125. /** Convert a OGRFieldDefn* to a OGRFieldDefnH.
  126. * @since GDAL 2.3
  127. */
  128. static inline OGRFieldDefnH ToHandle(OGRFieldDefn* poFieldDefn)
  129. { return reinterpret_cast<OGRFieldDefnH>(poFieldDefn); }
  130. /** Convert a OGRFieldDefnH to a OGRFieldDefn*.
  131. * @since GDAL 2.3
  132. */
  133. static inline OGRFieldDefn* FromHandle(OGRFieldDefnH hFieldDefn)
  134. { return reinterpret_cast<OGRFieldDefn*>(hFieldDefn); }
  135. private:
  136. CPL_DISALLOW_COPY_ASSIGN(OGRFieldDefn)
  137. };
  138. /************************************************************************/
  139. /* OGRGeomFieldDefn */
  140. /************************************************************************/
  141. /**
  142. * Definition of a geometry field of an OGRFeatureDefn. A geometry field is
  143. * described by :
  144. * <ul>
  145. * <li>a name. See SetName() / GetNameRef()</li>
  146. * <li>a type: wkbPoint, wkbLineString, ... See SetType() / GetType()</li>
  147. * <li>a spatial reference system (optional). See SetSpatialRef() / GetSpatialRef()</li>
  148. * <li>a NOT NULL constraint (optional). See SetNullable() / IsNullable()</li>
  149. * <li>a boolean to indicate whether it should be ignored when retrieving features. See SetIgnored() / IsIgnored()</li>
  150. * </ul>
  151. *
  152. * @since OGR 1.11
  153. */
  154. class CPL_DLL OGRGeomFieldDefn
  155. {
  156. protected:
  157. //! @cond Doxygen_Suppress
  158. char *pszName = nullptr;
  159. OGRwkbGeometryType eGeomType = wkbUnknown; /* all values possible except wkbNone */
  160. mutable OGRSpatialReference* poSRS = nullptr;
  161. int bIgnore = false;
  162. mutable int bNullable = true;
  163. void Initialize( const char *, OGRwkbGeometryType );
  164. //! @endcond
  165. public:
  166. OGRGeomFieldDefn( const char *pszNameIn,
  167. OGRwkbGeometryType eGeomTypeIn );
  168. explicit OGRGeomFieldDefn( const OGRGeomFieldDefn * );
  169. virtual ~OGRGeomFieldDefn();
  170. void SetName( const char * );
  171. const char *GetNameRef() const { return pszName; }
  172. OGRwkbGeometryType GetType() const { return eGeomType; }
  173. void SetType( OGRwkbGeometryType eTypeIn );
  174. virtual OGRSpatialReference* GetSpatialRef() const;
  175. void SetSpatialRef( OGRSpatialReference* poSRSIn );
  176. int IsIgnored() const { return bIgnore; }
  177. void SetIgnored( int bIgnoreIn ) { bIgnore = bIgnoreIn; }
  178. int IsNullable() const { return bNullable; }
  179. void SetNullable( int bNullableIn )
  180. { bNullable = bNullableIn; }
  181. int IsSame( const OGRGeomFieldDefn * ) const;
  182. /** Convert a OGRGeomFieldDefn* to a OGRGeomFieldDefnH.
  183. * @since GDAL 2.3
  184. */
  185. static inline OGRGeomFieldDefnH ToHandle(OGRGeomFieldDefn* poGeomFieldDefn)
  186. { return reinterpret_cast<OGRGeomFieldDefnH>(poGeomFieldDefn); }
  187. /** Convert a OGRGeomFieldDefnH to a OGRGeomFieldDefn*.
  188. * @since GDAL 2.3
  189. */
  190. static inline OGRGeomFieldDefn* FromHandle(OGRGeomFieldDefnH hGeomFieldDefn)
  191. { return reinterpret_cast<OGRGeomFieldDefn*>(hGeomFieldDefn); }
  192. private:
  193. CPL_DISALLOW_COPY_ASSIGN(OGRGeomFieldDefn)
  194. };
  195. /************************************************************************/
  196. /* OGRFeatureDefn */
  197. /************************************************************************/
  198. /**
  199. * Definition of a feature class or feature layer.
  200. *
  201. * This object contains schema information for a set of OGRFeatures. In
  202. * table based systems, an OGRFeatureDefn is essentially a layer. In more
  203. * object oriented approaches (such as SF CORBA) this can represent a class
  204. * of features but doesn't necessarily relate to all of a layer, or just one
  205. * layer.
  206. *
  207. * This object also can contain some other information such as a name and
  208. * potentially other metadata.
  209. *
  210. * It is essentially a collection of field descriptions (OGRFieldDefn class).
  211. * Starting with GDAL 1.11, in addition to attribute fields, it can also
  212. * contain multiple geometry fields (OGRGeomFieldDefn class).
  213. *
  214. * It is reasonable for different translators to derive classes from
  215. * OGRFeatureDefn with additional translator specific information.
  216. */
  217. class CPL_DLL OGRFeatureDefn
  218. {
  219. protected:
  220. //! @cond Doxygen_Suppress
  221. volatile int nRefCount;
  222. mutable int nFieldCount;
  223. mutable OGRFieldDefn **papoFieldDefn;
  224. mutable int nGeomFieldCount;
  225. mutable OGRGeomFieldDefn **papoGeomFieldDefn;
  226. char *pszFeatureClassName;
  227. int bIgnoreStyle;
  228. //! @endcond
  229. public:
  230. explicit OGRFeatureDefn( const char * pszName = nullptr );
  231. virtual ~OGRFeatureDefn();
  232. void SetName( const char* pszName );
  233. virtual const char *GetName() const;
  234. virtual int GetFieldCount() const;
  235. virtual OGRFieldDefn *GetFieldDefn( int i );
  236. virtual const OGRFieldDefn *GetFieldDefn( int i ) const;
  237. virtual int GetFieldIndex( const char * ) const;
  238. int GetFieldIndexCaseSensitive( const char * ) const;
  239. virtual void AddFieldDefn( OGRFieldDefn * );
  240. virtual OGRErr DeleteFieldDefn( int iField );
  241. virtual OGRErr ReorderFieldDefns( int* panMap );
  242. virtual int GetGeomFieldCount() const;
  243. virtual OGRGeomFieldDefn *GetGeomFieldDefn( int i );
  244. virtual const OGRGeomFieldDefn *GetGeomFieldDefn( int i ) const;
  245. virtual int GetGeomFieldIndex( const char * ) const;
  246. virtual void AddGeomFieldDefn( OGRGeomFieldDefn *,
  247. int bCopy = TRUE );
  248. virtual OGRErr DeleteGeomFieldDefn( int iGeomField );
  249. virtual OGRwkbGeometryType GetGeomType() const;
  250. virtual void SetGeomType( OGRwkbGeometryType );
  251. virtual OGRFeatureDefn *Clone() const;
  252. int Reference() { return CPLAtomicInc(&nRefCount); }
  253. int Dereference() { return CPLAtomicDec(&nRefCount); }
  254. int GetReferenceCount() const { return nRefCount; }
  255. void Release();
  256. virtual int IsGeometryIgnored() const;
  257. virtual void SetGeometryIgnored( int bIgnore );
  258. virtual int IsStyleIgnored() const { return bIgnoreStyle; }
  259. virtual void SetStyleIgnored( int bIgnore )
  260. { bIgnoreStyle = bIgnore; }
  261. virtual int IsSame( const OGRFeatureDefn * poOtherFeatureDefn ) const;
  262. //! @cond Doxygen_Suppress
  263. void ReserveSpaceForFields(int nFieldCountIn);
  264. //! @endcond
  265. std::vector<int> ComputeMapForSetFrom( const OGRFeatureDefn* poSrcFDefn,
  266. bool bForgiving = true ) const;
  267. static OGRFeatureDefn *CreateFeatureDefn( const char *pszName = nullptr );
  268. static void DestroyFeatureDefn( OGRFeatureDefn * );
  269. /** Convert a OGRFeatureDefn* to a OGRFeatureDefnH.
  270. * @since GDAL 2.3
  271. */
  272. static inline OGRFeatureDefnH ToHandle(OGRFeatureDefn* poFeatureDefn)
  273. { return reinterpret_cast<OGRFeatureDefnH>(poFeatureDefn); }
  274. /** Convert a OGRFeatureDefnH to a OGRFeatureDefn*.
  275. * @since GDAL 2.3
  276. */
  277. static inline OGRFeatureDefn* FromHandle(OGRFeatureDefnH hFeatureDefn)
  278. { return reinterpret_cast<OGRFeatureDefn*>(hFeatureDefn); }
  279. private:
  280. CPL_DISALLOW_COPY_ASSIGN(OGRFeatureDefn)
  281. };
  282. /************************************************************************/
  283. /* OGRFeature */
  284. /************************************************************************/
  285. /**
  286. * A simple feature, including geometry and attributes.
  287. */
  288. class CPL_DLL OGRFeature
  289. {
  290. private:
  291. GIntBig nFID;
  292. OGRFeatureDefn *poDefn;
  293. OGRGeometry **papoGeometries;
  294. OGRField *pauFields;
  295. char *m_pszNativeData;
  296. char *m_pszNativeMediaType;
  297. bool SetFieldInternal( int i, OGRField * puValue );
  298. protected:
  299. //! @cond Doxygen_Suppress
  300. mutable char *m_pszStyleString;
  301. mutable OGRStyleTable *m_poStyleTable;
  302. mutable char *m_pszTmpFieldValue;
  303. //! @endcond
  304. bool CopySelfTo( OGRFeature *poNew ) const;
  305. public:
  306. explicit OGRFeature( OGRFeatureDefn * );
  307. virtual ~OGRFeature();
  308. /** Field value. */
  309. class CPL_DLL FieldValue
  310. {
  311. friend class OGRFeature;
  312. struct Private;
  313. std::unique_ptr<Private> m_poPrivate;
  314. FieldValue(OGRFeature* poFeature, int iFieldIndex);
  315. FieldValue(const OGRFeature* poFeature, int iFieldIndex);
  316. FieldValue(const FieldValue& oOther) = delete;
  317. public:
  318. //! @cond Doxygen_Suppress
  319. ~FieldValue();
  320. //! @endcond
  321. /** Set a field value from another one. */
  322. FieldValue& operator= (const FieldValue& oOther);
  323. /** Set an integer value to the field. */
  324. FieldValue& operator= (int nVal);
  325. /** Set an integer value to the field. */
  326. FieldValue& operator= (GIntBig nVal);
  327. /** Set a real value to the field. */
  328. FieldValue& operator= (double dfVal);
  329. /** Set a string value to the field. */
  330. FieldValue& operator= (const char *pszVal);
  331. /** Set a string value to the field. */
  332. FieldValue& operator= (const std::string& osVal);
  333. /** Set an array of integer to the field. */
  334. FieldValue& operator= (const std::vector<int>& oArray);
  335. /** Set an array of big integer to the field. */
  336. FieldValue& operator= (const std::vector<GIntBig>& oArray);
  337. /** Set an array of double to the field. */
  338. FieldValue& operator= (const std::vector<double>& oArray);
  339. /** Set an array of strings to the field. */
  340. FieldValue& operator= (const std::vector<std::string>& oArray);
  341. /** Set an array of strings to the field. */
  342. FieldValue& operator= (CSLConstList papszValues);
  343. /** Set a null value to the field. */
  344. void SetNull();
  345. /** Unset the field. */
  346. void clear();
  347. /** Unset the field. */
  348. void Unset() { clear(); }
  349. /** Set date time value/ */
  350. void SetDateTime(int nYear, int nMonth, int nDay,
  351. int nHour=0, int nMinute=0, float fSecond=0.f,
  352. int nTZFlag = 0 );
  353. /** Return field index. */
  354. int GetIndex() const;
  355. /** Return field definition. */
  356. const OGRFieldDefn* GetDefn() const;
  357. /** Return field name. */
  358. const char* GetName() const { return GetDefn()->GetNameRef(); }
  359. /** Return field type. */
  360. OGRFieldType GetType() const { return GetDefn()->GetType(); }
  361. /** Return field subtype. */
  362. OGRFieldSubType GetSubType() const { return GetDefn()->GetSubType(); }
  363. /** Return whether the field value is unset/empty. */
  364. // cppcheck-suppress functionStatic
  365. bool empty() const { return IsUnset(); }
  366. /** Return whether the field value is unset/empty. */
  367. // cppcheck-suppress functionStatic
  368. bool IsUnset() const;
  369. /** Return whether the field value is null. */
  370. // cppcheck-suppress functionStatic
  371. bool IsNull() const;
  372. /** Return the raw field value */
  373. const OGRField *GetRawValue() const;
  374. /** Return the integer value.
  375. * Only use that method if and only if GetType() == OFTInteger.
  376. */
  377. // cppcheck-suppress functionStatic
  378. int GetInteger() const { return GetRawValue()->Integer; }
  379. /** Return the 64-bit integer value.
  380. * Only use that method if and only if GetType() == OFTInteger64.
  381. */
  382. // cppcheck-suppress functionStatic
  383. GIntBig GetInteger64() const { return GetRawValue()->Integer64; }
  384. /** Return the double value.
  385. * Only use that method if and only if GetType() == OFTReal.
  386. */
  387. // cppcheck-suppress functionStatic
  388. double GetDouble() const { return GetRawValue()->Real; }
  389. /** Return the string value.
  390. * Only use that method if and only if GetType() == OFTString.
  391. */
  392. // cppcheck-suppress functionStatic
  393. const char* GetString() const { return GetRawValue()->String; }
  394. /** Return the date/time/datetime value. */
  395. bool GetDateTime( int *pnYear, int *pnMonth,
  396. int *pnDay,
  397. int *pnHour, int *pnMinute,
  398. float *pfSecond,
  399. int *pnTZFlag ) const;
  400. /** Return the field value as integer, with potential conversion */
  401. operator int () const { return GetAsInteger(); }
  402. /** Return the field value as 64-bit integer, with potential conversion */
  403. operator GIntBig() const { return GetAsInteger64(); }
  404. /** Return the field value as double, with potential conversion */
  405. operator double () const { return GetAsDouble(); }
  406. /** Return the field value as string, with potential conversion */
  407. operator const char*() const { return GetAsString(); }
  408. /** Return the field value as integer list, with potential conversion */
  409. operator const std::vector<int>& () const { return GetAsIntegerList(); }
  410. /** Return the field value as 64-bit integer list, with potential conversion */
  411. operator const std::vector<GIntBig>& () const { return GetAsInteger64List(); }
  412. /** Return the field value as double list, with potential conversion */
  413. operator const std::vector<double>& () const { return GetAsDoubleList(); }
  414. /** Return the field value as string list, with potential conversion */
  415. operator const std::vector<std::string>& () const { return GetAsStringList(); }
  416. /** Return the field value as string list, with potential conversion */
  417. operator CSLConstList () const;
  418. /** Return the field value as integer, with potential conversion */
  419. int GetAsInteger() const;
  420. /** Return the field value as 64-bit integer, with potential conversion */
  421. GIntBig GetAsInteger64() const;
  422. /** Return the field value as double, with potential conversion */
  423. double GetAsDouble() const;
  424. /** Return the field value as string, with potential conversion */
  425. const char* GetAsString() const;
  426. /** Return the field value as integer list, with potential conversion */
  427. const std::vector<int>& GetAsIntegerList() const;
  428. /** Return the field value as 64-bit integer list, with potential conversion */
  429. const std::vector<GIntBig>& GetAsInteger64List() const;
  430. /** Return the field value as double list, with potential conversion */
  431. const std::vector<double>& GetAsDoubleList() const;
  432. /** Return the field value as string list, with potential conversion */
  433. const std::vector<std::string>& GetAsStringList() const;
  434. };
  435. /** Field value iterator class. */
  436. class CPL_DLL ConstFieldIterator
  437. {
  438. friend class OGRFeature;
  439. struct Private;
  440. std::unique_ptr<Private> m_poPrivate;
  441. ConstFieldIterator(const OGRFeature* poSelf, int nPos);
  442. public:
  443. //! @cond Doxygen_Suppress
  444. ConstFieldIterator(ConstFieldIterator&& oOther) noexcept; // declared but not defined. Needed for gcc 5.4 at least
  445. ~ConstFieldIterator();
  446. const FieldValue& operator*() const;
  447. ConstFieldIterator& operator++();
  448. bool operator!=(const ConstFieldIterator& it) const;
  449. //! @endcond
  450. };
  451. /** Return begin of field value iterator.
  452. *
  453. * Using this iterator for standard range-based loops is safe, but
  454. * due to implementation limitations, you shouldn't try to access
  455. * (dereference) more than one iterator step at a time, since you will get
  456. * a reference to the same object (FieldValue) at each iteration step.
  457. *
  458. * <pre>
  459. * for( auto&& oField: poFeature )
  460. * {
  461. * std::cout << oField.GetIndex() << "," << oField.GetName()<< ": " << oField.GetAsString() << std::endl;
  462. * }
  463. * </pre>
  464. *
  465. * @since GDAL 2.3
  466. */
  467. ConstFieldIterator begin() const;
  468. /** Return end of field value iterator. */
  469. ConstFieldIterator end() const;
  470. const FieldValue operator[](int iField) const;
  471. FieldValue operator[](int iField);
  472. /** Exception raised by operator[](const char*) when a field is not found. */
  473. class FieldNotFoundException: public std::exception {};
  474. const FieldValue operator[](const char* pszFieldName) const;
  475. FieldValue operator[](const char* pszFieldName);
  476. OGRFeatureDefn *GetDefnRef() { return poDefn; }
  477. const OGRFeatureDefn *GetDefnRef() const { return poDefn; }
  478. OGRErr SetGeometryDirectly( OGRGeometry * );
  479. OGRErr SetGeometry( const OGRGeometry * );
  480. OGRGeometry *GetGeometryRef();
  481. const OGRGeometry *GetGeometryRef() const;
  482. OGRGeometry *StealGeometry() CPL_WARN_UNUSED_RESULT;
  483. int GetGeomFieldCount() const
  484. { return poDefn->GetGeomFieldCount(); }
  485. OGRGeomFieldDefn *GetGeomFieldDefnRef( int iField )
  486. { return poDefn->GetGeomFieldDefn(iField); }
  487. const OGRGeomFieldDefn *GetGeomFieldDefnRef( int iField ) const
  488. { return poDefn->GetGeomFieldDefn(iField); }
  489. int GetGeomFieldIndex( const char * pszName ) const
  490. { return poDefn->GetGeomFieldIndex(pszName); }
  491. OGRGeometry* GetGeomFieldRef( int iField );
  492. const OGRGeometry* GetGeomFieldRef( int iField ) const;
  493. OGRGeometry* StealGeometry( int iField );
  494. OGRGeometry* GetGeomFieldRef( const char* pszFName );
  495. const OGRGeometry* GetGeomFieldRef( const char* pszFName ) const;
  496. OGRErr SetGeomFieldDirectly( int iField, OGRGeometry * );
  497. OGRErr SetGeomField( int iField, const OGRGeometry * );
  498. OGRFeature *Clone() const CPL_WARN_UNUSED_RESULT;
  499. virtual OGRBoolean Equal( const OGRFeature * poFeature ) const;
  500. int GetFieldCount() const
  501. { return poDefn->GetFieldCount(); }
  502. const OGRFieldDefn *GetFieldDefnRef( int iField ) const
  503. { return poDefn->GetFieldDefn(iField); }
  504. OGRFieldDefn *GetFieldDefnRef( int iField )
  505. { return poDefn->GetFieldDefn(iField); }
  506. int GetFieldIndex( const char * pszName ) const
  507. { return poDefn->GetFieldIndex(pszName); }
  508. int IsFieldSet( int iField ) const;
  509. void UnsetField( int iField );
  510. bool IsFieldNull( int iField ) const;
  511. void SetFieldNull( int iField );
  512. bool IsFieldSetAndNotNull( int iField ) const;
  513. OGRField *GetRawFieldRef( int i ) { return pauFields + i; }
  514. const OGRField *GetRawFieldRef( int i ) const { return pauFields + i; }
  515. int GetFieldAsInteger( int i ) const;
  516. GIntBig GetFieldAsInteger64( int i ) const;
  517. double GetFieldAsDouble( int i ) const;
  518. const char *GetFieldAsString( int i ) const;
  519. const int *GetFieldAsIntegerList( int i, int *pnCount ) const;
  520. const GIntBig *GetFieldAsInteger64List( int i, int *pnCount ) const;
  521. const double *GetFieldAsDoubleList( int i, int *pnCount ) const;
  522. char **GetFieldAsStringList( int i ) const;
  523. GByte *GetFieldAsBinary( int i, int *pnCount ) const;
  524. int GetFieldAsDateTime( int i,
  525. int *pnYear, int *pnMonth,
  526. int *pnDay,
  527. int *pnHour, int *pnMinute,
  528. int *pnSecond,
  529. int *pnTZFlag ) const;
  530. int GetFieldAsDateTime( int i,
  531. int *pnYear, int *pnMonth,
  532. int *pnDay,
  533. int *pnHour, int *pnMinute,
  534. float *pfSecond,
  535. int *pnTZFlag ) const;
  536. char *GetFieldAsSerializedJSon( int i ) const;
  537. int GetFieldAsInteger( const char *pszFName ) const
  538. { return GetFieldAsInteger( GetFieldIndex(pszFName) ); }
  539. GIntBig GetFieldAsInteger64( const char *pszFName ) const
  540. { return GetFieldAsInteger64( GetFieldIndex(pszFName) ); }
  541. double GetFieldAsDouble( const char *pszFName ) const
  542. { return GetFieldAsDouble( GetFieldIndex(pszFName) ); }
  543. const char *GetFieldAsString( const char *pszFName ) const
  544. { return GetFieldAsString( GetFieldIndex(pszFName) ); }
  545. const int *GetFieldAsIntegerList( const char *pszFName,
  546. int *pnCount ) const
  547. { return GetFieldAsIntegerList( GetFieldIndex(pszFName),
  548. pnCount ); }
  549. const GIntBig *GetFieldAsInteger64List( const char *pszFName,
  550. int *pnCount ) const
  551. { return GetFieldAsInteger64List( GetFieldIndex(pszFName),
  552. pnCount ); }
  553. const double *GetFieldAsDoubleList( const char *pszFName,
  554. int *pnCount ) const
  555. { return GetFieldAsDoubleList( GetFieldIndex(pszFName),
  556. pnCount ); }
  557. char **GetFieldAsStringList( const char *pszFName ) const
  558. { return GetFieldAsStringList(GetFieldIndex(pszFName)); }
  559. void SetField( int i, int nValue );
  560. void SetField( int i, GIntBig nValue );
  561. void SetField( int i, double dfValue );
  562. void SetField( int i, const char * pszValue );
  563. void SetField( int i, int nCount, const int * panValues );
  564. void SetField( int i, int nCount,
  565. const GIntBig * panValues );
  566. void SetField( int i, int nCount, const double * padfValues );
  567. void SetField( int i, const char * const * papszValues );
  568. void SetField( int i, OGRField * puValue );
  569. void SetField( int i, int nCount, const void * pabyBinary );
  570. void SetField( int i, int nYear, int nMonth, int nDay,
  571. int nHour=0, int nMinute=0, float fSecond=0.f,
  572. int nTZFlag = 0 );
  573. void SetField( const char *pszFName, int nValue )
  574. { SetField( GetFieldIndex(pszFName), nValue ); }
  575. void SetField( const char *pszFName, GIntBig nValue )
  576. { SetField( GetFieldIndex(pszFName), nValue ); }
  577. void SetField( const char *pszFName, double dfValue )
  578. { SetField( GetFieldIndex(pszFName), dfValue ); }
  579. void SetField( const char *pszFName, const char * pszValue )
  580. { SetField( GetFieldIndex(pszFName), pszValue ); }
  581. void SetField( const char *pszFName, int nCount,
  582. const int * panValues )
  583. { SetField(GetFieldIndex(pszFName),nCount,panValues); }
  584. void SetField( const char *pszFName, int nCount,
  585. const GIntBig * panValues )
  586. { SetField(GetFieldIndex(pszFName),nCount,panValues); }
  587. void SetField( const char *pszFName, int nCount,
  588. const double * padfValues )
  589. {SetField(GetFieldIndex(pszFName),nCount,padfValues); }
  590. void SetField( const char *pszFName, const char * const * papszValues )
  591. { SetField( GetFieldIndex(pszFName), papszValues); }
  592. void SetField( const char *pszFName, OGRField * puValue )
  593. { SetField( GetFieldIndex(pszFName), puValue ); }
  594. void SetField( const char *pszFName,
  595. int nYear, int nMonth, int nDay,
  596. int nHour=0, int nMinute=0, float fSecond=0.f,
  597. int nTZFlag = 0 )
  598. { SetField( GetFieldIndex(pszFName),
  599. nYear, nMonth, nDay,
  600. nHour, nMinute, fSecond, nTZFlag ); }
  601. GIntBig GetFID() const { return nFID; }
  602. virtual OGRErr SetFID( GIntBig nFIDIn );
  603. void DumpReadable( FILE *, char** papszOptions = nullptr ) const;
  604. OGRErr SetFrom( const OGRFeature *, int = TRUE );
  605. OGRErr SetFrom( const OGRFeature *, const int *, int = TRUE );
  606. OGRErr SetFieldsFrom( const OGRFeature *, const int *, int = TRUE );
  607. //! @cond Doxygen_Suppress
  608. OGRErr RemapFields( OGRFeatureDefn *poNewDefn,
  609. const int *panRemapSource );
  610. void AppendField();
  611. OGRErr RemapGeomFields( OGRFeatureDefn *poNewDefn,
  612. const int *panRemapSource );
  613. //! @endcond
  614. int Validate( int nValidateFlags,
  615. int bEmitError ) const;
  616. void FillUnsetWithDefault( int bNotNullableOnly,
  617. char** papszOptions );
  618. virtual const char *GetStyleString() const;
  619. virtual void SetStyleString( const char * );
  620. virtual void SetStyleStringDirectly( char * );
  621. /** Return style table.
  622. * @return style table.
  623. */
  624. virtual OGRStyleTable *GetStyleTable() const { return m_poStyleTable; } /* f.i.x.m.e: add a const qualifier for return type */
  625. virtual void SetStyleTable( OGRStyleTable *poStyleTable );
  626. virtual void SetStyleTableDirectly( OGRStyleTable *poStyleTable );
  627. const char *GetNativeData() const { return m_pszNativeData; }
  628. const char *GetNativeMediaType() const
  629. { return m_pszNativeMediaType; }
  630. void SetNativeData( const char* pszNativeData );
  631. void SetNativeMediaType( const char* pszNativeMediaType );
  632. static OGRFeature *CreateFeature( OGRFeatureDefn * );
  633. static void DestroyFeature( OGRFeature * );
  634. /** Convert a OGRFeature* to a OGRFeatureH.
  635. * @since GDAL 2.3
  636. */
  637. static inline OGRFeatureH ToHandle(OGRFeature* poFeature)
  638. { return reinterpret_cast<OGRFeatureH>(poFeature); }
  639. /** Convert a OGRFeatureH to a OGRFeature*.
  640. * @since GDAL 2.3
  641. */
  642. static inline OGRFeature* FromHandle(OGRFeatureH hFeature)
  643. { return reinterpret_cast<OGRFeature*>(hFeature); }
  644. private:
  645. CPL_DISALLOW_COPY_ASSIGN(OGRFeature)
  646. };
  647. //! @cond Doxygen_Suppress
  648. struct CPL_DLL OGRFeatureUniquePtrDeleter
  649. {
  650. void operator()(OGRFeature*) const;
  651. };
  652. //! @endcond
  653. /** Unique pointer type for OGRFeature.
  654. * @since GDAL 2.3
  655. */
  656. typedef std::unique_ptr<OGRFeature, OGRFeatureUniquePtrDeleter> OGRFeatureUniquePtr;
  657. //! @cond Doxygen_Suppress
  658. /** @see OGRFeature::begin() const */
  659. inline OGRFeature::ConstFieldIterator begin(const OGRFeature* poFeature) { return poFeature->begin(); }
  660. /** @see OGRFeature::end() const */
  661. inline OGRFeature::ConstFieldIterator end(const OGRFeature* poFeature) { return poFeature->end(); }
  662. /** @see OGRFeature::begin() const */
  663. inline OGRFeature::ConstFieldIterator begin(const OGRFeatureUniquePtr& poFeature) { return poFeature->begin(); }
  664. /** @see OGRFeature::end() const */
  665. inline OGRFeature::ConstFieldIterator end(const OGRFeatureUniquePtr& poFeature) { return poFeature->end(); }
  666. //! @endcond
  667. /************************************************************************/
  668. /* OGRFeatureQuery */
  669. /************************************************************************/
  670. //! @cond Doxygen_Suppress
  671. class OGRLayer;
  672. class swq_expr_node;
  673. class swq_custom_func_registrar;
  674. class CPL_DLL OGRFeatureQuery
  675. {
  676. private:
  677. OGRFeatureDefn *poTargetDefn;
  678. void *pSWQExpr;
  679. char **FieldCollector( void *, char ** );
  680. GIntBig *EvaluateAgainstIndices( swq_expr_node*, OGRLayer *,
  681. GIntBig& nFIDCount );
  682. int CanUseIndex( swq_expr_node*, OGRLayer * );
  683. OGRErr Compile( OGRLayer *, OGRFeatureDefn*, const char *,
  684. int bCheck,
  685. swq_custom_func_registrar* poCustomFuncRegistrar );
  686. CPL_DISALLOW_COPY_ASSIGN(OGRFeatureQuery)
  687. public:
  688. OGRFeatureQuery();
  689. ~OGRFeatureQuery();
  690. OGRErr Compile( OGRLayer *, const char *,
  691. int bCheck = TRUE,
  692. swq_custom_func_registrar*
  693. poCustomFuncRegistrar = nullptr );
  694. OGRErr Compile( OGRFeatureDefn *, const char *,
  695. int bCheck = TRUE,
  696. swq_custom_func_registrar*
  697. poCustomFuncRegistrar = nullptr );
  698. int Evaluate( OGRFeature * );
  699. GIntBig *EvaluateAgainstIndices( OGRLayer *, OGRErr * );
  700. int CanUseIndex( OGRLayer * );
  701. char **GetUsedFields();
  702. void *GetSWQExpr() { return pSWQExpr; }
  703. };
  704. //! @endcond
  705. #endif /* ndef OGR_FEATURE_H_INCLUDED */
上海开阖软件有限公司 沪ICP备12045867号-1