gooderp18绿色标准版
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

2946 lines
114KB

  1. /******************************************************************************
  2. * $Id: ogr_geometry.h 0ca04053b3a7d0ebc1f0ecdc86e7084162945176 2019-06-13 10:53:23 +0200 Even Rouault $
  3. *
  4. * Project: OpenGIS Simple Features Reference Implementation
  5. * Purpose: Classes for manipulating simple features that is not specific
  6. * to a particular interface technology.
  7. * Author: Frank Warmerdam, warmerdam@pobox.com
  8. *
  9. ******************************************************************************
  10. * Copyright (c) 1999, Frank Warmerdam
  11. * Copyright (c) 2008-2014, Even Rouault <even dot rouault at mines-paris dot org>
  12. *
  13. * Permission is hereby granted, free of charge, to any person obtaining a
  14. * copy of this software and associated documentation files (the "Software"),
  15. * to deal in the Software without restriction, including without limitation
  16. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  17. * and/or sell copies of the Software, and to permit persons to whom the
  18. * Software is furnished to do so, subject to the following conditions:
  19. *
  20. * The above copyright notice and this permission notice shall be included
  21. * in all copies or substantial portions of the Software.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  24. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  25. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  26. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  27. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  28. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  29. * DEALINGS IN THE SOFTWARE.
  30. ****************************************************************************/
  31. #ifndef OGR_GEOMETRY_H_INCLUDED
  32. #define OGR_GEOMETRY_H_INCLUDED
  33. #include "cpl_conv.h"
  34. #include "cpl_json.h"
  35. #include "ogr_core.h"
  36. #include "ogr_spatialref.h"
  37. #include <memory>
  38. /**
  39. * \file ogr_geometry.h
  40. *
  41. * Simple feature geometry classes.
  42. */
  43. /*! @cond Doxygen_Suppress */
  44. #ifndef DEFINEH_OGRGeometryH
  45. #define DEFINEH_OGRGeometryH
  46. #ifdef DEBUG
  47. typedef struct OGRGeometryHS *OGRGeometryH;
  48. #else
  49. typedef void *OGRGeometryH;
  50. #endif
  51. #endif /* DEFINEH_OGRGeometryH */
  52. /*! @endcond */
  53. /**
  54. * Simple container for a position.
  55. */
  56. class OGRRawPoint
  57. {
  58. public:
  59. /** Constructor */
  60. OGRRawPoint() : x(0.0), y(0.0) {}
  61. /** Constructor */
  62. OGRRawPoint(double xIn, double yIn) : x(xIn), y(yIn) {}
  63. /** x */
  64. double x;
  65. /** y */
  66. double y;
  67. };
  68. /** GEOS geometry type */
  69. typedef struct GEOSGeom_t *GEOSGeom;
  70. /** GEOS context handle type */
  71. typedef struct GEOSContextHandle_HS *GEOSContextHandle_t;
  72. /** SFCGAL geometry type */
  73. typedef void sfcgal_geometry_t;
  74. class OGRPoint;
  75. class OGRCurve;
  76. class OGRCompoundCurve;
  77. class OGRSimpleCurve;
  78. class OGRLinearRing;
  79. class OGRLineString;
  80. class OGRCircularString;
  81. class OGRSurface;
  82. class OGRCurvePolygon;
  83. class OGRPolygon;
  84. class OGRMultiPoint;
  85. class OGRMultiSurface;
  86. class OGRMultiPolygon;
  87. class OGRMultiCurve;
  88. class OGRMultiLineString;
  89. class OGRGeometryCollection;
  90. class OGRTriangle;
  91. class OGRPolyhedralSurface;
  92. class OGRTriangulatedSurface;
  93. //! @cond Doxygen_Suppress
  94. typedef OGRLineString* (*OGRCurveCasterToLineString)(OGRCurve*);
  95. typedef OGRLinearRing* (*OGRCurveCasterToLinearRing)(OGRCurve*);
  96. typedef OGRPolygon* (*OGRSurfaceCasterToPolygon)(OGRSurface*);
  97. typedef OGRCurvePolygon* (*OGRSurfaceCasterToCurvePolygon)(OGRSurface*);
  98. typedef OGRMultiPolygon* (*OGRPolyhedralSurfaceCastToMultiPolygon)(OGRPolyhedralSurface*);
  99. //! @endcond
  100. /** OGRGeometry visitor interface.
  101. * @since GDAL 2.3
  102. */
  103. class CPL_DLL IOGRGeometryVisitor
  104. {
  105. public:
  106. /** Destructor/ */
  107. virtual ~IOGRGeometryVisitor() = default;
  108. /** Visit OGRPoint. */
  109. virtual void visit(OGRPoint*) = 0;
  110. /** Visit OGRLineString. */
  111. virtual void visit(OGRLineString*) = 0;
  112. /** Visit OGRLinearRing. */
  113. virtual void visit(OGRLinearRing*) = 0;
  114. /** Visit OGRPolygon. */
  115. virtual void visit(OGRPolygon*) = 0;
  116. /** Visit OGRMultiPoint. */
  117. virtual void visit(OGRMultiPoint*) = 0;
  118. /** Visit OGRMultiLineString. */
  119. virtual void visit(OGRMultiLineString*) = 0;
  120. /** Visit OGRMultiPolygon. */
  121. virtual void visit(OGRMultiPolygon*) = 0;
  122. /** Visit OGRGeometryCollection. */
  123. virtual void visit(OGRGeometryCollection*) = 0;
  124. /** Visit OGRCircularString. */
  125. virtual void visit(OGRCircularString*) = 0;
  126. /** Visit OGRCompoundCurve. */
  127. virtual void visit(OGRCompoundCurve*) = 0;
  128. /** Visit OGRCurvePolygon. */
  129. virtual void visit(OGRCurvePolygon*) = 0;
  130. /** Visit OGRMultiCurve. */
  131. virtual void visit(OGRMultiCurve*) = 0;
  132. /** Visit OGRMultiSurface. */
  133. virtual void visit(OGRMultiSurface*) = 0;
  134. /** Visit OGRTriangle. */
  135. virtual void visit(OGRTriangle*) = 0;
  136. /** Visit OGRPolyhedralSurface. */
  137. virtual void visit(OGRPolyhedralSurface*) = 0;
  138. /** Visit OGRTriangulatedSurface. */
  139. virtual void visit(OGRTriangulatedSurface*) = 0;
  140. };
  141. /** OGRGeometry visitor default implementation.
  142. *
  143. * This default implementation will recurse down to calling
  144. * visit(OGRPoint*) on each point.
  145. *
  146. * @since GDAL 2.3
  147. */
  148. class CPL_DLL OGRDefaultGeometryVisitor: public IOGRGeometryVisitor
  149. {
  150. void _visit(OGRSimpleCurve* poGeom);
  151. public:
  152. void visit(OGRPoint*) override {}
  153. void visit(OGRLineString*) override;
  154. void visit(OGRLinearRing*) override;
  155. void visit(OGRPolygon*) override;
  156. void visit(OGRMultiPoint*) override;
  157. void visit(OGRMultiLineString*) override;
  158. void visit(OGRMultiPolygon*) override;
  159. void visit(OGRGeometryCollection*) override;
  160. void visit(OGRCircularString*) override;
  161. void visit(OGRCompoundCurve*) override;
  162. void visit(OGRCurvePolygon*) override;
  163. void visit(OGRMultiCurve*) override;
  164. void visit(OGRMultiSurface*) override;
  165. void visit(OGRTriangle*) override;
  166. void visit(OGRPolyhedralSurface*) override;
  167. void visit(OGRTriangulatedSurface*) override;
  168. };
  169. /** OGRGeometry visitor interface.
  170. * @since GDAL 2.3
  171. */
  172. class CPL_DLL IOGRConstGeometryVisitor
  173. {
  174. public:
  175. /** Destructor/ */
  176. virtual ~IOGRConstGeometryVisitor() = default;
  177. /** Visit OGRPoint. */
  178. virtual void visit(const OGRPoint*) = 0;
  179. /** Visit OGRLineString. */
  180. virtual void visit(const OGRLineString*) = 0;
  181. /** Visit OGRLinearRing. */
  182. virtual void visit(const OGRLinearRing*) = 0;
  183. /** Visit OGRPolygon. */
  184. virtual void visit(const OGRPolygon*) = 0;
  185. /** Visit OGRMultiPoint. */
  186. virtual void visit(const OGRMultiPoint*) = 0;
  187. /** Visit OGRMultiLineString. */
  188. virtual void visit(const OGRMultiLineString*) = 0;
  189. /** Visit OGRMultiPolygon. */
  190. virtual void visit(const OGRMultiPolygon*) = 0;
  191. /** Visit OGRGeometryCollection. */
  192. virtual void visit(const OGRGeometryCollection*) = 0;
  193. /** Visit OGRCircularString. */
  194. virtual void visit(const OGRCircularString*) = 0;
  195. /** Visit OGRCompoundCurve. */
  196. virtual void visit(const OGRCompoundCurve*) = 0;
  197. /** Visit OGRCurvePolygon. */
  198. virtual void visit(const OGRCurvePolygon*) = 0;
  199. /** Visit OGRMultiCurve. */
  200. virtual void visit(const OGRMultiCurve*) = 0;
  201. /** Visit OGRMultiSurface. */
  202. virtual void visit(const OGRMultiSurface*) = 0;
  203. /** Visit OGRTriangle. */
  204. virtual void visit(const OGRTriangle*) = 0;
  205. /** Visit OGRPolyhedralSurface. */
  206. virtual void visit(const OGRPolyhedralSurface*) = 0;
  207. /** Visit OGRTriangulatedSurface. */
  208. virtual void visit(const OGRTriangulatedSurface*) = 0;
  209. };
  210. /** OGRGeometry visitor default implementation.
  211. *
  212. * This default implementation will recurse down to calling
  213. * visit(const OGRPoint*) on each point.
  214. *
  215. * @since GDAL 2.3
  216. */
  217. class CPL_DLL OGRDefaultConstGeometryVisitor: public IOGRConstGeometryVisitor
  218. {
  219. void _visit(const OGRSimpleCurve* poGeom);
  220. public:
  221. void visit(const OGRPoint*) override {}
  222. void visit(const OGRLineString*) override;
  223. void visit(const OGRLinearRing*) override;
  224. void visit(const OGRPolygon*) override;
  225. void visit(const OGRMultiPoint*) override;
  226. void visit(const OGRMultiLineString*) override;
  227. void visit(const OGRMultiPolygon*) override;
  228. void visit(const OGRGeometryCollection*) override;
  229. void visit(const OGRCircularString*) override;
  230. void visit(const OGRCompoundCurve*) override;
  231. void visit(const OGRCurvePolygon*) override;
  232. void visit(const OGRMultiCurve*) override;
  233. void visit(const OGRMultiSurface*) override;
  234. void visit(const OGRTriangle*) override;
  235. void visit(const OGRPolyhedralSurface*) override;
  236. void visit(const OGRTriangulatedSurface*) override;
  237. };
  238. /************************************************************************/
  239. /* OGRGeometry */
  240. /************************************************************************/
  241. /**
  242. * Abstract base class for all geometry classes.
  243. *
  244. * Some spatial analysis methods require that OGR is built on the GEOS library
  245. * to work properly. The precise meaning of methods that describe spatial
  246. * relationships between geometries is described in the SFCOM, or other simple
  247. * features interface specifications, like "OpenGIS® Implementation
  248. * Specification for Geographic information - Simple feature access - Part 1:
  249. * Common architecture":
  250. * <a href="http://www.opengeospatial.org/standards/sfa">OGC 06-103r4</a>
  251. *
  252. * In GDAL 2.0, the hierarchy of classes has been extended with
  253. * <a href="https://portal.opengeospatial.org/files/?artifact_id=32024">
  254. * (working draft) ISO SQL/MM Part 3 (ISO/IEC 13249-3)</a> curve geometries :
  255. * CIRCULARSTRING (OGRCircularString), COMPOUNDCURVE (OGRCompoundCurve),
  256. * CURVEPOLYGON (OGRCurvePolygon), MULTICURVE (OGRMultiCurve) and
  257. * MULTISURFACE (OGRMultiSurface).
  258. *
  259. */
  260. class CPL_DLL OGRGeometry
  261. {
  262. private:
  263. OGRSpatialReference * poSRS = nullptr; // may be NULL
  264. protected:
  265. //! @cond Doxygen_Suppress
  266. friend class OGRCurveCollection;
  267. unsigned int flags = 0;
  268. OGRErr importPreambleFromWkt( const char ** ppszInput,
  269. int* pbHasZ, int* pbHasM,
  270. bool* pbIsEmpty );
  271. OGRErr importCurveCollectionFromWkt(
  272. const char ** ppszInput,
  273. int bAllowEmptyComponent,
  274. int bAllowLineString,
  275. int bAllowCurve,
  276. int bAllowCompoundCurve,
  277. OGRErr (*pfnAddCurveDirectly)(OGRGeometry* poSelf,
  278. OGRCurve* poCurve) );
  279. OGRErr importPreambleFromWkb( const unsigned char * pabyData,
  280. int nSize,
  281. OGRwkbByteOrder& eByteOrder,
  282. OGRwkbVariant eWkbVariant );
  283. OGRErr importPreambleOfCollectionFromWkb(
  284. const unsigned char * pabyData,
  285. int& nSize,
  286. int& nDataOffset,
  287. OGRwkbByteOrder& eByteOrder,
  288. int nMinSubGeomSize,
  289. int& nGeomCount,
  290. OGRwkbVariant eWkbVariant );
  291. OGRErr PointOnSurfaceInternal( OGRPoint * poPoint ) const;
  292. OGRBoolean IsSFCGALCompatible() const;
  293. void HomogenizeDimensionalityWith( OGRGeometry* poOtherGeom );
  294. //! @endcond
  295. public:
  296. /************************************************************************/
  297. /* Bit flags for OGRGeometry */
  298. /* The OGR_G_NOT_EMPTY_POINT is used *only* for points. */
  299. /* Do not use these outside of the core. */
  300. /* Use Is3D, IsMeasured, set3D, and setMeasured instead */
  301. /************************************************************************/
  302. //! @cond Doxygen_Suppress
  303. static const unsigned int OGR_G_NOT_EMPTY_POINT = 0x1;
  304. static const unsigned int OGR_G_3D = 0x2;
  305. static const unsigned int OGR_G_MEASURED = 0x4;
  306. //! @endcond
  307. OGRGeometry();
  308. OGRGeometry( const OGRGeometry& other );
  309. virtual ~OGRGeometry();
  310. OGRGeometry& operator=( const OGRGeometry& other );
  311. /** Returns if two geometries are equal. */
  312. bool operator==( const OGRGeometry& other ) const { return CPL_TO_BOOL(Equals(&other)); }
  313. /** Returns if two geometries are different. */
  314. bool operator!=( const OGRGeometry& other ) const { return !CPL_TO_BOOL(Equals(&other)); }
  315. // Standard IGeometry.
  316. virtual int getDimension() const = 0;
  317. virtual int getCoordinateDimension() const;
  318. int CoordinateDimension() const;
  319. virtual OGRBoolean IsEmpty() const = 0;
  320. virtual OGRBoolean IsValid() const;
  321. virtual OGRGeometry* MakeValid() const;
  322. virtual OGRBoolean IsSimple() const;
  323. /*! Returns whether the geometry has a Z component. */
  324. OGRBoolean Is3D() const { return flags & OGR_G_3D; }
  325. /*! Returns whether the geometry has a M component. */
  326. OGRBoolean IsMeasured() const { return flags & OGR_G_MEASURED; }
  327. virtual OGRBoolean IsRing() const;
  328. virtual void empty() = 0;
  329. virtual OGRGeometry *clone() const CPL_WARN_UNUSED_RESULT = 0;
  330. virtual void getEnvelope( OGREnvelope * psEnvelope ) const = 0;
  331. virtual void getEnvelope( OGREnvelope3D * psEnvelope ) const = 0;
  332. // IWks Interface.
  333. virtual int WkbSize() const = 0;
  334. OGRErr importFromWkb( const GByte*, int=-1,
  335. OGRwkbVariant=wkbVariantOldOgc );
  336. virtual OGRErr importFromWkb( const unsigned char *,
  337. int,
  338. OGRwkbVariant,
  339. int& nBytesConsumedOut ) = 0;
  340. virtual OGRErr exportToWkb( OGRwkbByteOrder, unsigned char *,
  341. OGRwkbVariant=wkbVariantOldOgc ) const = 0;
  342. virtual OGRErr importFromWkt( const char ** ppszInput ) = 0;
  343. /** Deprecated.
  344. * @deprecated in GDAL 2.3
  345. */
  346. OGRErr importFromWkt( char ** ppszInput ) CPL_WARN_DEPRECATED("Use importFromWkt(const char**) instead")
  347. {
  348. return importFromWkt( const_cast<const char**>(ppszInput) );
  349. }
  350. virtual OGRErr exportToWkt( char ** ppszDstText,
  351. OGRwkbVariant=wkbVariantOldOgc ) const = 0;
  352. // Non-standard.
  353. virtual OGRwkbGeometryType getGeometryType() const = 0;
  354. OGRwkbGeometryType getIsoGeometryType() const;
  355. virtual const char *getGeometryName() const = 0;
  356. virtual void dumpReadable( FILE *, const char * = nullptr
  357. , char** papszOptions = nullptr ) const;
  358. virtual void flattenTo2D() = 0;
  359. virtual char * exportToGML( const char* const * papszOptions = nullptr ) const;
  360. virtual char * exportToKML() const;
  361. virtual char * exportToJson() const;
  362. /** Accept a visitor. */
  363. virtual void accept(IOGRGeometryVisitor* visitor) = 0;
  364. /** Accept a visitor. */
  365. virtual void accept(IOGRConstGeometryVisitor* visitor) const = 0;
  366. static GEOSContextHandle_t createGEOSContext();
  367. static void freeGEOSContext( GEOSContextHandle_t hGEOSCtxt );
  368. virtual GEOSGeom exportToGEOS( GEOSContextHandle_t hGEOSCtxt )
  369. const CPL_WARN_UNUSED_RESULT;
  370. virtual OGRBoolean hasCurveGeometry(int bLookForNonLinear = FALSE) const;
  371. virtual OGRGeometry* getCurveGeometry(
  372. const char* const* papszOptions = nullptr ) const CPL_WARN_UNUSED_RESULT;
  373. virtual OGRGeometry* getLinearGeometry(
  374. double dfMaxAngleStepSizeDegrees = 0,
  375. const char* const* papszOptions = nullptr ) const CPL_WARN_UNUSED_RESULT;
  376. // SFCGAL interfacing methods.
  377. //! @cond Doxygen_Suppress
  378. static sfcgal_geometry_t* OGRexportToSFCGAL( const OGRGeometry *poGeom );
  379. static OGRGeometry* SFCGALexportToOGR( const sfcgal_geometry_t* _geometry );
  380. //! @endcond
  381. virtual void closeRings();
  382. virtual void setCoordinateDimension( int nDimension );
  383. virtual void set3D( OGRBoolean bIs3D );
  384. virtual void setMeasured( OGRBoolean bIsMeasured );
  385. virtual void assignSpatialReference( OGRSpatialReference * poSR );
  386. OGRSpatialReference *getSpatialReference( void ) const { return poSRS; }
  387. virtual OGRErr transform( OGRCoordinateTransformation *poCT ) = 0;
  388. OGRErr transformTo( OGRSpatialReference *poSR );
  389. virtual void segmentize(double dfMaxLength);
  390. // ISpatialRelation
  391. virtual OGRBoolean Intersects( const OGRGeometry * ) const;
  392. virtual OGRBoolean Equals( const OGRGeometry * ) const = 0;
  393. virtual OGRBoolean Disjoint( const OGRGeometry * ) const;
  394. virtual OGRBoolean Touches( const OGRGeometry * ) const;
  395. virtual OGRBoolean Crosses( const OGRGeometry * ) const;
  396. virtual OGRBoolean Within( const OGRGeometry * ) const;
  397. virtual OGRBoolean Contains( const OGRGeometry * ) const;
  398. virtual OGRBoolean Overlaps( const OGRGeometry * ) const;
  399. // virtual OGRBoolean Relate( const OGRGeometry *, const char * ) const;
  400. // virtual OGRGeometry *LocateAlong( double mValue ) const;
  401. // virtual OGRGeometry *LocateBetween( double mStart, double mEnd ) const;
  402. virtual OGRGeometry *Boundary() const CPL_WARN_UNUSED_RESULT;
  403. virtual double Distance( const OGRGeometry * ) const ;
  404. virtual OGRGeometry *ConvexHull() const CPL_WARN_UNUSED_RESULT;
  405. virtual OGRGeometry *Buffer( double dfDist, int nQuadSegs = 30 )
  406. const CPL_WARN_UNUSED_RESULT;
  407. virtual OGRGeometry *Intersection( const OGRGeometry *)
  408. const CPL_WARN_UNUSED_RESULT;
  409. virtual OGRGeometry *Union( const OGRGeometry * )
  410. const CPL_WARN_UNUSED_RESULT;
  411. virtual OGRGeometry *UnionCascaded() const CPL_WARN_UNUSED_RESULT;
  412. virtual OGRGeometry *Difference( const OGRGeometry * )
  413. const CPL_WARN_UNUSED_RESULT;
  414. virtual OGRGeometry *SymDifference( const OGRGeometry * )
  415. const CPL_WARN_UNUSED_RESULT;
  416. virtual OGRErr Centroid( OGRPoint * poPoint ) const;
  417. virtual OGRGeometry *Simplify(double dTolerance)
  418. const CPL_WARN_UNUSED_RESULT;
  419. OGRGeometry *SimplifyPreserveTopology(double dTolerance)
  420. const CPL_WARN_UNUSED_RESULT;
  421. virtual OGRGeometry *DelaunayTriangulation(
  422. double dfTolerance, int bOnlyEdges ) const CPL_WARN_UNUSED_RESULT;
  423. virtual OGRGeometry *Polygonize() const CPL_WARN_UNUSED_RESULT;
  424. virtual double Distance3D( const OGRGeometry *poOtherGeom ) const;
  425. //! @cond Doxygen_Suppress
  426. // backward compatibility to non-standard method names.
  427. OGRBoolean Intersect( OGRGeometry * )
  428. const CPL_WARN_DEPRECATED("Non standard method. "
  429. "Use Intersects() instead");
  430. OGRBoolean Equal( OGRGeometry * )
  431. const CPL_WARN_DEPRECATED("Non standard method. "
  432. "Use Equals() instead");
  433. OGRGeometry *SymmetricDifference( const OGRGeometry * )
  434. const CPL_WARN_DEPRECATED("Non standard method. "
  435. "Use SymDifference() instead");
  436. OGRGeometry *getBoundary()
  437. const CPL_WARN_DEPRECATED("Non standard method. "
  438. "Use Boundary() instead");
  439. //! @endcond
  440. //! @cond Doxygen_Suppress
  441. // Special HACK for DB2 7.2 support
  442. static int bGenerate_DB2_V72_BYTE_ORDER;
  443. //! @endcond
  444. virtual void swapXY();
  445. //! @cond Doxygen_Suppress
  446. static OGRGeometry* CastToIdentity( OGRGeometry* poGeom ) { return poGeom; }
  447. static OGRGeometry* CastToError( OGRGeometry* poGeom );
  448. //! @endcond
  449. /** Convert a OGRGeometry* to a OGRGeometryH.
  450. * @since GDAL 2.3
  451. */
  452. static inline OGRGeometryH ToHandle(OGRGeometry* poGeom)
  453. { return reinterpret_cast<OGRGeometryH>(poGeom); }
  454. /** Convert a OGRGeometryH to a OGRGeometry*.
  455. * @since GDAL 2.3
  456. */
  457. static inline OGRGeometry* FromHandle(OGRGeometryH hGeom)
  458. { return reinterpret_cast<OGRGeometry*>(hGeom); }
  459. /** Down-cast to OGRPoint*.
  460. * Implies prior checking that wkbFlatten(getGeometryType()) == wkbPoint.
  461. * @since GDAL 2.3
  462. */
  463. inline OGRPoint* toPoint()
  464. { return cpl::down_cast<OGRPoint*>(this); }
  465. /** Down-cast to OGRPoint*.
  466. * Implies prior checking that wkbFlatten(getGeometryType()) == wkbPoint.
  467. * @since GDAL 2.3
  468. */
  469. inline const OGRPoint* toPoint() const
  470. { return cpl::down_cast<const OGRPoint*>(this); }
  471. /** Down-cast to OGRCurve*.
  472. * Implies prior checking that OGR_GT_IsSubClass(getGeometryType(), wkbCurve).
  473. * @since GDAL 2.3
  474. */
  475. inline OGRCurve* toCurve()
  476. { return cpl::down_cast<OGRCurve*>(this); }
  477. /** Down-cast to OGRCurve*.
  478. * Implies prior checking that OGR_GT_IsSubClass(getGeometryType(), wkbCurve).
  479. * @since GDAL 2.3
  480. */
  481. inline const OGRCurve* toCurve() const
  482. { return cpl::down_cast<const OGRCurve*>(this); }
  483. /** Down-cast to OGRSimpleCurve*.
  484. * Implies prior checking that getGeometryType() is wkbLineString, wkbCircularString or a derived type.
  485. * @since GDAL 2.3
  486. */
  487. inline OGRSimpleCurve* toSimpleCurve()
  488. { return cpl::down_cast<OGRSimpleCurve*>(this); }
  489. /** Down-cast to OGRSimpleCurve*.
  490. * Implies prior checking that getGeometryType() is wkbLineString, wkbCircularString or a derived type.
  491. * @since GDAL 2.3
  492. */
  493. inline const OGRSimpleCurve* toSimpleCurve() const
  494. { return cpl::down_cast<const OGRSimpleCurve*>(this); }
  495. /** Down-cast to OGRLineString*.
  496. * Implies prior checking that wkbFlatten(getGeometryType()) == wkbLineString.
  497. * @since GDAL 2.3
  498. */
  499. inline OGRLineString* toLineString()
  500. { return cpl::down_cast<OGRLineString*>(this); }
  501. /** Down-cast to OGRLineString*.
  502. * Implies prior checking that wkbFlatten(getGeometryType()) == wkbLineString.
  503. * @since GDAL 2.3
  504. */
  505. inline const OGRLineString* toLineString() const
  506. { return cpl::down_cast<const OGRLineString*>(this); }
  507. /** Down-cast to OGRLinearRing*.
  508. * Implies prior checking that EQUAL(getGeometryName(), "LINEARRING").
  509. * @since GDAL 2.3
  510. */
  511. inline OGRLinearRing* toLinearRing()
  512. { return cpl::down_cast<OGRLinearRing*>(this); }
  513. /** Down-cast to OGRLinearRing*.
  514. * Implies prior checking that EQUAL(getGeometryName(), "LINEARRING").
  515. * @since GDAL 2.3
  516. */
  517. inline const OGRLinearRing* toLinearRing() const
  518. { return cpl::down_cast<const OGRLinearRing*>(this); }
  519. /** Down-cast to OGRCircularString*.
  520. * Implies prior checking that wkbFlatten(getGeometryType()) == wkbCircularString.
  521. * @since GDAL 2.3
  522. */
  523. inline OGRCircularString* toCircularString()
  524. { return cpl::down_cast<OGRCircularString*>(this); }
  525. /** Down-cast to OGRCircularString*.
  526. * Implies prior checking that wkbFlatten(getGeometryType()) == wkbCircularString.
  527. * @since GDAL 2.3
  528. */
  529. inline const OGRCircularString* toCircularString() const
  530. { return cpl::down_cast<const OGRCircularString*>(this); }
  531. /** Down-cast to OGRCompoundCurve*.
  532. * Implies prior checking that wkbFlatten(getGeometryType()) == wkbCompoundCurve.
  533. * @since GDAL 2.3
  534. */
  535. inline OGRCompoundCurve* toCompoundCurve()
  536. { return cpl::down_cast<OGRCompoundCurve*>(this); }
  537. /** Down-cast to OGRCompoundCurve*.
  538. * Implies prior checking that wkbFlatten(getGeometryType()) == wkbCompoundCurve.
  539. * @since GDAL 2.3
  540. */
  541. inline const OGRCompoundCurve* toCompoundCurve() const
  542. { return cpl::down_cast<const OGRCompoundCurve*>(this); }
  543. /** Down-cast to OGRSurface*.
  544. * Implies prior checking that OGR_GT_IsSubClass(getGeometryType(), wkbSurface).
  545. * @since GDAL 2.3
  546. */
  547. inline OGRSurface* toSurface()
  548. { return cpl::down_cast<OGRSurface*>(this); }
  549. /** Down-cast to OGRSurface*.
  550. * Implies prior checking that OGR_GT_IsSubClass(getGeometryType(), wkbSurface).
  551. * @since GDAL 2.3
  552. */
  553. inline const OGRSurface* toSurface() const
  554. { return cpl::down_cast<const OGRSurface*>(this); }
  555. /** Down-cast to OGRPolygon*.
  556. * Implies prior checking that wkbFlatten(getGeometryType()) == wkbPolygon or wkbTriangle.
  557. * @since GDAL 2.3
  558. */
  559. inline OGRPolygon* toPolygon()
  560. { return cpl::down_cast<OGRPolygon*>(this); }
  561. /** Down-cast to OGRPolygon*.
  562. * Implies prior checking that wkbFlatten(getGeometryType()) == wkbPolygon or wkbTriangle.
  563. * @since GDAL 2.3
  564. */
  565. inline const OGRPolygon* toPolygon() const
  566. { return cpl::down_cast<const OGRPolygon*>(this); }
  567. /** Down-cast to OGRTriangle*.
  568. * Implies prior checking that wkbFlatten(getGeometryType()) == wkbTriangle.
  569. * @since GDAL 2.3
  570. */
  571. inline OGRTriangle* toTriangle()
  572. { return cpl::down_cast<OGRTriangle*>(this); }
  573. /** Down-cast to OGRTriangle*.
  574. * Implies prior checking that wkbFlatten(getGeometryType()) == wkbTriangle.
  575. * @since GDAL 2.3
  576. */
  577. inline const OGRTriangle* toTriangle() const
  578. { return cpl::down_cast<const OGRTriangle*>(this); }
  579. /** Down-cast to OGRCurvePolygon*.
  580. * Implies prior checking that wkbFlatten(getGeometryType()) == wkbCurvePolygon or wkbPolygon or wkbTriangle.
  581. * @since GDAL 2.3
  582. */
  583. inline OGRCurvePolygon* toCurvePolygon()
  584. { return cpl::down_cast<OGRCurvePolygon*>(this); }
  585. /** Down-cast to OGRCurvePolygon*.
  586. * Implies prior checking that wkbFlatten(getGeometryType()) == wkbCurvePolygon or wkbPolygon or wkbTriangle.
  587. * @since GDAL 2.3
  588. */
  589. inline const OGRCurvePolygon* toCurvePolygon() const
  590. { return cpl::down_cast<const OGRCurvePolygon*>(this); }
  591. /** Down-cast to OGRGeometryCollection*.
  592. * Implies prior checking that OGR_GT_IsSubClass(getGeometryType(), wkbGeometryCollection).
  593. * @since GDAL 2.3
  594. */
  595. inline OGRGeometryCollection* toGeometryCollection()
  596. { return cpl::down_cast<OGRGeometryCollection*>(this); }
  597. /** Down-cast to OGRGeometryCollection*.
  598. * Implies prior checking that OGR_GT_IsSubClass(getGeometryType(), wkbGeometryCollection).
  599. * @since GDAL 2.3
  600. */
  601. inline const OGRGeometryCollection* toGeometryCollection() const
  602. { return cpl::down_cast<const OGRGeometryCollection*>(this); }
  603. /** Down-cast to OGRMultiPoint*.
  604. * Implies prior checking that wkbFlatten(getGeometryType()) == wkbMultiPoint.
  605. * @since GDAL 2.3
  606. */
  607. inline OGRMultiPoint* toMultiPoint()
  608. { return cpl::down_cast<OGRMultiPoint*>(this); }
  609. /** Down-cast to OGRMultiPoint*.
  610. * Implies prior checking that wkbFlatten(getGeometryType()) == wkbMultiPoint.
  611. * @since GDAL 2.3
  612. */
  613. inline const OGRMultiPoint* toMultiPoint() const
  614. { return cpl::down_cast<const OGRMultiPoint*>(this); }
  615. /** Down-cast to OGRMultiLineString*.
  616. * Implies prior checking that wkbFlatten(getGeometryType()) == wkbMultiLineString.
  617. * @since GDAL 2.3
  618. */
  619. inline OGRMultiLineString* toMultiLineString()
  620. { return cpl::down_cast<OGRMultiLineString*>(this); }
  621. /** Down-cast to OGRMultiLineString*.
  622. * Implies prior checking that wkbFlatten(getGeometryType()) == wkbMultiLineString.
  623. * @since GDAL 2.3
  624. */
  625. inline const OGRMultiLineString* toMultiLineString() const
  626. { return cpl::down_cast<const OGRMultiLineString*>(this); }
  627. /** Down-cast to OGRMultiPolygon*.
  628. * Implies prior checking that wkbFlatten(getGeometryType()) == wkbMultiPolygon.
  629. * @since GDAL 2.3
  630. */
  631. inline OGRMultiPolygon* toMultiPolygon()
  632. { return cpl::down_cast<OGRMultiPolygon*>(this); }
  633. /** Down-cast to OGRMultiPolygon*.
  634. * Implies prior checking that wkbFlatten(getGeometryType()) == wkbMultiPolygon.
  635. * @since GDAL 2.3
  636. */
  637. inline const OGRMultiPolygon* toMultiPolygon() const
  638. { return cpl::down_cast<const OGRMultiPolygon*>(this); }
  639. /** Down-cast to OGRMultiCurve*.
  640. * Implies prior checking that wkbFlatten(getGeometryType()) == wkbMultiCurve and derived types.
  641. * @since GDAL 2.3
  642. */
  643. inline OGRMultiCurve* toMultiCurve()
  644. { return cpl::down_cast<OGRMultiCurve*>(this); }
  645. /** Down-cast to OGRMultiCurve*.
  646. * Implies prior checking that wkbFlatten(getGeometryType()) == wkbMultiCurve and derived types.
  647. * @since GDAL 2.3
  648. */
  649. inline const OGRMultiCurve* toMultiCurve() const
  650. { return cpl::down_cast<const OGRMultiCurve*>(this); }
  651. /** Down-cast to OGRMultiSurface*.
  652. * Implies prior checking that wkbFlatten(getGeometryType()) == wkbMultiSurface and derived types.
  653. * @since GDAL 2.3
  654. */
  655. inline OGRMultiSurface* toMultiSurface()
  656. { return cpl::down_cast<OGRMultiSurface*>(this); }
  657. /** Down-cast to OGRMultiSurface*.
  658. * Implies prior checking that wkbFlatten(getGeometryType()) == wkbMultiSurface and derived types.
  659. * @since GDAL 2.3
  660. */
  661. inline const OGRMultiSurface* toMultiSurface() const
  662. { return cpl::down_cast<const OGRMultiSurface*>(this); }
  663. /** Down-cast to OGRPolyhedralSurface*.
  664. * Implies prior checking that wkbFlatten(getGeometryType()) == wkbPolyhedralSurface or wkbTIN.
  665. * @since GDAL 2.3
  666. */
  667. inline OGRPolyhedralSurface* toPolyhedralSurface()
  668. { return cpl::down_cast<OGRPolyhedralSurface*>(this); }
  669. /** Down-cast to OGRPolyhedralSurface*.
  670. * Implies prior checking that wkbFlatten(getGeometryType()) == wkbPolyhedralSurface or wkbTIN.
  671. * @since GDAL 2.3
  672. */
  673. inline const OGRPolyhedralSurface* toPolyhedralSurface() const
  674. { return cpl::down_cast<const OGRPolyhedralSurface*>(this); }
  675. /** Down-cast to OGRTriangulatedSurface*.
  676. * Implies prior checking that wkbFlatten(getGeometryType()) == wkbTIN.
  677. * @since GDAL 2.3
  678. */
  679. inline OGRTriangulatedSurface* toTriangulatedSurface()
  680. { return cpl::down_cast<OGRTriangulatedSurface*>(this); }
  681. /** Down-cast to OGRTriangulatedSurface*.
  682. * Implies prior checking that wkbFlatten(getGeometryType()) == wkbTIN.
  683. * @since GDAL 2.3
  684. */
  685. inline const OGRTriangulatedSurface* toTriangulatedSurface() const
  686. { return cpl::down_cast<const OGRTriangulatedSurface*>(this); }
  687. };
  688. //! @cond Doxygen_Suppress
  689. struct CPL_DLL OGRGeometryUniquePtrDeleter
  690. {
  691. void operator()(OGRGeometry*) const;
  692. };
  693. //! @endcond
  694. /** Unique pointer type for OGRGeometry.
  695. * @since GDAL 2.3
  696. */
  697. typedef std::unique_ptr<OGRGeometry, OGRGeometryUniquePtrDeleter> OGRGeometryUniquePtr;
  698. /************************************************************************/
  699. /* OGRPoint */
  700. /************************************************************************/
  701. /**
  702. * Point class.
  703. *
  704. * Implements SFCOM IPoint methods.
  705. */
  706. class CPL_DLL OGRPoint : public OGRGeometry
  707. {
  708. double x;
  709. double y;
  710. double z;
  711. double m;
  712. public:
  713. OGRPoint();
  714. OGRPoint( double x, double y );
  715. OGRPoint( double x, double y, double z );
  716. OGRPoint( double x, double y, double z, double m );
  717. OGRPoint( const OGRPoint& other );
  718. ~OGRPoint() override;
  719. OGRPoint& operator=( const OGRPoint& other );
  720. // IWks Interface
  721. int WkbSize() const override;
  722. OGRErr importFromWkb( const unsigned char *,
  723. int,
  724. OGRwkbVariant,
  725. int& nBytesConsumedOut ) override;
  726. OGRErr exportToWkb( OGRwkbByteOrder, unsigned char *,
  727. OGRwkbVariant=wkbVariantOldOgc )
  728. const override;
  729. using OGRGeometry::importFromWkt; /** deprecated */
  730. OGRErr importFromWkt( const char ** ) override;
  731. OGRErr exportToWkt( char ** ppszDstText,
  732. OGRwkbVariant=wkbVariantOldOgc )
  733. const override;
  734. // IGeometry
  735. virtual int getDimension() const override;
  736. virtual OGRGeometry *clone() const override;
  737. virtual void empty() override;
  738. virtual void getEnvelope( OGREnvelope * psEnvelope ) const override;
  739. virtual void getEnvelope( OGREnvelope3D * psEnvelope ) const override;
  740. virtual OGRBoolean IsEmpty() const override
  741. { return !(flags & OGR_G_NOT_EMPTY_POINT); }
  742. // IPoint
  743. /** Return x */
  744. double getX() const { return x; }
  745. /** Return y */
  746. double getY() const { return y; }
  747. /** Return z */
  748. double getZ() const { return z; }
  749. /** Return m */
  750. double getM() const { return m; }
  751. // Non standard
  752. virtual void setCoordinateDimension( int nDimension ) override;
  753. /** Set x
  754. * @param xIn x
  755. */
  756. void setX( double xIn ) { x = xIn; flags |= OGR_G_NOT_EMPTY_POINT; }
  757. /** Set y
  758. * @param yIn y
  759. */
  760. void setY( double yIn ) { y = yIn; flags |= OGR_G_NOT_EMPTY_POINT; }
  761. /** Set z
  762. * @param zIn z
  763. */
  764. void setZ( double zIn )
  765. { z = zIn; flags |= (OGR_G_NOT_EMPTY_POINT | OGR_G_3D); }
  766. /** Set m
  767. * @param mIn m
  768. */
  769. void setM( double mIn )
  770. { m = mIn; flags |= (OGR_G_NOT_EMPTY_POINT | OGR_G_MEASURED); }
  771. // ISpatialRelation
  772. virtual OGRBoolean Equals( const OGRGeometry * ) const override;
  773. virtual OGRBoolean Intersects( const OGRGeometry * ) const override;
  774. virtual OGRBoolean Within( const OGRGeometry * ) const override;
  775. // Non standard from OGRGeometry
  776. virtual const char *getGeometryName() const override;
  777. virtual OGRwkbGeometryType getGeometryType() const override;
  778. virtual OGRErr transform( OGRCoordinateTransformation *poCT ) override;
  779. virtual void flattenTo2D() override;
  780. virtual void accept(IOGRGeometryVisitor* visitor) override { visitor->visit(this); }
  781. virtual void accept(IOGRConstGeometryVisitor* visitor) const override { visitor->visit(this); }
  782. virtual void swapXY() override;
  783. };
  784. /************************************************************************/
  785. /* OGRPointIterator */
  786. /************************************************************************/
  787. /**
  788. * Interface for a point iterator.
  789. *
  790. * @since GDAL 2.0
  791. */
  792. class CPL_DLL OGRPointIterator
  793. {
  794. public:
  795. virtual ~OGRPointIterator();
  796. virtual OGRBoolean getNextPoint( OGRPoint* p ) = 0;
  797. static void destroy( OGRPointIterator* );
  798. };
  799. /************************************************************************/
  800. /* OGRCurve */
  801. /************************************************************************/
  802. /**
  803. * Abstract curve base class for OGRLineString, OGRCircularString and
  804. * OGRCompoundCurve
  805. */
  806. class CPL_DLL OGRCurve : public OGRGeometry
  807. {
  808. protected:
  809. //! @cond Doxygen_Suppress
  810. OGRCurve();
  811. OGRCurve( const OGRCurve& other );
  812. virtual OGRCurveCasterToLineString GetCasterToLineString() const = 0;
  813. virtual OGRCurveCasterToLinearRing GetCasterToLinearRing() const = 0;
  814. friend class OGRCurvePolygon;
  815. friend class OGRCompoundCurve;
  816. //! @endcond
  817. virtual int ContainsPoint( const OGRPoint* p ) const;
  818. virtual int IntersectsPoint( const OGRPoint* p ) const;
  819. virtual double get_AreaOfCurveSegments() const = 0;
  820. private:
  821. class CPL_DLL ConstIterator
  822. {
  823. struct Private;
  824. std::unique_ptr<Private> m_poPrivate;
  825. public:
  826. ConstIterator(const OGRCurve* poSelf, bool bStart);
  827. ConstIterator(ConstIterator&& oOther) noexcept; // declared but not defined. Needed for gcc 5.4 at least
  828. ~ConstIterator();
  829. const OGRPoint& operator*() const;
  830. ConstIterator& operator++();
  831. bool operator!=(const ConstIterator& it) const;
  832. };
  833. friend inline ConstIterator begin(const OGRCurve*);
  834. friend inline ConstIterator end(const OGRCurve*);
  835. public:
  836. ~OGRCurve() override;
  837. //! @cond Doxygen_Suppress
  838. OGRCurve& operator=( const OGRCurve& other );
  839. //! @endcond
  840. /** Type of child elements. */
  841. typedef OGRPoint ChildType;
  842. /** Return begin of a point iterator.
  843. *
  844. * Using this iterator for standard range-based loops is safe, but
  845. * due to implementation limitations, you shouldn't try to access
  846. * (dereference) more than one iterator step at a time, since you will get
  847. * a reference to the same OGRPoint& object.
  848. * @since GDAL 2.3
  849. */
  850. ConstIterator begin() const;
  851. /** Return end of a point iterator. */
  852. ConstIterator end() const;
  853. // ICurve methods
  854. virtual double get_Length() const = 0;
  855. virtual void StartPoint( OGRPoint * ) const = 0;
  856. virtual void EndPoint( OGRPoint * ) const = 0;
  857. virtual int get_IsClosed() const;
  858. virtual void Value( double, OGRPoint * ) const = 0;
  859. virtual OGRLineString* CurveToLine( double dfMaxAngleStepSizeDegrees = 0,
  860. const char* const* papszOptions = nullptr)
  861. const = 0;
  862. virtual int getDimension() const override;
  863. // non standard
  864. virtual int getNumPoints() const = 0;
  865. virtual OGRPointIterator* getPointIterator() const = 0;
  866. virtual OGRBoolean IsConvex() const;
  867. virtual double get_Area() const = 0;
  868. /** Down-cast to OGRSimpleCurve*.
  869. * Implies prior checking that wkbFlatten(getGeometryType()) == wkbLineString or wkbCircularString. */
  870. inline OGRSimpleCurve* toSimpleCurve()
  871. { return cpl::down_cast<OGRSimpleCurve*>(this); }
  872. /** Down-cast to OGRSimpleCurve*.
  873. * Implies prior checking that wkbFlatten(getGeometryType()) == wkbLineString or wkbCircularString. */
  874. inline const OGRSimpleCurve* toSimpleCurve() const
  875. { return cpl::down_cast<const OGRSimpleCurve*>(this); }
  876. static OGRCompoundCurve* CastToCompoundCurve( OGRCurve* puCurve );
  877. static OGRLineString* CastToLineString( OGRCurve* poCurve );
  878. static OGRLinearRing* CastToLinearRing( OGRCurve* poCurve );
  879. };
  880. //! @cond Doxygen_Suppress
  881. /** @see OGRCurve::begin() const */
  882. inline OGRCurve::ConstIterator begin(const OGRCurve* poCurve) { return poCurve->begin(); }
  883. /** @see OGRCurve::end() const */
  884. inline OGRCurve::ConstIterator end(const OGRCurve* poCurve) { return poCurve->end(); }
  885. //! @endcond
  886. /************************************************************************/
  887. /* OGRSimpleCurve */
  888. /************************************************************************/
  889. /**
  890. * Abstract curve base class for OGRLineString and OGRCircularString
  891. *
  892. * Note: this class does not exist in SQL/MM standard and exists for
  893. * implementation convenience.
  894. *
  895. * @since GDAL 2.0
  896. */
  897. class CPL_DLL OGRSimpleCurve: public OGRCurve
  898. {
  899. protected:
  900. //! @cond Doxygen_Suppress
  901. friend class OGRGeometry;
  902. int nPointCount;
  903. OGRRawPoint *paoPoints;
  904. double *padfZ;
  905. double *padfM;
  906. void Make3D();
  907. void Make2D();
  908. void RemoveM();
  909. void AddM();
  910. OGRErr importFromWKTListOnly( const char ** ppszInput, int bHasZ, int bHasM,
  911. OGRRawPoint*& paoPointsIn,
  912. int& nMaxPoints,
  913. double*& padfZIn );
  914. //! @endcond
  915. virtual double get_LinearArea() const;
  916. OGRSimpleCurve();
  917. OGRSimpleCurve( const OGRSimpleCurve& other );
  918. private:
  919. class CPL_DLL Iterator
  920. {
  921. struct Private;
  922. std::unique_ptr<Private> m_poPrivate;
  923. void update();
  924. public:
  925. Iterator(OGRSimpleCurve* poSelf, int nPos);
  926. Iterator(Iterator&& oOther) noexcept; // declared but not defined. Needed for gcc 5.4 at least
  927. ~Iterator();
  928. OGRPoint& operator*();
  929. Iterator& operator++();
  930. bool operator!=(const Iterator& it) const;
  931. };
  932. friend inline Iterator begin(OGRSimpleCurve*);
  933. friend inline Iterator end(OGRSimpleCurve*);
  934. class CPL_DLL ConstIterator
  935. {
  936. struct Private;
  937. std::unique_ptr<Private> m_poPrivate;
  938. public:
  939. ConstIterator(const OGRSimpleCurve* poSelf, int nPos);
  940. ConstIterator(ConstIterator&& oOther) noexcept; // declared but not defined. Needed for gcc 5.4 at least
  941. ~ConstIterator();
  942. const OGRPoint& operator*() const;
  943. ConstIterator& operator++();
  944. bool operator!=(const ConstIterator& it) const;
  945. };
  946. friend inline ConstIterator begin(const OGRSimpleCurve*);
  947. friend inline ConstIterator end(const OGRSimpleCurve*);
  948. public:
  949. ~OGRSimpleCurve() override;
  950. OGRSimpleCurve& operator=( const OGRSimpleCurve& other );
  951. /** Type of child elements. */
  952. typedef OGRPoint ChildType;
  953. /** Return begin of point iterator.
  954. *
  955. * Using this iterator for standard range-based loops is safe, but
  956. * due to implementation limitations, you shouldn't try to access
  957. * (dereference) more than one iterator step at a time, since you will get
  958. * a reference to the same OGRPoint& object.
  959. * @since GDAL 2.3
  960. */
  961. Iterator begin();
  962. /** Return end of point iterator. */
  963. Iterator end();
  964. /** Return begin of point iterator.
  965. *
  966. * Using this iterator for standard range-based loops is safe, but
  967. * due to implementation limitations, you shouldn't try to access
  968. * (dereference) more than one iterator step at a time, since you will get
  969. * a reference to the same OGRPoint& object.
  970. * @since GDAL 2.3
  971. */
  972. ConstIterator begin() const;
  973. /** Return end of point iterator. */
  974. ConstIterator end() const;
  975. // IWks Interface.
  976. virtual int WkbSize() const override;
  977. virtual OGRErr importFromWkb( const unsigned char *,
  978. int,
  979. OGRwkbVariant,
  980. int& nBytesConsumedOut ) override;
  981. virtual OGRErr exportToWkb( OGRwkbByteOrder, unsigned char *,
  982. OGRwkbVariant=wkbVariantOldOgc )
  983. const override;
  984. using OGRGeometry::importFromWkt; /** deprecated */
  985. OGRErr importFromWkt( const char ** ) override;
  986. virtual OGRErr exportToWkt( char ** ppszDstText,
  987. OGRwkbVariant=wkbVariantOldOgc )
  988. const override;
  989. // IGeometry interface.
  990. virtual OGRGeometry *clone() const override;
  991. virtual void empty() override;
  992. virtual void getEnvelope( OGREnvelope * psEnvelope ) const override;
  993. virtual void getEnvelope( OGREnvelope3D * psEnvelope ) const override;
  994. virtual OGRBoolean IsEmpty() const override;
  995. // ICurve methods.
  996. virtual double get_Length() const override;
  997. virtual void StartPoint( OGRPoint * ) const override;
  998. virtual void EndPoint( OGRPoint * ) const override;
  999. virtual void Value( double, OGRPoint * ) const override;
  1000. virtual double Project( const OGRPoint * ) const;
  1001. virtual OGRLineString* getSubLine( double, double, int ) const;
  1002. // ILineString methods.
  1003. virtual int getNumPoints() const override { return nPointCount; }
  1004. void getPoint( int, OGRPoint * ) const;
  1005. double getX( int i ) const { return paoPoints[i].x; }
  1006. double getY( int i ) const { return paoPoints[i].y; }
  1007. double getZ( int i ) const;
  1008. double getM( int i ) const;
  1009. // ISpatialRelation
  1010. virtual OGRBoolean Equals( const OGRGeometry * ) const override;
  1011. // non standard.
  1012. virtual void setCoordinateDimension( int nDimension ) override;
  1013. virtual void set3D( OGRBoolean bIs3D ) override;
  1014. virtual void setMeasured( OGRBoolean bIsMeasured ) override;
  1015. void setNumPoints( int nNewPointCount,
  1016. int bZeroizeNewContent = TRUE );
  1017. void setPoint( int, OGRPoint * );
  1018. void setPoint( int, double, double );
  1019. void setZ( int, double );
  1020. void setM( int, double );
  1021. void setPoint( int, double, double, double );
  1022. void setPointM( int, double, double, double );
  1023. void setPoint( int, double, double, double, double );
  1024. void setPoints( int, const OGRRawPoint *, const double * = nullptr );
  1025. void setPointsM( int, const OGRRawPoint *, const double * );
  1026. void setPoints( int, const OGRRawPoint *, const double *, const double * );
  1027. void setPoints( int, const double * padfX, const double * padfY,
  1028. const double *padfZIn = nullptr );
  1029. void setPointsM( int, const double * padfX, const double * padfY,
  1030. const double *padfMIn = nullptr );
  1031. void setPoints( int, const double * padfX, const double * padfY,
  1032. const double *padfZIn, const double *padfMIn );
  1033. void addPoint( const OGRPoint * );
  1034. void addPoint( double, double );
  1035. void addPoint( double, double, double );
  1036. void addPointM( double, double, double );
  1037. void addPoint( double, double, double, double );
  1038. void getPoints( OGRRawPoint *, double * = nullptr ) const;
  1039. void getPoints( void* pabyX, int nXStride,
  1040. void* pabyY, int nYStride,
  1041. void* pabyZ = nullptr, int nZStride = 0 ) const;
  1042. void getPoints( void* pabyX, int nXStride,
  1043. void* pabyY, int nYStride,
  1044. void* pabyZ, int nZStride,
  1045. void* pabyM, int nMStride ) const;
  1046. void addSubLineString( const OGRLineString *,
  1047. int nStartVertex = 0, int nEndVertex = -1 );
  1048. void reversePoints( void );
  1049. virtual OGRPointIterator* getPointIterator() const override;
  1050. // non-standard from OGRGeometry
  1051. virtual OGRErr transform( OGRCoordinateTransformation *poCT ) override;
  1052. virtual void flattenTo2D() override;
  1053. virtual void segmentize(double dfMaxLength) override;
  1054. virtual void swapXY() override;
  1055. };
  1056. //! @cond Doxygen_Suppress
  1057. /** @see OGRSimpleCurve::begin() */
  1058. inline OGRSimpleCurve::Iterator begin(OGRSimpleCurve* poCurve) { return poCurve->begin(); }
  1059. /** @see OGRSimpleCurve::end() */
  1060. inline OGRSimpleCurve::Iterator end(OGRSimpleCurve* poCurve) { return poCurve->end(); }
  1061. /** @see OGRSimpleCurve::begin() const */
  1062. inline OGRSimpleCurve::ConstIterator begin(const OGRSimpleCurve* poCurve) { return poCurve->begin(); }
  1063. /** @see OGRSimpleCurve::end() const */
  1064. inline OGRSimpleCurve::ConstIterator end(const OGRSimpleCurve* poCurve) { return poCurve->end(); }
  1065. //! @endcond
  1066. /************************************************************************/
  1067. /* OGRLineString */
  1068. /************************************************************************/
  1069. /**
  1070. * Concrete representation of a multi-vertex line.
  1071. *
  1072. * Note: for implementation convenience, we make it inherit from OGRSimpleCurve
  1073. * whereas SFSQL and SQL/MM only make it inherits from OGRCurve.
  1074. */
  1075. class CPL_DLL OGRLineString : public OGRSimpleCurve
  1076. {
  1077. // cppcheck-suppress unusedPrivateFunction
  1078. static OGRLinearRing* CasterToLinearRing(OGRCurve* poCurve);
  1079. protected:
  1080. //! @cond Doxygen_Suppress
  1081. static OGRLineString* TransferMembersAndDestroy(
  1082. OGRLineString* poSrc,
  1083. OGRLineString* poDst);
  1084. virtual OGRCurveCasterToLineString GetCasterToLineString()
  1085. const override;
  1086. virtual OGRCurveCasterToLinearRing GetCasterToLinearRing()
  1087. const override;
  1088. virtual double get_AreaOfCurveSegments() const override;
  1089. //! @endcond
  1090. static OGRLinearRing* CastToLinearRing( OGRLineString* poLS );
  1091. public:
  1092. OGRLineString();
  1093. OGRLineString( const OGRLineString& other );
  1094. ~OGRLineString() override;
  1095. OGRLineString& operator=(const OGRLineString& other);
  1096. virtual OGRLineString* CurveToLine( double dfMaxAngleStepSizeDegrees = 0,
  1097. const char* const* papszOptions = nullptr )
  1098. const override;
  1099. virtual OGRGeometry* getCurveGeometry(
  1100. const char* const* papszOptions = nullptr ) const override;
  1101. virtual double get_Area() const override;
  1102. // Non-standard from OGRGeometry.
  1103. virtual OGRwkbGeometryType getGeometryType() const override;
  1104. virtual const char *getGeometryName() const override;
  1105. /** Return pointer of this in upper class */
  1106. inline OGRSimpleCurve* toUpperClass() { return this; }
  1107. /** Return pointer of this in upper class */
  1108. inline const OGRSimpleCurve* toUpperClass() const { return this; }
  1109. virtual void accept(IOGRGeometryVisitor* visitor) override { visitor->visit(this); }
  1110. virtual void accept(IOGRConstGeometryVisitor* visitor) const override { visitor->visit(this); }
  1111. };
  1112. /************************************************************************/
  1113. /* OGRLinearRing */
  1114. /************************************************************************/
  1115. /**
  1116. * Concrete representation of a closed ring.
  1117. *
  1118. * This class is functionally equivalent to an OGRLineString, but has a
  1119. * separate identity to maintain alignment with the OpenGIS simple feature
  1120. * data model. It exists to serve as a component of an OGRPolygon.
  1121. *
  1122. * The OGRLinearRing has no corresponding free standing well known binary
  1123. * representation, so importFromWkb() and exportToWkb() will not actually
  1124. * work. There is a non-standard GDAL WKT representation though.
  1125. *
  1126. * Because OGRLinearRing is not a "proper" free standing simple features
  1127. * object, it cannot be directly used on a feature via SetGeometry(), and
  1128. * cannot generally be used with GEOS for operations like Intersects().
  1129. * Instead the polygon should be used, or the OGRLinearRing should be
  1130. * converted to an OGRLineString for such operations.
  1131. *
  1132. * Note: this class exists in SFSQL 1.2, but not in ISO SQL/MM Part 3.
  1133. */
  1134. class CPL_DLL OGRLinearRing : public OGRLineString
  1135. {
  1136. static OGRLineString* CasterToLineString( OGRCurve* poCurve );
  1137. protected:
  1138. //! @cond Doxygen_Suppress
  1139. friend class OGRPolygon;
  1140. friend class OGRTriangle;
  1141. // These are not IWks compatible ... just a convenience for OGRPolygon.
  1142. virtual int _WkbSize( int _flags ) const;
  1143. virtual OGRErr _importFromWkb( OGRwkbByteOrder, int _flags,
  1144. const unsigned char *, int,
  1145. int& nBytesConsumedOut );
  1146. virtual OGRErr _exportToWkb( OGRwkbByteOrder, int _flags,
  1147. unsigned char * ) const;
  1148. virtual OGRCurveCasterToLineString GetCasterToLineString()
  1149. const override;
  1150. virtual OGRCurveCasterToLinearRing GetCasterToLinearRing()
  1151. const override;
  1152. //! @endcond
  1153. static OGRLineString* CastToLineString( OGRLinearRing* poLR );
  1154. public:
  1155. OGRLinearRing();
  1156. OGRLinearRing( const OGRLinearRing& other );
  1157. explicit OGRLinearRing( OGRLinearRing * );
  1158. ~OGRLinearRing() override;
  1159. OGRLinearRing& operator=( const OGRLinearRing& other );
  1160. // Non standard.
  1161. virtual const char *getGeometryName() const override;
  1162. virtual OGRGeometry *clone() const override;
  1163. virtual int isClockwise() const;
  1164. virtual void reverseWindingOrder();
  1165. virtual void closeRings() override;
  1166. OGRBoolean isPointInRing( const OGRPoint* pt,
  1167. int bTestEnvelope = TRUE ) const;
  1168. OGRBoolean isPointOnRingBoundary( const OGRPoint* pt,
  1169. int bTestEnvelope = TRUE ) const;
  1170. virtual OGRErr transform( OGRCoordinateTransformation *poCT ) override;
  1171. /** Return pointer of this in upper class */
  1172. inline OGRLineString* toUpperClass() { return this; }
  1173. /** Return pointer of this in upper class */
  1174. inline const OGRLineString* toUpperClass() const { return this; }
  1175. virtual void accept(IOGRGeometryVisitor* visitor) override { visitor->visit(this); }
  1176. virtual void accept(IOGRConstGeometryVisitor* visitor) const override { visitor->visit(this); }
  1177. // IWks Interface - Note this isn't really a first class object
  1178. // for the purposes of WKB form. These methods always fail since this
  1179. // object can't be serialized on its own.
  1180. virtual int WkbSize() const override;
  1181. virtual OGRErr importFromWkb( const unsigned char *,
  1182. int,
  1183. OGRwkbVariant,
  1184. int& nBytesConsumedOut ) override;
  1185. virtual OGRErr exportToWkb( OGRwkbByteOrder, unsigned char *,
  1186. OGRwkbVariant=wkbVariantOldOgc )
  1187. const override;
  1188. };
  1189. /************************************************************************/
  1190. /* OGRCircularString */
  1191. /************************************************************************/
  1192. /**
  1193. * Concrete representation of a circular string, that is to say a curve made
  1194. * of one or several arc circles.
  1195. *
  1196. * Note: for implementation convenience, we make it inherit from OGRSimpleCurve
  1197. * whereas SQL/MM only makes it inherits from OGRCurve.
  1198. *
  1199. * Compatibility: ISO SQL/MM Part 3.
  1200. *
  1201. * @since GDAL 2.0
  1202. */
  1203. class CPL_DLL OGRCircularString : public OGRSimpleCurve
  1204. {
  1205. private:
  1206. void ExtendEnvelopeWithCircular( OGREnvelope * psEnvelope ) const;
  1207. OGRBoolean IsValidFast() const;
  1208. int IsFullCircle( double& cx, double& cy, double& square_R ) const;
  1209. protected:
  1210. //! @cond Doxygen_Suppress
  1211. virtual OGRCurveCasterToLineString GetCasterToLineString()
  1212. const override;
  1213. virtual OGRCurveCasterToLinearRing GetCasterToLinearRing()
  1214. const override;
  1215. virtual int IntersectsPoint( const OGRPoint* p ) const override;
  1216. virtual int ContainsPoint( const OGRPoint* p ) const override;
  1217. virtual double get_AreaOfCurveSegments() const override;
  1218. //! @endcond
  1219. public:
  1220. OGRCircularString();
  1221. OGRCircularString( const OGRCircularString& other );
  1222. ~OGRCircularString() override;
  1223. OGRCircularString& operator=(const OGRCircularString& other);
  1224. // IWks Interface.
  1225. virtual OGRErr importFromWkb( const unsigned char *,
  1226. int,
  1227. OGRwkbVariant,
  1228. int& nBytesConsumedOut ) override;
  1229. virtual OGRErr exportToWkb( OGRwkbByteOrder, unsigned char *,
  1230. OGRwkbVariant=wkbVariantOldOgc )
  1231. const override;
  1232. using OGRGeometry::importFromWkt; /** deprecated */
  1233. OGRErr importFromWkt( const char ** ) override;
  1234. virtual OGRErr exportToWkt( char ** ppszDstText,
  1235. OGRwkbVariant=wkbVariantOldOgc )
  1236. const override;
  1237. // IGeometry interface.
  1238. virtual OGRBoolean IsValid() const override;
  1239. virtual void getEnvelope( OGREnvelope * psEnvelope ) const override;
  1240. virtual void getEnvelope( OGREnvelope3D * psEnvelope ) const override;
  1241. // ICurve methods.
  1242. virtual double get_Length() const override;
  1243. virtual OGRLineString* CurveToLine( double dfMaxAngleStepSizeDegrees = 0,
  1244. const char* const* papszOptions = nullptr )
  1245. const override;
  1246. virtual void Value( double, OGRPoint * ) const override;
  1247. virtual double get_Area() const override;
  1248. // Non-standard from OGRGeometry.
  1249. virtual OGRwkbGeometryType getGeometryType() const override;
  1250. virtual const char *getGeometryName() const override;
  1251. virtual void segmentize( double dfMaxLength ) override;
  1252. virtual OGRBoolean hasCurveGeometry( int bLookForNonLinear = FALSE )
  1253. const override;
  1254. virtual OGRGeometry* getLinearGeometry(
  1255. double dfMaxAngleStepSizeDegrees = 0,
  1256. const char* const* papszOptions = nullptr) const override;
  1257. /** Return pointer of this in upper class */
  1258. inline OGRSimpleCurve* toUpperClass() { return this; }
  1259. /** Return pointer of this in upper class */
  1260. inline const OGRSimpleCurve* toUpperClass() const { return this; }
  1261. virtual void accept(IOGRGeometryVisitor* visitor) override { visitor->visit(this); }
  1262. virtual void accept(IOGRConstGeometryVisitor* visitor) const override { visitor->visit(this); }
  1263. };
  1264. /************************************************************************/
  1265. /* OGRCurveCollection */
  1266. /************************************************************************/
  1267. /**
  1268. * Utility class to store a collection of curves. Used as a member of
  1269. * OGRCompoundCurve and OGRCurvePolygon.
  1270. *
  1271. * This class is only exported because of linking issues. It should never
  1272. * be directly used.
  1273. *
  1274. * @since GDAL 2.0
  1275. */
  1276. //! @cond Doxygen_Suppress
  1277. class CPL_DLL OGRCurveCollection
  1278. {
  1279. protected:
  1280. friend class OGRCompoundCurve;
  1281. friend class OGRCurvePolygon;
  1282. friend class OGRPolygon;
  1283. friend class OGRTriangle;
  1284. int nCurveCount = 0;
  1285. OGRCurve **papoCurves = nullptr;
  1286. public:
  1287. OGRCurveCollection();
  1288. OGRCurveCollection(const OGRCurveCollection& other);
  1289. ~OGRCurveCollection();
  1290. OGRCurveCollection& operator=(const OGRCurveCollection& other);
  1291. /** Type of child elements. */
  1292. typedef OGRCurve ChildType;
  1293. /** Return begin of curve iterator.
  1294. * @since GDAL 2.3
  1295. */
  1296. OGRCurve** begin() { return papoCurves; }
  1297. /** Return end of curve iterator. */
  1298. OGRCurve** end() { return papoCurves + nCurveCount; }
  1299. /** Return begin of curve iterator.
  1300. * @since GDAL 2.3
  1301. */
  1302. const OGRCurve* const* begin() const { return papoCurves; }
  1303. /** Return end of curve iterator. */
  1304. const OGRCurve* const* end() const { return papoCurves + nCurveCount; }
  1305. void empty(OGRGeometry* poGeom);
  1306. OGRBoolean IsEmpty() const;
  1307. void getEnvelope( OGREnvelope * psEnvelope ) const;
  1308. void getEnvelope( OGREnvelope3D * psEnvelope ) const;
  1309. OGRErr addCurveDirectly( OGRGeometry* poGeom, OGRCurve* poCurve,
  1310. int bNeedRealloc );
  1311. int WkbSize() const;
  1312. OGRErr importPreambleFromWkb( OGRGeometry* poGeom,
  1313. const unsigned char * pabyData,
  1314. int& nSize,
  1315. int& nDataOffset,
  1316. OGRwkbByteOrder& eByteOrder,
  1317. int nMinSubGeomSize,
  1318. OGRwkbVariant eWkbVariant );
  1319. OGRErr importBodyFromWkb(
  1320. OGRGeometry* poGeom,
  1321. const unsigned char * pabyData,
  1322. int nSize,
  1323. int bAcceptCompoundCurve,
  1324. OGRErr (*pfnAddCurveDirectlyFromWkb)( OGRGeometry* poGeom,
  1325. OGRCurve* poCurve ),
  1326. OGRwkbVariant eWkbVariant,
  1327. int& nBytesConsumedOut );
  1328. OGRErr exportToWkt( const OGRGeometry* poGeom,
  1329. char ** ppszDstText ) const;
  1330. OGRErr exportToWkb( const OGRGeometry* poGeom, OGRwkbByteOrder,
  1331. unsigned char *,
  1332. OGRwkbVariant eWkbVariant ) const;
  1333. OGRBoolean Equals(const OGRCurveCollection *poOCC) const;
  1334. void setCoordinateDimension( OGRGeometry* poGeom,
  1335. int nNewDimension );
  1336. void set3D( OGRGeometry* poGeom, OGRBoolean bIs3D );
  1337. void setMeasured( OGRGeometry* poGeom, OGRBoolean bIsMeasured );
  1338. void assignSpatialReference( OGRGeometry* poGeom, OGRSpatialReference * poSR );
  1339. int getNumCurves() const;
  1340. OGRCurve *getCurve( int );
  1341. const OGRCurve *getCurve( int ) const;
  1342. OGRCurve *stealCurve( int );
  1343. OGRErr removeCurve( int iIndex, bool bDelete = true );
  1344. OGRErr transform( OGRGeometry* poGeom,
  1345. OGRCoordinateTransformation *poCT );
  1346. void flattenTo2D( OGRGeometry* poGeom );
  1347. void segmentize( double dfMaxLength );
  1348. void swapXY();
  1349. OGRBoolean hasCurveGeometry(int bLookForNonLinear) const;
  1350. };
  1351. //! @endcond
  1352. /************************************************************************/
  1353. /* OGRCompoundCurve */
  1354. /************************************************************************/
  1355. /**
  1356. * Concrete representation of a compound curve, made of curves: OGRLineString
  1357. * and OGRCircularString. Each curve is connected by its first point to
  1358. * the last point of the previous curve.
  1359. *
  1360. * Compatibility: ISO SQL/MM Part 3.
  1361. *
  1362. * @since GDAL 2.0
  1363. */
  1364. class CPL_DLL OGRCompoundCurve : public OGRCurve
  1365. {
  1366. private:
  1367. OGRCurveCollection oCC{};
  1368. OGRErr addCurveDirectlyInternal( OGRCurve* poCurve,
  1369. double dfToleranceEps,
  1370. int bNeedRealloc );
  1371. static OGRErr addCurveDirectlyFromWkt( OGRGeometry* poSelf,
  1372. OGRCurve* poCurve );
  1373. static OGRErr addCurveDirectlyFromWkb( OGRGeometry* poSelf,
  1374. OGRCurve* poCurve );
  1375. OGRLineString* CurveToLineInternal( double dfMaxAngleStepSizeDegrees,
  1376. const char* const* papszOptions,
  1377. int bIsLinearRing ) const;
  1378. // cppcheck-suppress unusedPrivateFunction
  1379. static OGRLineString* CasterToLineString( OGRCurve* poCurve );
  1380. // cppcheck-suppress unusedPrivateFunction
  1381. static OGRLinearRing* CasterToLinearRing( OGRCurve* poCurve );
  1382. protected:
  1383. //! @cond Doxygen_Suppress
  1384. static OGRLineString* CastToLineString( OGRCompoundCurve* poCC );
  1385. static OGRLinearRing* CastToLinearRing( OGRCompoundCurve* poCC );
  1386. virtual OGRCurveCasterToLineString GetCasterToLineString()
  1387. const override;
  1388. virtual OGRCurveCasterToLinearRing GetCasterToLinearRing()
  1389. const override;
  1390. //! @endcond
  1391. public:
  1392. OGRCompoundCurve();
  1393. OGRCompoundCurve( const OGRCompoundCurve& other );
  1394. ~OGRCompoundCurve() override;
  1395. OGRCompoundCurve& operator=( const OGRCompoundCurve& other );
  1396. /** Type of child elements. */
  1397. typedef OGRCurve ChildType;
  1398. /** Return begin of curve iterator.
  1399. * @since GDAL 2.3
  1400. */
  1401. ChildType** begin() { return oCC.begin(); }
  1402. /** Return end of curve iterator. */
  1403. ChildType** end() { return oCC.end(); }
  1404. /** Return begin of curve iterator.
  1405. * @since GDAL 2.3
  1406. */
  1407. const ChildType* const * begin() const { return oCC.begin(); }
  1408. /** Return end of curve iterator. */
  1409. const ChildType* const * end() const { return oCC.end(); }
  1410. // IWks Interface
  1411. virtual int WkbSize() const override;
  1412. virtual OGRErr importFromWkb( const unsigned char *,
  1413. int,
  1414. OGRwkbVariant,
  1415. int& nBytesConsumedOut ) override;
  1416. virtual OGRErr exportToWkb( OGRwkbByteOrder, unsigned char *,
  1417. OGRwkbVariant=wkbVariantOldOgc )
  1418. const override;
  1419. using OGRGeometry::importFromWkt; /** deprecated */
  1420. OGRErr importFromWkt( const char ** ) override;
  1421. virtual OGRErr exportToWkt( char ** ppszDstText,
  1422. OGRwkbVariant=wkbVariantOldOgc )
  1423. const override;
  1424. // IGeometry interface.
  1425. virtual OGRGeometry *clone() const override;
  1426. virtual void empty() override;
  1427. virtual void getEnvelope( OGREnvelope * psEnvelope ) const override;
  1428. virtual void getEnvelope( OGREnvelope3D * psEnvelope ) const override;
  1429. virtual OGRBoolean IsEmpty() const override;
  1430. // ICurve methods.
  1431. virtual double get_Length() const override;
  1432. virtual void StartPoint( OGRPoint * ) const override;
  1433. virtual void EndPoint( OGRPoint * ) const override;
  1434. virtual void Value( double, OGRPoint * ) const override;
  1435. virtual OGRLineString* CurveToLine( double dfMaxAngleStepSizeDegrees = 0,
  1436. const char* const* papszOptions = nullptr )
  1437. const override;
  1438. virtual int getNumPoints() const override;
  1439. virtual double get_AreaOfCurveSegments() const override;
  1440. virtual double get_Area() const override;
  1441. // ISpatialRelation.
  1442. virtual OGRBoolean Equals( const OGRGeometry * ) const override;
  1443. // ICompoundCurve method.
  1444. int getNumCurves() const;
  1445. OGRCurve *getCurve( int );
  1446. const OGRCurve *getCurve( int ) const;
  1447. // Non-standard.
  1448. virtual void setCoordinateDimension( int nDimension ) override;
  1449. virtual void set3D( OGRBoolean bIs3D ) override;
  1450. virtual void setMeasured( OGRBoolean bIsMeasured ) override;
  1451. virtual void assignSpatialReference( OGRSpatialReference * poSR ) override;
  1452. OGRErr addCurve( OGRCurve*, double dfToleranceEps = 1e-14 );
  1453. OGRErr addCurveDirectly( OGRCurve*, double dfToleranceEps = 1e-14 );
  1454. OGRCurve *stealCurve( int );
  1455. virtual OGRPointIterator* getPointIterator() const override;
  1456. // Non-standard from OGRGeometry.
  1457. virtual OGRwkbGeometryType getGeometryType() const override;
  1458. virtual const char *getGeometryName() const override;
  1459. virtual OGRErr transform( OGRCoordinateTransformation *poCT ) override;
  1460. virtual void flattenTo2D() override;
  1461. virtual void segmentize(double dfMaxLength) override;
  1462. virtual OGRBoolean hasCurveGeometry(int bLookForNonLinear = FALSE)
  1463. const override;
  1464. virtual OGRGeometry* getLinearGeometry(
  1465. double dfMaxAngleStepSizeDegrees = 0,
  1466. const char* const* papszOptions = nullptr) const override;
  1467. virtual void accept(IOGRGeometryVisitor* visitor) override { visitor->visit(this); }
  1468. virtual void accept(IOGRConstGeometryVisitor* visitor) const override { visitor->visit(this); }
  1469. virtual void swapXY() override;
  1470. };
  1471. //! @cond Doxygen_Suppress
  1472. /** @see OGRCompoundCurve::begin() const */
  1473. inline const OGRCompoundCurve::ChildType* const * begin(const OGRCompoundCurve* poCurve) { return poCurve->begin(); }
  1474. /** @see OGRCompoundCurve::end() const */
  1475. inline const OGRCompoundCurve::ChildType* const * end(const OGRCompoundCurve* poCurve) { return poCurve->end(); }
  1476. /** @see OGRCompoundCurve::begin() */
  1477. inline OGRCompoundCurve::ChildType** begin(OGRCompoundCurve* poCurve) { return poCurve->begin(); }
  1478. /** @see OGRCompoundCurve::end() */
  1479. inline OGRCompoundCurve::ChildType** end(OGRCompoundCurve* poCurve) { return poCurve->end(); }
  1480. //! @endcond
  1481. /************************************************************************/
  1482. /* OGRSurface */
  1483. /************************************************************************/
  1484. /**
  1485. * Abstract base class for 2 dimensional objects like polygons or curve
  1486. * polygons.
  1487. */
  1488. class CPL_DLL OGRSurface : public OGRGeometry
  1489. {
  1490. protected:
  1491. //! @cond Doxygen_Suppress
  1492. virtual OGRSurfaceCasterToPolygon GetCasterToPolygon() const = 0;
  1493. virtual OGRSurfaceCasterToCurvePolygon GetCasterToCurvePolygon() const = 0;
  1494. //! @endcond
  1495. public:
  1496. virtual double get_Area() const = 0;
  1497. virtual OGRErr PointOnSurface( OGRPoint * poPoint ) const
  1498. { return PointOnSurfaceInternal(poPoint); }
  1499. //! @cond Doxygen_Suppress
  1500. static OGRPolygon* CastToPolygon(OGRSurface* poSurface);
  1501. static OGRCurvePolygon* CastToCurvePolygon(OGRSurface* poSurface);
  1502. //! @endcond
  1503. };
  1504. /************************************************************************/
  1505. /* OGRCurvePolygon */
  1506. /************************************************************************/
  1507. /**
  1508. * Concrete class representing curve polygons.
  1509. *
  1510. * Note that curve polygons consist of one outer (curve) ring, and zero or
  1511. * more inner rings. A curve polygon cannot represent disconnected
  1512. * regions (such as multiple islands in a political body). The
  1513. * OGRMultiSurface must be used for this.
  1514. *
  1515. * Compatibility: ISO SQL/MM Part 3.
  1516. *
  1517. * @since GDAL 2.0
  1518. */
  1519. class CPL_DLL OGRCurvePolygon : public OGRSurface
  1520. {
  1521. static OGRPolygon* CasterToPolygon(OGRSurface* poSurface);
  1522. private:
  1523. OGRBoolean IntersectsPoint( const OGRPoint* p ) const;
  1524. OGRBoolean ContainsPoint( const OGRPoint* p ) const;
  1525. virtual int checkRing( OGRCurve * poNewRing ) const;
  1526. OGRErr addRingDirectlyInternal( OGRCurve* poCurve,
  1527. int bNeedRealloc );
  1528. static OGRErr addCurveDirectlyFromWkt( OGRGeometry* poSelf,
  1529. OGRCurve* poCurve );
  1530. static OGRErr addCurveDirectlyFromWkb( OGRGeometry* poSelf,
  1531. OGRCurve* poCurve );
  1532. protected:
  1533. //! @cond Doxygen_Suppress
  1534. friend class OGRPolygon;
  1535. friend class OGRTriangle;
  1536. OGRCurveCollection oCC{};
  1537. virtual OGRSurfaceCasterToPolygon GetCasterToPolygon()
  1538. const override;
  1539. virtual OGRSurfaceCasterToCurvePolygon GetCasterToCurvePolygon()
  1540. const override;
  1541. //! @endcond
  1542. static OGRPolygon* CastToPolygon( OGRCurvePolygon* poCP );
  1543. public:
  1544. OGRCurvePolygon();
  1545. OGRCurvePolygon( const OGRCurvePolygon& );
  1546. ~OGRCurvePolygon() override;
  1547. OGRCurvePolygon& operator=( const OGRCurvePolygon& other );
  1548. /** Type of child elements. */
  1549. typedef OGRCurve ChildType;
  1550. /** Return begin of curve iterator.
  1551. * @since GDAL 2.3
  1552. */
  1553. ChildType** begin() { return oCC.begin(); }
  1554. /** Return end of curve iterator. */
  1555. ChildType** end() { return oCC.end(); }
  1556. /** Return begin of curve iterator.
  1557. * @since GDAL 2.3
  1558. */
  1559. const ChildType* const * begin() const { return oCC.begin(); }
  1560. /** Return end of curve iterator. */
  1561. const ChildType* const * end() const { return oCC.end(); }
  1562. // Non standard (OGRGeometry).
  1563. virtual const char *getGeometryName() const override;
  1564. virtual OGRwkbGeometryType getGeometryType() const override;
  1565. virtual OGRGeometry *clone() const override;
  1566. virtual void empty() override;
  1567. virtual OGRErr transform( OGRCoordinateTransformation *poCT ) override;
  1568. virtual void flattenTo2D() override;
  1569. virtual OGRBoolean IsEmpty() const override;
  1570. virtual void segmentize( double dfMaxLength ) override;
  1571. virtual OGRBoolean hasCurveGeometry( int bLookForNonLinear = FALSE )
  1572. const override;
  1573. virtual OGRGeometry* getLinearGeometry(
  1574. double dfMaxAngleStepSizeDegrees = 0,
  1575. const char* const* papszOptions = nullptr ) const override;
  1576. // ISurface Interface
  1577. virtual double get_Area() const override;
  1578. // IWks Interface
  1579. virtual int WkbSize() const override;
  1580. virtual OGRErr importFromWkb( const unsigned char *,
  1581. int,
  1582. OGRwkbVariant,
  1583. int& nBytesConsumedOut ) override;
  1584. virtual OGRErr exportToWkb( OGRwkbByteOrder, unsigned char *,
  1585. OGRwkbVariant=wkbVariantOldOgc )
  1586. const override;
  1587. using OGRGeometry::importFromWkt; /** deprecated */
  1588. OGRErr importFromWkt( const char ** ) override;
  1589. virtual OGRErr exportToWkt( char ** ppszDstText,
  1590. OGRwkbVariant eWkbVariant = wkbVariantOldOgc )
  1591. const override;
  1592. // IGeometry
  1593. virtual int getDimension() const override;
  1594. virtual void getEnvelope( OGREnvelope * psEnvelope ) const override;
  1595. virtual void getEnvelope( OGREnvelope3D * psEnvelope ) const override;
  1596. // ICurvePolygon
  1597. virtual OGRPolygon* CurvePolyToPoly(
  1598. double dfMaxAngleStepSizeDegrees = 0,
  1599. const char* const* papszOptions = nullptr ) const;
  1600. // ISpatialRelation
  1601. virtual OGRBoolean Equals( const OGRGeometry * ) const override;
  1602. virtual OGRBoolean Intersects( const OGRGeometry * ) const override;
  1603. virtual OGRBoolean Contains( const OGRGeometry * ) const override;
  1604. // Non standard
  1605. virtual void setCoordinateDimension( int nDimension ) override;
  1606. virtual void set3D( OGRBoolean bIs3D ) override;
  1607. virtual void setMeasured( OGRBoolean bIsMeasured ) override;
  1608. virtual void assignSpatialReference( OGRSpatialReference * poSR ) override;
  1609. virtual OGRErr addRing( OGRCurve * );
  1610. virtual OGRErr addRingDirectly( OGRCurve * );
  1611. OGRCurve *getExteriorRingCurve();
  1612. const OGRCurve *getExteriorRingCurve() const;
  1613. int getNumInteriorRings() const;
  1614. OGRCurve *getInteriorRingCurve( int );
  1615. const OGRCurve *getInteriorRingCurve( int ) const;
  1616. OGRCurve *stealExteriorRingCurve();
  1617. OGRErr removeRing( int iIndex, bool bDelete = true );
  1618. virtual void accept(IOGRGeometryVisitor* visitor) override { visitor->visit(this); }
  1619. virtual void accept(IOGRConstGeometryVisitor* visitor) const override { visitor->visit(this); }
  1620. virtual void swapXY() override;
  1621. };
  1622. //! @cond Doxygen_Suppress
  1623. /** @see OGRCurvePolygon::begin() const */
  1624. inline const OGRCurvePolygon::ChildType* const * begin(const OGRCurvePolygon* poGeom) { return poGeom->begin(); }
  1625. /** @see OGRCurvePolygon::end() const */
  1626. inline const OGRCurvePolygon::ChildType* const * end(const OGRCurvePolygon* poGeom) { return poGeom->end(); }
  1627. /** @see OGRCurvePolygon::begin() */
  1628. inline OGRCurvePolygon::ChildType** begin(OGRCurvePolygon* poGeom) { return poGeom->begin(); }
  1629. /** @see OGRCurvePolygon::end() */
  1630. inline OGRCurvePolygon::ChildType** end(OGRCurvePolygon* poGeom) { return poGeom->end(); }
  1631. //! @endcond
  1632. /************************************************************************/
  1633. /* OGRPolygon */
  1634. /************************************************************************/
  1635. /**
  1636. * Concrete class representing polygons.
  1637. *
  1638. * Note that the OpenGIS simple features polygons consist of one outer ring
  1639. * (linearring), and zero or more inner rings. A polygon cannot represent
  1640. * disconnected regions (such as multiple islands in a political body). The
  1641. * OGRMultiPolygon must be used for this.
  1642. */
  1643. class CPL_DLL OGRPolygon : public OGRCurvePolygon
  1644. {
  1645. static OGRCurvePolygon* CasterToCurvePolygon(OGRSurface* poSurface);
  1646. protected:
  1647. //! @cond Doxygen_Suppress
  1648. friend class OGRMultiSurface;
  1649. friend class OGRPolyhedralSurface;
  1650. friend class OGRTriangulatedSurface;
  1651. virtual int checkRing( OGRCurve * poNewRing ) const override;
  1652. virtual OGRErr importFromWKTListOnly( const char ** ppszInput,
  1653. int bHasZ, int bHasM,
  1654. OGRRawPoint*& paoPoints,
  1655. int& nMaxPoints,
  1656. double*& padfZ );
  1657. static OGRCurvePolygon* CastToCurvePolygon(OGRPolygon* poPoly);
  1658. virtual OGRSurfaceCasterToPolygon GetCasterToPolygon()
  1659. const override;
  1660. virtual OGRSurfaceCasterToCurvePolygon GetCasterToCurvePolygon()
  1661. const override;
  1662. //! @endcond
  1663. public:
  1664. OGRPolygon();
  1665. OGRPolygon(const OGRPolygon& other);
  1666. ~OGRPolygon() override;
  1667. OGRPolygon& operator=(const OGRPolygon& other);
  1668. /** Type of child elements. */
  1669. typedef OGRLinearRing ChildType;
  1670. /** Return begin of iterator.
  1671. * @since GDAL 2.3
  1672. */
  1673. ChildType** begin() { return reinterpret_cast<ChildType**>(oCC.begin()); }
  1674. /** Return end of iterator */
  1675. ChildType** end() { return reinterpret_cast<ChildType**>(oCC.end()); }
  1676. /** Return begin of iterator.
  1677. * @since GDAL 2.3
  1678. */
  1679. const ChildType* const* begin() const { return reinterpret_cast<const ChildType* const*>(oCC.begin()); }
  1680. /** Return end of iterator */
  1681. const ChildType* const* end() const { return reinterpret_cast<const ChildType* const*>(oCC.end()); }
  1682. // Non-standard (OGRGeometry).
  1683. virtual const char *getGeometryName() const override;
  1684. virtual OGRwkbGeometryType getGeometryType() const override;
  1685. virtual OGRBoolean hasCurveGeometry( int bLookForNonLinear = FALSE )
  1686. const override;
  1687. virtual OGRGeometry* getCurveGeometry(
  1688. const char* const* papszOptions = nullptr ) const override;
  1689. virtual OGRGeometry* getLinearGeometry(
  1690. double dfMaxAngleStepSizeDegrees = 0,
  1691. const char* const* papszOptions = nullptr) const override;
  1692. // IWks Interface.
  1693. virtual int WkbSize() const override;
  1694. virtual OGRErr importFromWkb( const unsigned char *,
  1695. int,
  1696. OGRwkbVariant,
  1697. int& nBytesConsumedOut ) override;
  1698. virtual OGRErr exportToWkb( OGRwkbByteOrder, unsigned char *,
  1699. OGRwkbVariant=wkbVariantOldOgc )
  1700. const override;
  1701. using OGRGeometry::importFromWkt; /** deprecated */
  1702. OGRErr importFromWkt( const char ** ) override;
  1703. virtual OGRErr exportToWkt( char ** ppszDstText,
  1704. OGRwkbVariant=wkbVariantOldOgc )
  1705. const override;
  1706. // ICurvePolygon.
  1707. virtual OGRPolygon* CurvePolyToPoly(
  1708. double dfMaxAngleStepSizeDegrees = 0,
  1709. const char* const* papszOptions = nullptr ) const override;
  1710. OGRLinearRing *getExteriorRing();
  1711. const OGRLinearRing *getExteriorRing() const;
  1712. virtual OGRLinearRing *getInteriorRing( int );
  1713. virtual const OGRLinearRing *getInteriorRing( int ) const;
  1714. OGRLinearRing *stealExteriorRing();
  1715. virtual OGRLinearRing *stealInteriorRing(int);
  1716. OGRBoolean IsPointOnSurface( const OGRPoint * ) const;
  1717. /** Return pointer of this in upper class */
  1718. inline OGRCurvePolygon* toUpperClass() { return this; }
  1719. /** Return pointer of this in upper class */
  1720. inline const OGRCurvePolygon* toUpperClass() const { return this; }
  1721. virtual void accept(IOGRGeometryVisitor* visitor) override { visitor->visit(this); }
  1722. virtual void accept(IOGRConstGeometryVisitor* visitor) const override { visitor->visit(this); }
  1723. virtual void closeRings() override;
  1724. };
  1725. //! @cond Doxygen_Suppress
  1726. /** @see OGRPolygon::begin() const */
  1727. inline const OGRPolygon::ChildType* const * begin(const OGRPolygon* poGeom) { return poGeom->begin(); }
  1728. /** @see OGRPolygon::end() const */
  1729. inline const OGRPolygon::ChildType* const * end(const OGRPolygon* poGeom) { return poGeom->end(); }
  1730. /** @see OGRPolygon::begin() */
  1731. inline OGRPolygon::ChildType** begin(OGRPolygon* poGeom) { return poGeom->begin(); }
  1732. /** @see OGRPolygon::end() */
  1733. inline OGRPolygon::ChildType** end(OGRPolygon* poGeom) { return poGeom->end(); }
  1734. //! @endcond
  1735. /************************************************************************/
  1736. /* OGRTriangle */
  1737. /************************************************************************/
  1738. /**
  1739. * Triangle class.
  1740. *
  1741. * @since GDAL 2.2
  1742. */
  1743. class CPL_DLL OGRTriangle : public OGRPolygon
  1744. {
  1745. private:
  1746. // cppcheck-suppress unusedPrivateFunction
  1747. static OGRPolygon* CasterToPolygon(OGRSurface* poSurface);
  1748. bool quickValidityCheck() const;
  1749. protected:
  1750. //! @cond Doxygen_Suppress
  1751. virtual OGRSurfaceCasterToPolygon GetCasterToPolygon() const override;
  1752. virtual OGRErr importFromWKTListOnly( const char ** ppszInput,
  1753. int bHasZ, int bHasM,
  1754. OGRRawPoint*& paoPoints,
  1755. int& nMaxPoints,
  1756. double*& padfZ ) override;
  1757. //! @endcond
  1758. public:
  1759. OGRTriangle();
  1760. OGRTriangle( const OGRPoint &p, const OGRPoint &q, const OGRPoint &r );
  1761. OGRTriangle( const OGRTriangle &other );
  1762. OGRTriangle( const OGRPolygon &other, OGRErr &eErr );
  1763. OGRTriangle& operator=( const OGRTriangle& other );
  1764. ~OGRTriangle() override;
  1765. virtual const char *getGeometryName() const override;
  1766. virtual OGRwkbGeometryType getGeometryType() const override;
  1767. // IWks Interface.
  1768. virtual OGRErr importFromWkb( const unsigned char *,
  1769. int,
  1770. OGRwkbVariant,
  1771. int& nBytesConsumedOut ) override;
  1772. // New methods rewritten from OGRPolygon/OGRCurvePolygon/OGRGeometry.
  1773. virtual OGRErr addRingDirectly( OGRCurve * poNewRing ) override;
  1774. /** Return pointer of this in upper class */
  1775. inline OGRPolygon* toUpperClass() { return this; }
  1776. /** Return pointer of this in upper class */
  1777. inline const OGRPolygon* toUpperClass() const { return this; }
  1778. virtual void accept(IOGRGeometryVisitor* visitor) override { visitor->visit(this); }
  1779. virtual void accept(IOGRConstGeometryVisitor* visitor) const override { visitor->visit(this); }
  1780. //! @cond Doxygen_Suppress
  1781. static OGRGeometry* CastToPolygon( OGRGeometry* poGeom );
  1782. //! @endcond
  1783. };
  1784. /************************************************************************/
  1785. /* OGRGeometryCollection */
  1786. /************************************************************************/
  1787. /**
  1788. * A collection of 1 or more geometry objects.
  1789. *
  1790. * All geometries must share a common spatial reference system, and
  1791. * Subclasses may impose additional restrictions on the contents.
  1792. */
  1793. class CPL_DLL OGRGeometryCollection : public OGRGeometry
  1794. {
  1795. OGRErr importFromWkbInternal( const unsigned char * pabyData,
  1796. int nSize,
  1797. int nRecLevel,
  1798. OGRwkbVariant, int& nBytesConsumedOut );
  1799. OGRErr importFromWktInternal( const char **ppszInput, int nRecLevel );
  1800. protected:
  1801. //! @cond Doxygen_Suppress
  1802. int nGeomCount = 0;
  1803. OGRGeometry **papoGeoms = nullptr;
  1804. OGRErr exportToWktInternal( char ** ppszDstText,
  1805. OGRwkbVariant eWkbVariant,
  1806. const char* pszSkipPrefix ) const;
  1807. static OGRGeometryCollection* TransferMembersAndDestroy(
  1808. OGRGeometryCollection* poSrc,
  1809. OGRGeometryCollection* poDst );
  1810. //! @endcond
  1811. virtual OGRBoolean isCompatibleSubType( OGRwkbGeometryType ) const;
  1812. public:
  1813. OGRGeometryCollection();
  1814. OGRGeometryCollection( const OGRGeometryCollection& other );
  1815. ~OGRGeometryCollection() override;
  1816. OGRGeometryCollection& operator=( const OGRGeometryCollection& other );
  1817. /** Type of child elements. */
  1818. typedef OGRGeometry ChildType;
  1819. /** Return begin of sub-geometry iterator.
  1820. * @since GDAL 2.3
  1821. */
  1822. ChildType** begin() { return papoGeoms; }
  1823. /** Return end of sub-geometry iterator. */
  1824. ChildType** end() { return papoGeoms + nGeomCount; }
  1825. /** Return begin of sub-geometry iterator.
  1826. * @since GDAL 2.3
  1827. */
  1828. const ChildType* const* begin() const { return papoGeoms; }
  1829. /** Return end of sub-geometry iterator. */
  1830. const ChildType* const* end() const { return papoGeoms + nGeomCount; }
  1831. // Non standard (OGRGeometry).
  1832. virtual const char *getGeometryName() const override;
  1833. virtual OGRwkbGeometryType getGeometryType() const override;
  1834. virtual OGRGeometry *clone() const override;
  1835. virtual void empty() override;
  1836. virtual OGRErr transform( OGRCoordinateTransformation *poCT ) override;
  1837. virtual void flattenTo2D() override;
  1838. virtual OGRBoolean IsEmpty() const override;
  1839. virtual void segmentize(double dfMaxLength) override;
  1840. virtual OGRBoolean hasCurveGeometry( int bLookForNonLinear = FALSE )
  1841. const override;
  1842. virtual OGRGeometry* getCurveGeometry(
  1843. const char* const* papszOptions = nullptr ) const override;
  1844. virtual OGRGeometry* getLinearGeometry(
  1845. double dfMaxAngleStepSizeDegrees = 0,
  1846. const char* const* papszOptions = nullptr ) const override;
  1847. // IWks Interface
  1848. virtual int WkbSize() const override;
  1849. virtual OGRErr importFromWkb( const unsigned char *,
  1850. int,
  1851. OGRwkbVariant,
  1852. int& nBytesConsumedOut ) override;
  1853. virtual OGRErr exportToWkb( OGRwkbByteOrder, unsigned char *,
  1854. OGRwkbVariant=wkbVariantOldOgc )
  1855. const override;
  1856. using OGRGeometry::importFromWkt; /** deprecated */
  1857. OGRErr importFromWkt( const char ** ) override;
  1858. virtual OGRErr exportToWkt( char ** ppszDstText,
  1859. OGRwkbVariant=wkbVariantOldOgc )
  1860. const override;
  1861. virtual double get_Length() const;
  1862. virtual double get_Area() const;
  1863. // IGeometry methods
  1864. virtual int getDimension() const override;
  1865. virtual void getEnvelope( OGREnvelope * psEnvelope ) const override;
  1866. virtual void getEnvelope( OGREnvelope3D * psEnvelope ) const override;
  1867. // IGeometryCollection
  1868. int getNumGeometries() const;
  1869. OGRGeometry *getGeometryRef( int );
  1870. const OGRGeometry *getGeometryRef( int ) const;
  1871. // ISpatialRelation
  1872. virtual OGRBoolean Equals( const OGRGeometry * ) const override;
  1873. // Non standard
  1874. virtual void setCoordinateDimension( int nDimension ) override;
  1875. virtual void set3D( OGRBoolean bIs3D ) override;
  1876. virtual void setMeasured( OGRBoolean bIsMeasured ) override;
  1877. virtual OGRErr addGeometry( const OGRGeometry * );
  1878. virtual OGRErr addGeometryDirectly( OGRGeometry * );
  1879. virtual OGRErr removeGeometry( int iIndex, int bDelete = TRUE );
  1880. virtual void assignSpatialReference( OGRSpatialReference * poSR ) override;
  1881. void closeRings() override;
  1882. virtual void swapXY() override;
  1883. virtual void accept(IOGRGeometryVisitor* visitor) override { visitor->visit(this); }
  1884. virtual void accept(IOGRConstGeometryVisitor* visitor) const override { visitor->visit(this); }
  1885. static OGRGeometryCollection* CastToGeometryCollection(
  1886. OGRGeometryCollection* poSrc );
  1887. };
  1888. //! @cond Doxygen_Suppress
  1889. /** @see OGRGeometryCollection::begin() const */
  1890. inline const OGRGeometryCollection::ChildType* const * begin(const OGRGeometryCollection* poGeom) { return poGeom->begin(); }
  1891. /** @see OGRGeometryCollection::end() const */
  1892. inline const OGRGeometryCollection::ChildType* const * end(const OGRGeometryCollection* poGeom) { return poGeom->end(); }
  1893. /** @see OGRGeometryCollection::begin() */
  1894. inline OGRGeometryCollection::ChildType** begin(OGRGeometryCollection* poGeom) { return poGeom->begin(); }
  1895. /** @see OGRGeometryCollection::end() */
  1896. inline OGRGeometryCollection::ChildType** end(OGRGeometryCollection* poGeom) { return poGeom->end(); }
  1897. //! @endcond
  1898. /************************************************************************/
  1899. /* OGRMultiSurface */
  1900. /************************************************************************/
  1901. /**
  1902. * A collection of non-overlapping OGRSurface.
  1903. *
  1904. * @since GDAL 2.0
  1905. */
  1906. class CPL_DLL OGRMultiSurface : public OGRGeometryCollection
  1907. {
  1908. protected:
  1909. virtual OGRBoolean isCompatibleSubType( OGRwkbGeometryType )
  1910. const override;
  1911. public:
  1912. OGRMultiSurface();
  1913. OGRMultiSurface( const OGRMultiSurface& other );
  1914. ~OGRMultiSurface() override;
  1915. OGRMultiSurface& operator=( const OGRMultiSurface& other );
  1916. /** Type of child elements. */
  1917. typedef OGRSurface ChildType;
  1918. /** Return begin of iterator.
  1919. * @since GDAL 2.3
  1920. */
  1921. ChildType** begin() { return reinterpret_cast<ChildType**>(papoGeoms); }
  1922. /** Return end of iterator */
  1923. ChildType** end() { return reinterpret_cast<ChildType**>(papoGeoms + nGeomCount); }
  1924. /** Return begin of iterator.
  1925. * @since GDAL 2.3
  1926. */
  1927. const ChildType* const* begin() const { return reinterpret_cast<const ChildType* const*>(papoGeoms); }
  1928. /** Return end of iterator */
  1929. const ChildType* const* end() const { return reinterpret_cast<const ChildType* const*>(papoGeoms + nGeomCount); }
  1930. // Non standard (OGRGeometry).
  1931. virtual const char *getGeometryName() const override;
  1932. virtual OGRwkbGeometryType getGeometryType() const override;
  1933. using OGRGeometry::importFromWkt; /** deprecated */
  1934. OGRErr importFromWkt( const char ** ) override;
  1935. virtual OGRErr exportToWkt( char **, OGRwkbVariant=wkbVariantOldOgc )
  1936. const override;
  1937. // IMultiSurface methods
  1938. virtual OGRErr PointOnSurface( OGRPoint * poPoint ) const;
  1939. // IGeometry methods
  1940. virtual int getDimension() const override;
  1941. // Non standard
  1942. virtual OGRBoolean hasCurveGeometry( int bLookForNonLinear = FALSE )
  1943. const override;
  1944. /** Return pointer of this in upper class */
  1945. inline OGRGeometryCollection* toUpperClass() { return this; }
  1946. /** Return pointer of this in upper class */
  1947. inline const OGRGeometryCollection* toUpperClass() const { return this; }
  1948. virtual void accept(IOGRGeometryVisitor* visitor) override { visitor->visit(this); }
  1949. virtual void accept(IOGRConstGeometryVisitor* visitor) const override { visitor->visit(this); }
  1950. static OGRMultiPolygon* CastToMultiPolygon( OGRMultiSurface* poMS );
  1951. };
  1952. //! @cond Doxygen_Suppress
  1953. /** @see OGRMultiSurface::begin() const */
  1954. inline const OGRMultiSurface::ChildType* const * begin(const OGRMultiSurface* poGeom) { return poGeom->begin(); }
  1955. /** @see OGRMultiSurface::end() const */
  1956. inline const OGRMultiSurface::ChildType* const * end(const OGRMultiSurface* poGeom) { return poGeom->end(); }
  1957. /** @see OGRMultiSurface::begin() */
  1958. inline OGRMultiSurface::ChildType** begin(OGRMultiSurface* poGeom) { return poGeom->begin(); }
  1959. /** @see OGRMultiSurface::end() */
  1960. inline OGRMultiSurface::ChildType** end(OGRMultiSurface* poGeom) { return poGeom->end(); }
  1961. //! @endcond
  1962. /************************************************************************/
  1963. /* OGRMultiPolygon */
  1964. /************************************************************************/
  1965. /**
  1966. * A collection of non-overlapping OGRPolygon.
  1967. */
  1968. class CPL_DLL OGRMultiPolygon : public OGRMultiSurface
  1969. {
  1970. protected:
  1971. virtual OGRBoolean isCompatibleSubType( OGRwkbGeometryType )
  1972. const override;
  1973. friend class OGRPolyhedralSurface;
  1974. friend class OGRTriangulatedSurface;
  1975. private:
  1976. //! @cond Doxygen_Suppress
  1977. OGRErr _addGeometryWithExpectedSubGeometryType(
  1978. const OGRGeometry * poNewGeom,
  1979. OGRwkbGeometryType eSubGeometryType );
  1980. OGRErr _addGeometryDirectlyWithExpectedSubGeometryType(
  1981. OGRGeometry * poNewGeom,
  1982. OGRwkbGeometryType eSubGeometryType );
  1983. //! @endcond
  1984. public:
  1985. OGRMultiPolygon();
  1986. OGRMultiPolygon( const OGRMultiPolygon& other );
  1987. ~OGRMultiPolygon() override;
  1988. OGRMultiPolygon& operator=(const OGRMultiPolygon& other);
  1989. /** Type of child elements. */
  1990. typedef OGRPolygon ChildType;
  1991. /** Return begin of iterator.
  1992. * @since GDAL 2.3
  1993. */
  1994. ChildType** begin() { return reinterpret_cast<ChildType**>(papoGeoms); }
  1995. /** Return end of iterator */
  1996. ChildType** end() { return reinterpret_cast<ChildType**>(papoGeoms + nGeomCount); }
  1997. /** Return begin of iterator.
  1998. * @since GDAL 2.3
  1999. */
  2000. const ChildType* const* begin() const { return reinterpret_cast<const ChildType* const*>(papoGeoms); }
  2001. /** Return end of iterator */
  2002. const ChildType* const* end() const { return reinterpret_cast<const ChildType* const*>(papoGeoms + nGeomCount); }
  2003. // Non-standard (OGRGeometry).
  2004. virtual const char *getGeometryName() const override;
  2005. virtual OGRwkbGeometryType getGeometryType() const override;
  2006. virtual OGRErr exportToWkt( char **, OGRwkbVariant=wkbVariantOldOgc )
  2007. const override;
  2008. // Non standard
  2009. virtual OGRBoolean hasCurveGeometry( int bLookForNonLinear = FALSE )
  2010. const override;
  2011. /** Return pointer of this in upper class */
  2012. inline OGRGeometryCollection* toUpperClass() { return this; }
  2013. /** Return pointer of this in upper class */
  2014. inline const OGRGeometryCollection* toUpperClass() const { return this; }
  2015. virtual void accept(IOGRGeometryVisitor* visitor) override { visitor->visit(this); }
  2016. virtual void accept(IOGRConstGeometryVisitor* visitor) const override { visitor->visit(this); }
  2017. static OGRMultiSurface* CastToMultiSurface( OGRMultiPolygon* poMP );
  2018. };
  2019. //! @cond Doxygen_Suppress
  2020. /** @see OGRMultiPolygon::begin() const */
  2021. inline const OGRMultiPolygon::ChildType* const * begin(const OGRMultiPolygon* poGeom) { return poGeom->begin(); }
  2022. /** @see OGRMultiPolygon::end() const */
  2023. inline const OGRMultiPolygon::ChildType* const * end(const OGRMultiPolygon* poGeom) { return poGeom->end(); }
  2024. /** @see OGRMultiPolygon::begin() */
  2025. inline OGRMultiPolygon::ChildType** begin(OGRMultiPolygon* poGeom) { return poGeom->begin(); }
  2026. /** @see OGRMultiPolygon::end() */
  2027. inline OGRMultiPolygon::ChildType** end(OGRMultiPolygon* poGeom) { return poGeom->end(); }
  2028. //! @endcond
  2029. /************************************************************************/
  2030. /* OGRPolyhedralSurface */
  2031. /************************************************************************/
  2032. /**
  2033. * PolyhedralSurface class.
  2034. *
  2035. * @since GDAL 2.2
  2036. */
  2037. class CPL_DLL OGRPolyhedralSurface : public OGRSurface
  2038. {
  2039. protected:
  2040. //! @cond Doxygen_Suppress
  2041. friend class OGRTriangulatedSurface;
  2042. OGRMultiPolygon oMP{};
  2043. virtual OGRSurfaceCasterToPolygon GetCasterToPolygon()
  2044. const override;
  2045. virtual OGRSurfaceCasterToCurvePolygon GetCasterToCurvePolygon()
  2046. const override;
  2047. virtual OGRBoolean isCompatibleSubType( OGRwkbGeometryType ) const;
  2048. virtual const char* getSubGeometryName() const;
  2049. virtual OGRwkbGeometryType getSubGeometryType() const;
  2050. OGRErr exportToWktInternal (char ** ppszDstText, OGRwkbVariant eWkbVariant,
  2051. const char* pszSkipPrefix ) const;
  2052. virtual OGRPolyhedralSurfaceCastToMultiPolygon GetCasterToMultiPolygon()
  2053. const;
  2054. static OGRMultiPolygon* CastToMultiPolygonImpl(OGRPolyhedralSurface* poPS);
  2055. //! @endcond
  2056. public:
  2057. OGRPolyhedralSurface();
  2058. OGRPolyhedralSurface( const OGRPolyhedralSurface &poGeom );
  2059. ~OGRPolyhedralSurface() override;
  2060. OGRPolyhedralSurface& operator=(const OGRPolyhedralSurface& other);
  2061. /** Type of child elements. */
  2062. typedef OGRPolygon ChildType;
  2063. /** Return begin of iterator.
  2064. * @since GDAL 2.3
  2065. */
  2066. ChildType** begin() { return oMP.begin(); }
  2067. /** Return end of iterator */
  2068. ChildType** end() { return oMP.end(); }
  2069. /** Return begin of iterator.
  2070. * @since GDAL 2.3
  2071. */
  2072. const ChildType* const* begin() const { return oMP.begin(); }
  2073. /** Return end of iterator */
  2074. const ChildType* const* end() const { return oMP.end(); }
  2075. // IWks Interface.
  2076. virtual int WkbSize() const override;
  2077. virtual const char *getGeometryName() const override;
  2078. virtual OGRwkbGeometryType getGeometryType() const override;
  2079. virtual OGRErr importFromWkb( const unsigned char *,
  2080. int,
  2081. OGRwkbVariant,
  2082. int& nBytesConsumedOut ) override;
  2083. virtual OGRErr exportToWkb( OGRwkbByteOrder, unsigned char *,
  2084. OGRwkbVariant=wkbVariantOldOgc )
  2085. const override;
  2086. using OGRGeometry::importFromWkt; /** deprecated */
  2087. OGRErr importFromWkt( const char ** ) override;
  2088. virtual OGRErr exportToWkt( char ** ppszDstText,
  2089. OGRwkbVariant=wkbVariantOldOgc )
  2090. const override;
  2091. // IGeometry methods.
  2092. virtual int getDimension() const override;
  2093. virtual void empty() override;
  2094. virtual OGRGeometry *clone() const override;
  2095. virtual void getEnvelope( OGREnvelope * psEnvelope ) const override;
  2096. virtual void getEnvelope( OGREnvelope3D * psEnvelope ) const override;
  2097. virtual void flattenTo2D() override;
  2098. virtual OGRErr transform( OGRCoordinateTransformation* ) override;
  2099. virtual OGRBoolean Equals( const OGRGeometry* ) const override;
  2100. virtual double get_Area() const override;
  2101. virtual OGRErr PointOnSurface( OGRPoint* ) const override;
  2102. static OGRMultiPolygon* CastToMultiPolygon( OGRPolyhedralSurface* poPS );
  2103. virtual OGRBoolean hasCurveGeometry( int bLookForNonLinear = FALSE )
  2104. const override;
  2105. virtual OGRErr addGeometry( const OGRGeometry * );
  2106. OGRErr addGeometryDirectly( OGRGeometry *poNewGeom );
  2107. int getNumGeometries() const;
  2108. OGRGeometry* getGeometryRef(int i);
  2109. const OGRGeometry* getGeometryRef(int i) const;
  2110. virtual OGRBoolean IsEmpty() const override;
  2111. virtual void setCoordinateDimension( int nDimension ) override;
  2112. virtual void set3D( OGRBoolean bIs3D ) override;
  2113. virtual void setMeasured( OGRBoolean bIsMeasured ) override;
  2114. virtual void swapXY() override;
  2115. OGRErr removeGeometry( int iIndex, int bDelete = TRUE );
  2116. virtual void accept(IOGRGeometryVisitor* visitor) override { visitor->visit(this); }
  2117. virtual void accept(IOGRConstGeometryVisitor* visitor) const override { visitor->visit(this); }
  2118. virtual void assignSpatialReference( OGRSpatialReference * poSR ) override;
  2119. };
  2120. //! @cond Doxygen_Suppress
  2121. /** @see OGRPolyhedralSurface::begin() const */
  2122. inline const OGRPolyhedralSurface::ChildType* const * begin(const OGRPolyhedralSurface* poGeom) { return poGeom->begin(); }
  2123. /** @see OGRPolyhedralSurface::end() const */
  2124. inline const OGRPolyhedralSurface::ChildType* const * end(const OGRPolyhedralSurface* poGeom) { return poGeom->end(); }
  2125. /** @see OGRPolyhedralSurface::begin() */
  2126. inline OGRPolyhedralSurface::ChildType** begin(OGRPolyhedralSurface* poGeom) { return poGeom->begin(); }
  2127. /** @see OGRPolyhedralSurface::end() */
  2128. inline OGRPolyhedralSurface::ChildType** end(OGRPolyhedralSurface* poGeom) { return poGeom->end(); }
  2129. //! @endcond
  2130. /************************************************************************/
  2131. /* OGRTriangulatedSurface */
  2132. /************************************************************************/
  2133. /**
  2134. * TriangulatedSurface class.
  2135. *
  2136. * @since GDAL 2.2
  2137. */
  2138. class CPL_DLL OGRTriangulatedSurface : public OGRPolyhedralSurface
  2139. {
  2140. protected:
  2141. //! @cond Doxygen_Suppress
  2142. virtual OGRBoolean isCompatibleSubType( OGRwkbGeometryType )
  2143. const override;
  2144. virtual const char* getSubGeometryName() const override;
  2145. virtual OGRwkbGeometryType getSubGeometryType() const override;
  2146. virtual OGRPolyhedralSurfaceCastToMultiPolygon GetCasterToMultiPolygon()
  2147. const override;
  2148. static OGRMultiPolygon *
  2149. CastToMultiPolygonImpl( OGRPolyhedralSurface* poPS );
  2150. //! @endcond
  2151. public:
  2152. OGRTriangulatedSurface();
  2153. OGRTriangulatedSurface( const OGRTriangulatedSurface &other );
  2154. ~OGRTriangulatedSurface();
  2155. /** Type of child elements. */
  2156. typedef OGRTriangle ChildType;
  2157. /** Return begin of iterator.
  2158. * @since GDAL 2.3
  2159. */
  2160. ChildType** begin() { return reinterpret_cast<ChildType**>(oMP.begin()); }
  2161. /** Return end of iterator */
  2162. ChildType** end() { return reinterpret_cast<ChildType**>(oMP.end()); }
  2163. /** Return begin of iterator.
  2164. * @since GDAL 2.3
  2165. */
  2166. const ChildType* const* begin() const { return reinterpret_cast<const ChildType* const*>(oMP.begin()); }
  2167. /** Return end of iterator */
  2168. const ChildType* const* end() const { return reinterpret_cast<const ChildType* const*>(oMP.end()); }
  2169. OGRTriangulatedSurface& operator=( const OGRTriangulatedSurface& other );
  2170. virtual const char *getGeometryName() const override;
  2171. virtual OGRwkbGeometryType getGeometryType() const override;
  2172. // IWks Interface.
  2173. virtual OGRErr addGeometry( const OGRGeometry * ) override;
  2174. /** Return pointer of this in upper class */
  2175. inline OGRPolyhedralSurface* toUpperClass() { return this; }
  2176. /** Return pointer of this in upper class */
  2177. inline const OGRPolyhedralSurface* toUpperClass() const { return this; }
  2178. virtual void accept(IOGRGeometryVisitor* visitor) override { visitor->visit(this); }
  2179. virtual void accept(IOGRConstGeometryVisitor* visitor) const override { visitor->visit(this); }
  2180. static OGRPolyhedralSurface *
  2181. CastToPolyhedralSurface( OGRTriangulatedSurface* poTS );
  2182. };
  2183. //! @cond Doxygen_Suppress
  2184. /** @see OGRTriangulatedSurface::begin() const */
  2185. inline const OGRTriangulatedSurface::ChildType* const * begin(const OGRTriangulatedSurface* poGeom) { return poGeom->begin(); }
  2186. /** @see OGRTriangulatedSurface::end() const */
  2187. inline const OGRTriangulatedSurface::ChildType* const * end(const OGRTriangulatedSurface* poGeom) { return poGeom->end(); }
  2188. /** @see OGRTriangulatedSurface::begin() */
  2189. inline OGRTriangulatedSurface::ChildType** begin(OGRTriangulatedSurface* poGeom) { return poGeom->begin(); }
  2190. /** @see OGRTriangulatedSurface::end() */
  2191. inline OGRTriangulatedSurface::ChildType** end(OGRTriangulatedSurface* poGeom) { return poGeom->end(); }
  2192. //! @endcond
  2193. /************************************************************************/
  2194. /* OGRMultiPoint */
  2195. /************************************************************************/
  2196. /**
  2197. * A collection of OGRPoint.
  2198. */
  2199. class CPL_DLL OGRMultiPoint : public OGRGeometryCollection
  2200. {
  2201. private:
  2202. OGRErr importFromWkt_Bracketed( const char **, int bHasM, int bHasZ );
  2203. protected:
  2204. virtual OGRBoolean isCompatibleSubType( OGRwkbGeometryType )
  2205. const override;
  2206. public:
  2207. OGRMultiPoint();
  2208. OGRMultiPoint(const OGRMultiPoint& other);
  2209. ~OGRMultiPoint() override;
  2210. OGRMultiPoint& operator=(const OGRMultiPoint& other);
  2211. /** Type of child elements. */
  2212. typedef OGRPoint ChildType;
  2213. /** Return begin of iterator.
  2214. * @since GDAL 2.3
  2215. */
  2216. ChildType** begin() { return reinterpret_cast<ChildType**>(papoGeoms); }
  2217. /** Return end of iterator */
  2218. ChildType** end() { return reinterpret_cast<ChildType**>(papoGeoms + nGeomCount); }
  2219. /** Return begin of iterator.
  2220. * @since GDAL 2.3
  2221. */
  2222. const ChildType* const* begin() const { return reinterpret_cast<const ChildType* const*>(papoGeoms); }
  2223. /** Return end of iterator */
  2224. const ChildType* const* end() const { return reinterpret_cast<const ChildType* const*>(papoGeoms + nGeomCount); }
  2225. // Non-standard (OGRGeometry).
  2226. virtual const char *getGeometryName() const override;
  2227. virtual OGRwkbGeometryType getGeometryType() const override;
  2228. using OGRGeometry::importFromWkt; /** deprecated */
  2229. OGRErr importFromWkt( const char ** ) override;
  2230. virtual OGRErr exportToWkt( char **, OGRwkbVariant=wkbVariantOldOgc )
  2231. const override;
  2232. // IGeometry methods.
  2233. virtual int getDimension() const override;
  2234. /** Return pointer of this in upper class */
  2235. inline OGRGeometryCollection* toUpperClass() { return this; }
  2236. /** Return pointer of this in upper class */
  2237. inline const OGRGeometryCollection* toUpperClass() const { return this; }
  2238. virtual void accept(IOGRGeometryVisitor* visitor) override { visitor->visit(this); }
  2239. virtual void accept(IOGRConstGeometryVisitor* visitor) const override { visitor->visit(this); }
  2240. // Non-standard.
  2241. virtual OGRBoolean hasCurveGeometry( int bLookForNonLinear = FALSE )
  2242. const override;
  2243. };
  2244. //! @cond Doxygen_Suppress
  2245. /** @see OGRMultiPoint::begin() const */
  2246. inline const OGRMultiPoint::ChildType* const * begin(const OGRMultiPoint* poGeom) { return poGeom->begin(); }
  2247. /** @see OGRMultiPoint::end() const */
  2248. inline const OGRMultiPoint::ChildType* const * end(const OGRMultiPoint* poGeom) { return poGeom->end(); }
  2249. /** @see OGRMultiPoint::begin() */
  2250. inline OGRMultiPoint::ChildType** begin(OGRMultiPoint* poGeom) { return poGeom->begin(); }
  2251. /** @see OGRMultiPoint::end() */
  2252. inline OGRMultiPoint::ChildType** end(OGRMultiPoint* poGeom) { return poGeom->end(); }
  2253. //! @endcond
  2254. /************************************************************************/
  2255. /* OGRMultiCurve */
  2256. /************************************************************************/
  2257. /**
  2258. * A collection of OGRCurve.
  2259. *
  2260. * @since GDAL 2.0
  2261. */
  2262. class CPL_DLL OGRMultiCurve : public OGRGeometryCollection
  2263. {
  2264. protected:
  2265. //! @cond Doxygen_Suppress
  2266. static OGRErr addCurveDirectlyFromWkt( OGRGeometry* poSelf,
  2267. OGRCurve* poCurve );
  2268. //! @endcond
  2269. virtual OGRBoolean isCompatibleSubType( OGRwkbGeometryType )
  2270. const override;
  2271. public:
  2272. OGRMultiCurve();
  2273. OGRMultiCurve( const OGRMultiCurve& other );
  2274. ~OGRMultiCurve() override;
  2275. OGRMultiCurve& operator=( const OGRMultiCurve& other );
  2276. /** Type of child elements. */
  2277. typedef OGRCurve ChildType;
  2278. /** Return begin of iterator.
  2279. * @since GDAL 2.3
  2280. */
  2281. ChildType** begin() { return reinterpret_cast<ChildType**>(papoGeoms); }
  2282. /** Return end of iterator */
  2283. ChildType** end() { return reinterpret_cast<ChildType**>(papoGeoms + nGeomCount); }
  2284. /** Return begin of iterator.
  2285. * @since GDAL 2.3
  2286. */
  2287. const ChildType* const* begin() const { return reinterpret_cast<const ChildType* const*>(papoGeoms); }
  2288. /** Return end of iterator */
  2289. const ChildType* const* end() const { return reinterpret_cast<const ChildType* const*>(papoGeoms + nGeomCount); }
  2290. // Non standard (OGRGeometry).
  2291. virtual const char *getGeometryName() const override;
  2292. virtual OGRwkbGeometryType getGeometryType() const override;
  2293. using OGRGeometry::importFromWkt; /** deprecated */
  2294. OGRErr importFromWkt( const char ** ) override;
  2295. virtual OGRErr exportToWkt( char **, OGRwkbVariant=wkbVariantOldOgc )
  2296. const override;
  2297. // IGeometry methods.
  2298. virtual int getDimension() const override;
  2299. // Non-standard.
  2300. virtual OGRBoolean hasCurveGeometry( int bLookForNonLinear = FALSE )
  2301. const override;
  2302. /** Return pointer of this in upper class */
  2303. inline OGRGeometryCollection* toUpperClass() { return this; }
  2304. /** Return pointer of this in upper class */
  2305. inline const OGRGeometryCollection* toUpperClass() const { return this; }
  2306. virtual void accept(IOGRGeometryVisitor* visitor) override { visitor->visit(this); }
  2307. virtual void accept(IOGRConstGeometryVisitor* visitor) const override { visitor->visit(this); }
  2308. static OGRMultiLineString* CastToMultiLineString(OGRMultiCurve* poMC);
  2309. };
  2310. //! @cond Doxygen_Suppress
  2311. /** @see OGRMultiCurve::begin() const */
  2312. inline const OGRMultiCurve::ChildType* const * begin(const OGRMultiCurve* poGeom) { return poGeom->begin(); }
  2313. /** @see OGRMultiCurve::end() const */
  2314. inline const OGRMultiCurve::ChildType* const * end(const OGRMultiCurve* poGeom) { return poGeom->end(); }
  2315. /** @see OGRMultiCurve::begin() */
  2316. inline OGRMultiCurve::ChildType** begin(OGRMultiCurve* poGeom) { return poGeom->begin(); }
  2317. /** @see OGRMultiCurve::end() */
  2318. inline OGRMultiCurve::ChildType** end(OGRMultiCurve* poGeom) { return poGeom->end(); }
  2319. //! @endcond
  2320. /************************************************************************/
  2321. /* OGRMultiLineString */
  2322. /************************************************************************/
  2323. /**
  2324. * A collection of OGRLineString.
  2325. */
  2326. class CPL_DLL OGRMultiLineString : public OGRMultiCurve
  2327. {
  2328. protected:
  2329. virtual OGRBoolean isCompatibleSubType( OGRwkbGeometryType )
  2330. const override;
  2331. public:
  2332. OGRMultiLineString();
  2333. OGRMultiLineString( const OGRMultiLineString& other );
  2334. ~OGRMultiLineString() override;
  2335. OGRMultiLineString& operator=( const OGRMultiLineString& other );
  2336. /** Type of child elements. */
  2337. typedef OGRLineString ChildType;
  2338. /** Return begin of iterator.
  2339. * @since GDAL 2.3
  2340. */
  2341. ChildType** begin() { return reinterpret_cast<ChildType**>(papoGeoms); }
  2342. /** Return end of iterator */
  2343. ChildType** end() { return reinterpret_cast<ChildType**>(papoGeoms + nGeomCount); }
  2344. /** Return begin of iterator.
  2345. * @since GDAL 2.3
  2346. */
  2347. const ChildType* const* begin() const { return reinterpret_cast<const ChildType* const*>(papoGeoms); }
  2348. /** Return end of iterator */
  2349. const ChildType* const* end() const { return reinterpret_cast<const ChildType* const*>(papoGeoms + nGeomCount); }
  2350. // Non standard (OGRGeometry).
  2351. virtual const char *getGeometryName() const override;
  2352. virtual OGRwkbGeometryType getGeometryType() const override;
  2353. virtual OGRErr exportToWkt( char **, OGRwkbVariant=wkbVariantOldOgc )
  2354. const override;
  2355. // Non standard
  2356. virtual OGRBoolean hasCurveGeometry( int bLookForNonLinear = FALSE )
  2357. const override;
  2358. /** Return pointer of this in upper class */
  2359. inline OGRGeometryCollection* toUpperClass() { return this; }
  2360. /** Return pointer of this in upper class */
  2361. inline const OGRGeometryCollection* toUpperClass() const { return this; }
  2362. virtual void accept(IOGRGeometryVisitor* visitor) override { visitor->visit(this); }
  2363. virtual void accept(IOGRConstGeometryVisitor* visitor) const override { visitor->visit(this); }
  2364. static OGRMultiCurve* CastToMultiCurve( OGRMultiLineString* poMLS );
  2365. };
  2366. //! @cond Doxygen_Suppress
  2367. /** @see OGRMultiLineString::begin() const */
  2368. inline const OGRMultiLineString::ChildType* const * begin(const OGRMultiLineString* poGeom) { return poGeom->begin(); }
  2369. /** @see OGRMultiLineString::end() const */
  2370. inline const OGRMultiLineString::ChildType* const * end(const OGRMultiLineString* poGeom) { return poGeom->end(); }
  2371. /** @see OGRMultiLineString::begin() */
  2372. inline OGRMultiLineString::ChildType** begin(OGRMultiLineString* poGeom) { return poGeom->begin(); }
  2373. /** @see OGRMultiLineString::end() */
  2374. inline OGRMultiLineString::ChildType** end(OGRMultiLineString* poGeom) { return poGeom->end(); }
  2375. //! @endcond
  2376. /************************************************************************/
  2377. /* OGRGeometryFactory */
  2378. /************************************************************************/
  2379. /**
  2380. * Create geometry objects from well known text/binary.
  2381. */
  2382. class CPL_DLL OGRGeometryFactory
  2383. {
  2384. static OGRErr createFromFgfInternal( const unsigned char *pabyData,
  2385. OGRSpatialReference * poSR,
  2386. OGRGeometry **ppoReturn,
  2387. int nBytes,
  2388. int *pnBytesConsumed,
  2389. int nRecLevel );
  2390. public:
  2391. static OGRErr createFromWkb( const void *, OGRSpatialReference *,
  2392. OGRGeometry **, int = -1,
  2393. OGRwkbVariant=wkbVariantOldOgc );
  2394. static OGRErr createFromWkb( const void * pabyData,
  2395. OGRSpatialReference *,
  2396. OGRGeometry **,
  2397. int nSize,
  2398. OGRwkbVariant eVariant,
  2399. int& nBytesConsumedOut );
  2400. static OGRErr createFromWkt( const char* , OGRSpatialReference *,
  2401. OGRGeometry ** );
  2402. static OGRErr createFromWkt( const char **, OGRSpatialReference *,
  2403. OGRGeometry ** );
  2404. /** Deprecated.
  2405. * @deprecated in GDAL 2.3
  2406. */
  2407. static OGRErr createFromWkt( char ** ppszInput, OGRSpatialReference * poSRS,
  2408. OGRGeometry ** ppoGeom )
  2409. CPL_WARN_DEPRECATED("Use createFromWkt(const char**, ...) instead")
  2410. {
  2411. return createFromWkt( const_cast<const char**>(ppszInput), poSRS, ppoGeom);
  2412. }
  2413. static OGRErr createFromFgf( const void*, OGRSpatialReference *,
  2414. OGRGeometry **, int = -1, int * = nullptr );
  2415. static OGRGeometry *createFromGML( const char * );
  2416. static OGRGeometry *createFromGEOS( GEOSContextHandle_t hGEOSCtxt,
  2417. GEOSGeom );
  2418. static OGRGeometry *createFromGeoJson( const char *);
  2419. static OGRGeometry *createFromGeoJson( const CPLJSONObject &oJSONObject );
  2420. static void destroyGeometry( OGRGeometry * );
  2421. static OGRGeometry *createGeometry( OGRwkbGeometryType );
  2422. static OGRGeometry * forceToPolygon( OGRGeometry * );
  2423. static OGRGeometry * forceToLineString( OGRGeometry *,
  2424. bool bOnlyInOrder = true );
  2425. static OGRGeometry * forceToMultiPolygon( OGRGeometry * );
  2426. static OGRGeometry * forceToMultiPoint( OGRGeometry * );
  2427. static OGRGeometry * forceToMultiLineString( OGRGeometry * );
  2428. static OGRGeometry * forceTo( OGRGeometry* poGeom,
  2429. OGRwkbGeometryType eTargetType,
  2430. const char*const* papszOptions = nullptr );
  2431. static OGRGeometry * organizePolygons( OGRGeometry **papoPolygons,
  2432. int nPolygonCount,
  2433. int *pbResultValidGeometry,
  2434. const char **papszOptions = nullptr);
  2435. static bool haveGEOS();
  2436. /** Opaque class used as argument to transformWithOptions() */
  2437. class CPL_DLL TransformWithOptionsCache
  2438. {
  2439. friend class OGRGeometryFactory;
  2440. struct Private;
  2441. std::unique_ptr<Private> d;
  2442. public:
  2443. TransformWithOptionsCache();
  2444. ~TransformWithOptionsCache();
  2445. };
  2446. static OGRGeometry* transformWithOptions( const OGRGeometry* poSrcGeom,
  2447. OGRCoordinateTransformation *poCT,
  2448. char** papszOptions,
  2449. const TransformWithOptionsCache& cache = TransformWithOptionsCache() );
  2450. static OGRGeometry*
  2451. approximateArcAngles( double dfX, double dfY, double dfZ,
  2452. double dfPrimaryRadius, double dfSecondaryAxis,
  2453. double dfRotation,
  2454. double dfStartAngle, double dfEndAngle,
  2455. double dfMaxAngleStepSizeDegrees );
  2456. static int GetCurveParmeters( double x0, double y0,
  2457. double x1, double y1,
  2458. double x2, double y2,
  2459. double& R, double& cx, double& cy,
  2460. double& alpha0, double& alpha1,
  2461. double& alpha2 );
  2462. static OGRLineString* curveToLineString(
  2463. double x0, double y0, double z0,
  2464. double x1, double y1, double z1,
  2465. double x2, double y2, double z2,
  2466. int bHasZ,
  2467. double dfMaxAngleStepSizeDegrees,
  2468. const char* const * papszOptions = nullptr );
  2469. static OGRCurve* curveFromLineString(
  2470. const OGRLineString* poLS,
  2471. const char* const * papszOptions = nullptr);
  2472. };
  2473. OGRwkbGeometryType CPL_DLL OGRFromOGCGeomType( const char *pszGeomType );
  2474. const char CPL_DLL * OGRToOGCGeomType( OGRwkbGeometryType eGeomType );
  2475. /** Prepared geometry API (needs GEOS >= 3.1.0) */
  2476. typedef struct _OGRPreparedGeometry OGRPreparedGeometry;
  2477. int OGRHasPreparedGeometrySupport();
  2478. OGRPreparedGeometry* OGRCreatePreparedGeometry( const OGRGeometry* poGeom );
  2479. void OGRDestroyPreparedGeometry( OGRPreparedGeometry* poPreparedGeom );
  2480. int OGRPreparedGeometryIntersects( const OGRPreparedGeometry* poPreparedGeom,
  2481. const OGRGeometry* poOtherGeom );
  2482. int OGRPreparedGeometryContains( const OGRPreparedGeometry* poPreparedGeom,
  2483. const OGRGeometry* poOtherGeom );
  2484. //! @cond Doxygen_Suppress
  2485. struct CPL_DLL OGRPreparedGeometryUniquePtrDeleter
  2486. {
  2487. void operator()(OGRPreparedGeometry*) const;
  2488. };
  2489. //! @endcond
  2490. /** Unique pointer type for OGRPreparedGeometry.
  2491. * @since GDAL 2.3
  2492. */
  2493. typedef std::unique_ptr<OGRPreparedGeometry, OGRPreparedGeometryUniquePtrDeleter> OGRPreparedGeometryUniquePtr;
  2494. #endif /* ndef OGR_GEOMETRY_H_INCLUDED */
上海开阖软件有限公司 沪ICP备12045867号-1