ogr_geometry.h 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292
  1. /******************************************************************************
  2. * $Id: ogr_geometry.h 28123 2014-12-10 19:27:55Z 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 "ogr_core.h"
  34. #include "ogr_spatialref.h"
  35. /**
  36. * \file ogr_geometry.h
  37. *
  38. * Simple feature geometry classes.
  39. */
  40. /**
  41. * Simple container for a position.
  42. */
  43. class OGRRawPoint
  44. {
  45. public:
  46. OGRRawPoint()
  47. {
  48. x = y = 0.0;
  49. }
  50. OGRRawPoint(double x, double y) : x(x), y(y) {}
  51. double x;
  52. double y;
  53. };
  54. typedef struct GEOSGeom_t *GEOSGeom;
  55. typedef struct GEOSContextHandle_HS *GEOSContextHandle_t;
  56. class OGRPoint;
  57. class OGRCurve;
  58. class OGRCompoundCurve;
  59. class OGRLinearRing;
  60. class OGRLineString;
  61. class OGRSurface;
  62. class OGRCurvePolygon;
  63. class OGRPolygon;
  64. class OGRMultiSurface;
  65. class OGRMultiPolygon;
  66. class OGRMultiCurve;
  67. class OGRMultiLineString;
  68. typedef OGRLineString* (*OGRCurveCasterToLineString)(OGRCurve*);
  69. typedef OGRLinearRing* (*OGRCurveCasterToLinearRing)(OGRCurve*);
  70. typedef OGRPolygon* (*OGRSurfaceCasterToPolygon)(OGRSurface*);
  71. typedef OGRCurvePolygon* (*OGRSurfaceCasterToCurvePolygon)(OGRSurface*);
  72. /************************************************************************/
  73. /* OGRGeometry */
  74. /************************************************************************/
  75. /**
  76. * Abstract base class for all geometry classes.
  77. *
  78. * Some spatial analysis methods require that OGR is built on the GEOS library
  79. * to work properly. The precise meaning of methods that describe spatial relationships
  80. * between geometries is described in the SFCOM, or other simple features interface
  81. * specifications, like "OpenGIS® Implementation Specification for
  82. * Geographic information - Simple feature access - Part 1: Common architecture"
  83. * (<a href="http://www.opengeospatial.org/standards/sfa">OGC 06-103r4</a>)
  84. *
  85. * In GDAL 2.0, the hierarchy of classes has been extended with
  86. * <a href="https://portal.opengeospatial.org/files/?artifact_id=32024">
  87. * (working draft) ISO SQL/MM Part 3 (ISO/IEC 13249-3)</a> curve geometries :
  88. * CIRCULARSTRING (OGRCircularString), COMPOUNDCURVE (OGRCompoundCurve),
  89. * CURVEPOLYGON (OGRCurvePolygon), MULTICURVE (OGRMultiCurve) and MULTISURFACE (OGRMultiSurface).
  90. *
  91. */
  92. class CPL_DLL OGRGeometry
  93. {
  94. private:
  95. OGRSpatialReference * poSRS; // may be NULL
  96. protected:
  97. friend class OGRCurveCollection;
  98. int nCoordDimension;
  99. OGRErr importPreambuleFromWkt( char ** ppszInput,
  100. int* pbHasZ, int* pbHasM );
  101. OGRErr importCurveCollectionFromWkt( char ** ppszInput,
  102. int bAllowEmptyComponent,
  103. int bAllowLineString,
  104. int bAllowCurve,
  105. int bAllowCompoundCurve,
  106. OGRErr (*pfnAddCurveDirectly)(OGRGeometry* poSelf, OGRCurve* poCurve) );
  107. OGRErr importPreambuleFromWkb( unsigned char * pabyData,
  108. int nSize,
  109. OGRwkbByteOrder& eByteOrder,
  110. OGRBoolean& b3D,
  111. OGRwkbVariant eWkbVariant );
  112. OGRErr importPreambuleOfCollectionFromWkb(
  113. unsigned char * pabyData,
  114. int& nSize,
  115. int& nDataOffset,
  116. OGRwkbByteOrder& eByteOrder,
  117. int nMinSubGeomSize,
  118. int& nGeomCount,
  119. OGRwkbVariant eWkbVariant );
  120. public:
  121. OGRGeometry();
  122. virtual ~OGRGeometry();
  123. // standard IGeometry
  124. virtual int getDimension() const = 0;
  125. virtual int getCoordinateDimension() const;
  126. virtual OGRBoolean IsEmpty() const = 0;
  127. virtual OGRBoolean IsValid() const;
  128. virtual OGRBoolean IsSimple() const;
  129. virtual OGRBoolean IsRing() const;
  130. virtual void empty() = 0;
  131. virtual OGRGeometry *clone() const = 0;
  132. virtual void getEnvelope( OGREnvelope * psEnvelope ) const = 0;
  133. virtual void getEnvelope( OGREnvelope3D * psEnvelope ) const = 0;
  134. // IWks Interface
  135. virtual int WkbSize() const = 0;
  136. virtual OGRErr importFromWkb( unsigned char *, int=-1, OGRwkbVariant=wkbVariantOldOgc )=0;
  137. virtual OGRErr exportToWkb( OGRwkbByteOrder, unsigned char *, OGRwkbVariant=wkbVariantOldOgc ) const = 0;
  138. virtual OGRErr importFromWkt( char ** ppszInput ) = 0;
  139. virtual OGRErr exportToWkt( char ** ppszDstText, OGRwkbVariant=wkbVariantOldOgc ) const = 0;
  140. // non-standard
  141. virtual OGRwkbGeometryType getGeometryType() const = 0;
  142. OGRwkbGeometryType getIsoGeometryType() const;
  143. virtual const char *getGeometryName() const = 0;
  144. virtual void dumpReadable( FILE *, const char * = NULL, char** papszOptions = NULL ) const;
  145. virtual void flattenTo2D() = 0;
  146. virtual char * exportToGML( const char* const * papszOptions = NULL ) const;
  147. virtual char * exportToKML() const;
  148. virtual char * exportToJson() const;
  149. static GEOSContextHandle_t createGEOSContext();
  150. static void freeGEOSContext(GEOSContextHandle_t hGEOSCtxt);
  151. virtual GEOSGeom exportToGEOS(GEOSContextHandle_t hGEOSCtxt) const;
  152. virtual OGRBoolean hasCurveGeometry(int bLookForNonLinear = FALSE) const;
  153. virtual OGRGeometry* getCurveGeometry(const char* const* papszOptions = NULL) const;
  154. virtual OGRGeometry* getLinearGeometry(double dfMaxAngleStepSizeDegrees = 0,
  155. const char* const* papszOptions = NULL) const;
  156. virtual void closeRings();
  157. virtual void setCoordinateDimension( int nDimension );
  158. void assignSpatialReference( OGRSpatialReference * poSR );
  159. OGRSpatialReference *getSpatialReference( void ) const { return poSRS; }
  160. virtual OGRErr transform( OGRCoordinateTransformation *poCT ) = 0;
  161. OGRErr transformTo( OGRSpatialReference *poSR );
  162. virtual void segmentize(double dfMaxLength);
  163. // ISpatialRelation
  164. virtual OGRBoolean Intersects( const OGRGeometry * ) const;
  165. virtual OGRBoolean Equals( OGRGeometry * ) const = 0;
  166. virtual OGRBoolean Disjoint( const OGRGeometry * ) const;
  167. virtual OGRBoolean Touches( const OGRGeometry * ) const;
  168. virtual OGRBoolean Crosses( const OGRGeometry * ) const;
  169. virtual OGRBoolean Within( const OGRGeometry * ) const;
  170. virtual OGRBoolean Contains( const OGRGeometry * ) const;
  171. virtual OGRBoolean Overlaps( const OGRGeometry * ) const;
  172. // virtual OGRBoolean Relate( const OGRGeometry *, const char * ) const;
  173. virtual OGRGeometry *Boundary() const;
  174. virtual double Distance( const OGRGeometry * ) const;
  175. virtual OGRGeometry *ConvexHull() const;
  176. virtual OGRGeometry *Buffer( double dfDist, int nQuadSegs = 30 ) const;
  177. virtual OGRGeometry *Intersection( const OGRGeometry *) const;
  178. virtual OGRGeometry *Union( const OGRGeometry * ) const;
  179. virtual OGRGeometry *UnionCascaded() const;
  180. virtual OGRGeometry *Difference( const OGRGeometry * ) const;
  181. virtual OGRGeometry *SymDifference( const OGRGeometry * ) const;
  182. virtual OGRErr Centroid( OGRPoint * poPoint ) const;
  183. virtual OGRGeometry *Simplify(double dTolerance) const;
  184. OGRGeometry *SimplifyPreserveTopology(double dTolerance) const;
  185. virtual OGRGeometry *Polygonize() const;
  186. // backward compatibility to non-standard method names.
  187. OGRBoolean Intersect( OGRGeometry * ) const CPL_WARN_DEPRECATED("Non standard method. Use Intersects() instead");
  188. OGRBoolean Equal( OGRGeometry * ) const CPL_WARN_DEPRECATED("Non standard method. Use Equals() instead");
  189. virtual OGRGeometry *SymmetricDifference( const OGRGeometry * ) const CPL_WARN_DEPRECATED("Non standard method. Use SymDifference() instead");
  190. virtual OGRGeometry *getBoundary() const CPL_WARN_DEPRECATED("Non standard method. Use Boundary() instead");
  191. // Special HACK for DB2 7.2 support
  192. static int bGenerate_DB2_V72_BYTE_ORDER;
  193. virtual void swapXY();
  194. static OGRGeometry* CastToIdentity(OGRGeometry* poGeom) { return poGeom; }
  195. static OGRGeometry* CastToError(OGRGeometry* poGeom);
  196. };
  197. /************************************************************************/
  198. /* OGRPoint */
  199. /************************************************************************/
  200. /**
  201. * Point class.
  202. *
  203. * Implements SFCOM IPoint methods.
  204. */
  205. class CPL_DLL OGRPoint : public OGRGeometry
  206. {
  207. double x;
  208. double y;
  209. double z;
  210. public:
  211. OGRPoint();
  212. OGRPoint( double x, double y );
  213. OGRPoint( double x, double y, double z );
  214. virtual ~OGRPoint();
  215. // IWks Interface
  216. virtual int WkbSize() const;
  217. virtual OGRErr importFromWkb( unsigned char *, int=-1, OGRwkbVariant=wkbVariantOldOgc );
  218. virtual OGRErr exportToWkb( OGRwkbByteOrder, unsigned char *, OGRwkbVariant=wkbVariantOldOgc ) const;
  219. virtual OGRErr importFromWkt( char ** );
  220. virtual OGRErr exportToWkt( char ** ppszDstText, OGRwkbVariant=wkbVariantOldOgc ) const;
  221. // IGeometry
  222. virtual int getDimension() const;
  223. virtual int getCoordinateDimension() const;
  224. virtual OGRGeometry *clone() const;
  225. virtual void empty();
  226. virtual void getEnvelope( OGREnvelope * psEnvelope ) const;
  227. virtual void getEnvelope( OGREnvelope3D * psEnvelope ) const;
  228. virtual OGRBoolean IsEmpty() const;
  229. // IPoint
  230. double getX() const { return x; }
  231. double getY() const { return y; }
  232. double getZ() const { return z; }
  233. // Non standard
  234. virtual void setCoordinateDimension( int nDimension );
  235. void setX( double xIn ) { x = xIn; if (nCoordDimension <= 0) nCoordDimension = 2; }
  236. void setY( double yIn ) { y = yIn; if (nCoordDimension <= 0) nCoordDimension = 2; }
  237. void setZ( double zIn ) { z = zIn; nCoordDimension=3; }
  238. // ISpatialRelation
  239. virtual OGRBoolean Equals( OGRGeometry * ) const;
  240. virtual OGRBoolean Intersects( const OGRGeometry * ) const;
  241. virtual OGRBoolean Within( const OGRGeometry * ) const;
  242. // Non standard from OGRGeometry
  243. virtual const char *getGeometryName() const;
  244. virtual OGRwkbGeometryType getGeometryType() const;
  245. virtual OGRErr transform( OGRCoordinateTransformation *poCT );
  246. virtual void flattenTo2D();
  247. virtual void swapXY();
  248. };
  249. /************************************************************************/
  250. /* OGRPointIterator */
  251. /************************************************************************/
  252. /**
  253. * Interface for a point iterator.
  254. *
  255. * @since GDAL 2.0
  256. */
  257. class CPL_DLL OGRPointIterator
  258. {
  259. public:
  260. virtual ~OGRPointIterator();
  261. virtual OGRBoolean getNextPoint(OGRPoint* p) = 0;
  262. static void destroy(OGRPointIterator*);
  263. };
  264. /************************************************************************/
  265. /* OGRCurve */
  266. /************************************************************************/
  267. /**
  268. * Abstract curve base class for OGRLineString, OGRCircularString and
  269. * OGRCompoundCurve
  270. */
  271. class CPL_DLL OGRCurve : public OGRGeometry
  272. {
  273. protected:
  274. OGRCurve();
  275. virtual OGRCurveCasterToLineString GetCasterToLineString() const = 0;
  276. virtual OGRCurveCasterToLinearRing GetCasterToLinearRing() const = 0;
  277. friend class OGRCurvePolygon;
  278. friend class OGRCompoundCurve;
  279. virtual int ContainsPoint( const OGRPoint* p ) const;
  280. virtual double get_AreaOfCurveSegments() const = 0;
  281. public:
  282. virtual ~OGRCurve();
  283. // ICurve methods
  284. virtual double get_Length() const = 0;
  285. virtual void StartPoint(OGRPoint *) const = 0;
  286. virtual void EndPoint(OGRPoint *) const = 0;
  287. virtual int get_IsClosed() const;
  288. virtual void Value( double, OGRPoint * ) const = 0;
  289. virtual OGRLineString* CurveToLine(double dfMaxAngleStepSizeDegrees = 0,
  290. const char* const* papszOptions = NULL) const = 0;
  291. virtual int getDimension() const;
  292. // non standard
  293. virtual int getNumPoints() const = 0;
  294. virtual OGRPointIterator* getPointIterator() const = 0;
  295. virtual OGRBoolean IsConvex() const;
  296. virtual double get_Area() const = 0;
  297. static OGRCompoundCurve* CastToCompoundCurve(OGRCurve* puCurve);
  298. static OGRLineString* CastToLineString(OGRCurve* poCurve);
  299. static OGRLinearRing* CastToLinearRing(OGRCurve* poCurve);
  300. };
  301. /************************************************************************/
  302. /* OGRSimpleCurve */
  303. /************************************************************************/
  304. /**
  305. * Abstract curve base class for OGRLineString and OGRCircularString
  306. *
  307. * Note: this class does not exist in SQL/MM standard and exists for
  308. * implementation convenience.
  309. *
  310. * @since GDAL 2.0
  311. */
  312. class CPL_DLL OGRSimpleCurve: public OGRCurve
  313. {
  314. protected:
  315. friend class OGRGeometry;
  316. int nPointCount;
  317. OGRRawPoint *paoPoints;
  318. double *padfZ;
  319. void Make3D();
  320. void Make2D();
  321. OGRErr importFromWKTListOnly( char ** ppszInput, int bHasZ, int bHasM,
  322. OGRRawPoint*& paoPointsIn, int& nMaxPoints,
  323. double*& padfZIn );
  324. virtual double get_LinearArea() const;
  325. OGRSimpleCurve();
  326. public:
  327. virtual ~OGRSimpleCurve();
  328. // IWks Interface
  329. virtual int WkbSize() const;
  330. virtual OGRErr importFromWkb( unsigned char *, int = -1, OGRwkbVariant=wkbVariantOldOgc );
  331. virtual OGRErr exportToWkb( OGRwkbByteOrder, unsigned char *, OGRwkbVariant=wkbVariantOldOgc ) const;
  332. virtual OGRErr importFromWkt( char ** );
  333. virtual OGRErr exportToWkt( char ** ppszDstText, OGRwkbVariant=wkbVariantOldOgc ) const;
  334. // IGeometry interface
  335. virtual OGRGeometry *clone() const;
  336. virtual void empty();
  337. virtual void getEnvelope( OGREnvelope * psEnvelope ) const;
  338. virtual void getEnvelope( OGREnvelope3D * psEnvelope ) const;
  339. virtual OGRBoolean IsEmpty() const;
  340. // ICurve methods
  341. virtual double get_Length() const;
  342. virtual void StartPoint(OGRPoint *) const;
  343. virtual void EndPoint(OGRPoint *) const;
  344. virtual void Value( double, OGRPoint * ) const;
  345. virtual double Project(const OGRPoint *) const;
  346. virtual OGRLineString* getSubLine(double, double, int) const;
  347. // ILineString methods
  348. virtual int getNumPoints() const { return nPointCount; }
  349. void getPoint( int, OGRPoint * ) const;
  350. double getX( int i ) const { return paoPoints[i].x; }
  351. double getY( int i ) const { return paoPoints[i].y; }
  352. double getZ( int i ) const;
  353. // ISpatialRelation
  354. virtual OGRBoolean Equals( OGRGeometry * ) const;
  355. // non standard.
  356. virtual void setCoordinateDimension( int nDimension );
  357. void setNumPoints( int nNewPointCount, int bZeroizeNewContent = TRUE );
  358. void setPoint( int, OGRPoint * );
  359. void setPoint( int, double, double );
  360. void setZ( int, double );
  361. void setPoint( int, double, double, double );
  362. void setPoints( int, OGRRawPoint *, double * = NULL );
  363. void setPoints( int, double * padfX, double * padfY,
  364. double *padfZIn = NULL );
  365. void addPoint( OGRPoint * );
  366. void addPoint( double, double );
  367. void addPoint( double, double, double );
  368. void getPoints( OGRRawPoint *, double * = NULL ) const;
  369. void getPoints( void* pabyX, int nXStride,
  370. void* pabyY, int nYStride,
  371. void* pabyZ = NULL, int nZStride = 0 ) const;
  372. void addSubLineString( const OGRLineString *,
  373. int nStartVertex = 0, int nEndVertex = -1 );
  374. void reversePoints( void );
  375. virtual OGRPointIterator* getPointIterator() const;
  376. // non-standard from OGRGeometry
  377. virtual OGRErr transform( OGRCoordinateTransformation *poCT );
  378. virtual void flattenTo2D();
  379. virtual void segmentize(double dfMaxLength);
  380. virtual void swapXY();
  381. };
  382. /************************************************************************/
  383. /* OGRLineString */
  384. /************************************************************************/
  385. /**
  386. * Concrete representation of a multi-vertex line.
  387. *
  388. * Note: for implementation convenience, we make it inherit from OGRSimpleCurve whereas
  389. * SFSQL and SQL/MM only make it inherits from OGRCurve.
  390. */
  391. class CPL_DLL OGRLineString : public OGRSimpleCurve
  392. {
  393. protected:
  394. static OGRLineString* TransferMembersAndDestroy(
  395. OGRLineString* poSrc,
  396. OGRLineString* poDst);
  397. static OGRLinearRing* CastToLinearRing(OGRLineString* poLS);
  398. virtual OGRCurveCasterToLineString GetCasterToLineString() const;
  399. virtual OGRCurveCasterToLinearRing GetCasterToLinearRing() const;
  400. virtual double get_AreaOfCurveSegments() const;
  401. public:
  402. OGRLineString();
  403. virtual ~OGRLineString();
  404. virtual OGRLineString* CurveToLine(double dfMaxAngleStepSizeDegrees = 0,
  405. const char* const* papszOptions = NULL) const;
  406. virtual OGRGeometry* getCurveGeometry(const char* const* papszOptions = NULL) const;
  407. virtual double get_Area() const;
  408. // non-standard from OGRGeometry
  409. virtual OGRwkbGeometryType getGeometryType() const;
  410. virtual const char *getGeometryName() const;
  411. };
  412. /************************************************************************/
  413. /* OGRLinearRing */
  414. /************************************************************************/
  415. /**
  416. * Concrete representation of a closed ring.
  417. *
  418. * This class is functionally equivelent to an OGRLineString, but has a
  419. * separate identity to maintain alignment with the OpenGIS simple feature
  420. * data model. It exists to serve as a component of an OGRPolygon.
  421. *
  422. * The OGRLinearRing has no corresponding free standing well known binary
  423. * representation, so importFromWkb() and exportToWkb() will not actually
  424. * work. There is a non-standard GDAL WKT representation though.
  425. *
  426. * Because OGRLinearRing is not a "proper" free standing simple features
  427. * object, it cannot be directly used on a feature via SetGeometry(), and
  428. * cannot genearally be used with GEOS for operations like Intersects().
  429. * Instead the polygon should be used, or the OGRLinearRing should be
  430. * converted to an OGRLineString for such operations.
  431. *
  432. * Note: this class exists in SFSQL 1.2, but not in ISO SQL/MM Part 3.
  433. */
  434. class CPL_DLL OGRLinearRing : public OGRLineString
  435. {
  436. protected:
  437. friend class OGRPolygon;
  438. // These are not IWks compatible ... just a convenience for OGRPolygon.
  439. virtual int _WkbSize( int b3D ) const;
  440. virtual OGRErr _importFromWkb( OGRwkbByteOrder, int b3D,
  441. unsigned char *, int=-1 );
  442. virtual OGRErr _exportToWkb( OGRwkbByteOrder, int b3D,
  443. unsigned char * ) const;
  444. static OGRLineString* CastToLineString(OGRLinearRing* poLR);
  445. virtual OGRCurveCasterToLineString GetCasterToLineString() const;
  446. virtual OGRCurveCasterToLinearRing GetCasterToLinearRing() const;
  447. public:
  448. OGRLinearRing();
  449. OGRLinearRing( OGRLinearRing * );
  450. virtual ~OGRLinearRing();
  451. // Non standard.
  452. virtual const char *getGeometryName() const;
  453. virtual OGRGeometry *clone() const;
  454. virtual int isClockwise() const;
  455. virtual void reverseWindingOrder();
  456. virtual void closeRings();
  457. OGRBoolean isPointInRing(const OGRPoint* pt, int bTestEnvelope = TRUE) const;
  458. OGRBoolean isPointOnRingBoundary(const OGRPoint* pt, int bTestEnvelope = TRUE) const;
  459. // IWks Interface - Note this isnt really a first class object
  460. // for the purposes of WKB form. These methods always fail since this
  461. // object cant be serialized on its own.
  462. virtual int WkbSize() const;
  463. virtual OGRErr importFromWkb( unsigned char *, int=-1, OGRwkbVariant=wkbVariantOldOgc );
  464. virtual OGRErr exportToWkb( OGRwkbByteOrder, unsigned char *, OGRwkbVariant=wkbVariantOldOgc ) const;
  465. };
  466. /************************************************************************/
  467. /* OGRCircularString */
  468. /************************************************************************/
  469. /**
  470. * Concrete representation of a circular string, that is to say a curve made
  471. * of one or several arc circles.
  472. *
  473. * Note: for implementation convenience, we make it inherit from OGRSimpleCurve whereas
  474. * SQL/MM only makes it inherits from OGRCurve.
  475. *
  476. * Compatibility: ISO SQL/MM Part 3.
  477. *
  478. * @since GDAL 2.0
  479. */
  480. class CPL_DLL OGRCircularString : public OGRSimpleCurve
  481. {
  482. private:
  483. void ExtendEnvelopeWithCircular( OGREnvelope * psEnvelope ) const;
  484. OGRBoolean IsValidFast() const;
  485. int IsFullCircle( double& cx, double& cy, double& square_R ) const;
  486. protected:
  487. virtual OGRCurveCasterToLineString GetCasterToLineString() const;
  488. virtual OGRCurveCasterToLinearRing GetCasterToLinearRing() const;
  489. virtual int ContainsPoint( const OGRPoint* p ) const;
  490. virtual double get_AreaOfCurveSegments() const;
  491. public:
  492. OGRCircularString();
  493. virtual ~OGRCircularString();
  494. // IWks Interface
  495. virtual OGRErr importFromWkb( unsigned char *, int = -1, OGRwkbVariant=wkbVariantOldOgc );
  496. virtual OGRErr exportToWkb( OGRwkbByteOrder, unsigned char *, OGRwkbVariant=wkbVariantOldOgc ) const;
  497. virtual OGRErr importFromWkt( char ** );
  498. virtual OGRErr exportToWkt( char ** ppszDstText, OGRwkbVariant=wkbVariantOldOgc ) const;
  499. // IGeometry interface
  500. virtual OGRBoolean IsValid() const;
  501. virtual void getEnvelope( OGREnvelope * psEnvelope ) const;
  502. virtual void getEnvelope( OGREnvelope3D * psEnvelope ) const;
  503. // ICurve methods
  504. virtual double get_Length() const;
  505. virtual OGRLineString* CurveToLine(double dfMaxAngleStepSizeDegrees = 0,
  506. const char* const* papszOptions = NULL) const;
  507. virtual void Value( double, OGRPoint * ) const;
  508. virtual double get_Area() const;
  509. // non-standard from OGRGeometry
  510. virtual OGRwkbGeometryType getGeometryType() const;
  511. virtual const char *getGeometryName() const;
  512. virtual void segmentize(double dfMaxLength);
  513. virtual OGRBoolean hasCurveGeometry(int bLookForNonLinear = FALSE) const;
  514. virtual OGRGeometry* getLinearGeometry(double dfMaxAngleStepSizeDegrees = 0,
  515. const char* const* papszOptions = NULL) const;
  516. };
  517. /************************************************************************/
  518. /* OGRCurveCollection */
  519. /************************************************************************/
  520. /**
  521. * Utility class to store a collection of curves. Used as a member of
  522. * OGRCompoundCurve and OGRCurvePolygon.
  523. *
  524. * This class is only exported because of linking issues. It should never
  525. * be directly used.
  526. *
  527. * @since GDAL 2.0
  528. */
  529. class CPL_DLL OGRCurveCollection
  530. {
  531. protected:
  532. friend class OGRCompoundCurve;
  533. friend class OGRCurvePolygon;
  534. friend class OGRPolygon;
  535. int nCurveCount;
  536. OGRCurve **papoCurves;
  537. public:
  538. OGRCurveCollection();
  539. ~OGRCurveCollection();
  540. void empty(OGRGeometry* poGeom);
  541. OGRBoolean IsEmpty() const;
  542. void getEnvelope( OGREnvelope * psEnvelope ) const;
  543. void getEnvelope( OGREnvelope3D * psEnvelope ) const;
  544. OGRErr addCurveDirectly( OGRGeometry* poGeom, OGRCurve* poCurve,
  545. int bNeedRealloc );
  546. int WkbSize() const;
  547. OGRErr importPreambuleFromWkb( OGRGeometry* poGeom,
  548. unsigned char * pabyData,
  549. int& nSize,
  550. int& nDataOffset,
  551. OGRwkbByteOrder& eByteOrder,
  552. int nMinSubGeomSize,
  553. OGRwkbVariant eWkVariant );
  554. OGRErr importBodyFromWkb( OGRGeometry* poGeom,
  555. unsigned char * pabyData,
  556. int nSize,
  557. int nDataOffset,
  558. int bAcceptCompoundCurve,
  559. OGRErr (*pfnAddCurveDirectlyFromWkb)(OGRGeometry* poGeom, OGRCurve* poCurve),
  560. OGRwkbVariant eWkVariant );
  561. OGRErr exportToWkt( const OGRGeometry* poGeom, char ** ppszDstText ) const;
  562. OGRErr exportToWkb( const OGRGeometry* poGeom, OGRwkbByteOrder,
  563. unsigned char *, OGRwkbVariant eWkbVariant ) const;
  564. OGRBoolean Equals(OGRCurveCollection *poOCC) const;
  565. void setCoordinateDimension( OGRGeometry* poGeom, int nNewDimension );
  566. int getNumCurves() const;
  567. OGRCurve *getCurve( int );
  568. const OGRCurve *getCurve( int ) const;
  569. OGRCurve *stealCurve( int );
  570. OGRErr transform( OGRGeometry* poGeom,
  571. OGRCoordinateTransformation *poCT );
  572. void flattenTo2D(OGRGeometry* poGeom);
  573. void segmentize(double dfMaxLength);
  574. void swapXY();
  575. OGRBoolean hasCurveGeometry(int bLookForNonLinear) const;
  576. };
  577. /************************************************************************/
  578. /* OGRCompoundCurve */
  579. /************************************************************************/
  580. /**
  581. * Concrete representation of a compound curve, made of curves: OGRLineString
  582. * and OGRCircularString. Each curve is connected by its first point to
  583. * the last point of the previous curve.
  584. *
  585. * Compatibility: ISO SQL/MM Part 3.
  586. *
  587. * @since GDAL 2.0
  588. */
  589. class CPL_DLL OGRCompoundCurve : public OGRCurve
  590. {
  591. private:
  592. OGRCurveCollection oCC;
  593. OGRErr addCurveDirectlyInternal( OGRCurve* poCurve,
  594. double dfToleranceEps,
  595. int bNeedRealloc );
  596. static OGRErr addCurveDirectlyFromWkt( OGRGeometry* poSelf, OGRCurve* poCurve );
  597. static OGRErr addCurveDirectlyFromWkb( OGRGeometry* poSelf, OGRCurve* poCurve );
  598. OGRLineString* CurveToLineInternal(double dfMaxAngleStepSizeDegrees,
  599. const char* const* papszOptions,
  600. int bIsLinearRing) const;
  601. protected:
  602. static OGRLineString* CastToLineString(OGRCompoundCurve* poCC);
  603. static OGRLinearRing* CastToLinearRing(OGRCompoundCurve* poCC);
  604. virtual OGRCurveCasterToLineString GetCasterToLineString() const;
  605. virtual OGRCurveCasterToLinearRing GetCasterToLinearRing() const;
  606. public:
  607. OGRCompoundCurve();
  608. virtual ~OGRCompoundCurve();
  609. // IWks Interface
  610. virtual int WkbSize() const;
  611. virtual OGRErr importFromWkb( unsigned char *, int = -1, OGRwkbVariant=wkbVariantOldOgc );
  612. virtual OGRErr exportToWkb( OGRwkbByteOrder, unsigned char *, OGRwkbVariant=wkbVariantOldOgc ) const;
  613. virtual OGRErr importFromWkt( char ** );
  614. virtual OGRErr exportToWkt( char ** ppszDstText, OGRwkbVariant=wkbVariantOldOgc ) const;
  615. // IGeometry interface
  616. virtual OGRGeometry *clone() const;
  617. virtual void empty();
  618. virtual void getEnvelope( OGREnvelope * psEnvelope ) const;
  619. virtual void getEnvelope( OGREnvelope3D * psEnvelope ) const;
  620. virtual OGRBoolean IsEmpty() const;
  621. // ICurve methods
  622. virtual double get_Length() const;
  623. virtual void StartPoint(OGRPoint *) const;
  624. virtual void EndPoint(OGRPoint *) const;
  625. virtual void Value( double, OGRPoint * ) const;
  626. virtual OGRLineString* CurveToLine(double dfMaxAngleStepSizeDegrees = 0,
  627. const char* const* papszOptions = NULL) const;
  628. virtual int getNumPoints() const;
  629. virtual double get_AreaOfCurveSegments() const;
  630. virtual double get_Area() const;
  631. // ISpatialRelation
  632. virtual OGRBoolean Equals( OGRGeometry * ) const;
  633. // ICompoundCurve method
  634. int getNumCurves() const;
  635. OGRCurve *getCurve( int );
  636. const OGRCurve *getCurve( int ) const;
  637. // non standard.
  638. virtual void setCoordinateDimension( int nDimension );
  639. OGRErr addCurve( OGRCurve*, double dfToleranceEps = 1e-14 );
  640. OGRErr addCurveDirectly( OGRCurve*, double dfToleranceEps = 1e-14 );
  641. OGRCurve *stealCurve( int );
  642. virtual OGRPointIterator* getPointIterator() const;
  643. // non-standard from OGRGeometry
  644. virtual OGRwkbGeometryType getGeometryType() const;
  645. virtual const char *getGeometryName() const;
  646. virtual OGRErr transform( OGRCoordinateTransformation *poCT );
  647. virtual void flattenTo2D();
  648. virtual void segmentize(double dfMaxLength);
  649. virtual OGRBoolean hasCurveGeometry(int bLookForNonLinear = FALSE) const;
  650. virtual OGRGeometry* getLinearGeometry(double dfMaxAngleStepSizeDegrees = 0,
  651. const char* const* papszOptions = NULL) const;
  652. virtual void swapXY();
  653. };
  654. /************************************************************************/
  655. /* OGRSurface */
  656. /************************************************************************/
  657. /**
  658. * Abstract base class for 2 dimensional objects like polygons or curve polygons.
  659. */
  660. class CPL_DLL OGRSurface : public OGRGeometry
  661. {
  662. protected:
  663. virtual OGRSurfaceCasterToPolygon GetCasterToPolygon() const = 0;
  664. virtual OGRSurfaceCasterToCurvePolygon GetCasterToCurvePolygon() const = 0;
  665. public:
  666. virtual double get_Area() const = 0;
  667. virtual OGRErr PointOnSurface( OGRPoint * poPoint ) const = 0;
  668. static OGRPolygon* CastToPolygon(OGRSurface* poSurface);
  669. static OGRCurvePolygon* CastToCurvePolygon(OGRSurface* poSurface);
  670. };
  671. /************************************************************************/
  672. /* OGRCurvePolygon */
  673. /************************************************************************/
  674. /**
  675. * Concrete class representing curve polygons.
  676. *
  677. * Note that curve polygons consist of one outer (curve) ring, and zero or
  678. * more inner rings. A curve polygon cannot represent disconnected
  679. * regions (such as multiple islands in a political body). The
  680. * OGRMultiSurface must be used for this.
  681. *
  682. * Compatibility: ISO SQL/MM Part 3.
  683. *
  684. * @since GDAL 2.0
  685. */
  686. class CPL_DLL OGRCurvePolygon : public OGRSurface
  687. {
  688. private:
  689. OGRBoolean ContainsPoint( const OGRPoint* p ) const;
  690. virtual int checkRing( OGRCurve * poNewRing ) const;
  691. OGRErr addRingDirectlyInternal( OGRCurve* poCurve, int bNeedRealloc );
  692. static OGRErr addCurveDirectlyFromWkt( OGRGeometry* poSelf, OGRCurve* poCurve );
  693. static OGRErr addCurveDirectlyFromWkb( OGRGeometry* poSelf, OGRCurve* poCurve );
  694. protected:
  695. friend class OGRPolygon;
  696. OGRCurveCollection oCC;
  697. static OGRPolygon* CastToPolygon(OGRCurvePolygon* poCP);
  698. virtual OGRSurfaceCasterToPolygon GetCasterToPolygon() const;
  699. virtual OGRSurfaceCasterToCurvePolygon GetCasterToCurvePolygon() const;
  700. public:
  701. OGRCurvePolygon();
  702. virtual ~OGRCurvePolygon();
  703. // Non standard (OGRGeometry).
  704. virtual const char *getGeometryName() const;
  705. virtual OGRwkbGeometryType getGeometryType() const;
  706. virtual OGRGeometry *clone() const;
  707. virtual void empty();
  708. virtual OGRErr transform( OGRCoordinateTransformation *poCT );
  709. virtual void flattenTo2D();
  710. virtual OGRBoolean IsEmpty() const;
  711. virtual void segmentize(double dfMaxLength);
  712. virtual OGRBoolean hasCurveGeometry(int bLookForNonLinear = FALSE) const;
  713. virtual OGRGeometry* getLinearGeometry(double dfMaxAngleStepSizeDegrees = 0,
  714. const char* const* papszOptions = NULL) const;
  715. // ISurface Interface
  716. virtual double get_Area() const;
  717. virtual int PointOnSurface( OGRPoint * poPoint ) const;
  718. // IWks Interface
  719. virtual int WkbSize() const;
  720. virtual OGRErr importFromWkb( unsigned char *, int = -1, OGRwkbVariant=wkbVariantOldOgc );
  721. virtual OGRErr exportToWkb( OGRwkbByteOrder, unsigned char *, OGRwkbVariant=wkbVariantOldOgc ) const;
  722. virtual OGRErr importFromWkt( char ** );
  723. virtual OGRErr exportToWkt( char ** ppszDstText, OGRwkbVariant eWkbVariant = wkbVariantOldOgc ) const;
  724. // IGeometry
  725. virtual int getDimension() const;
  726. virtual void getEnvelope( OGREnvelope * psEnvelope ) const;
  727. virtual void getEnvelope( OGREnvelope3D * psEnvelope ) const;
  728. // ICurvePolygon
  729. virtual OGRPolygon* CurvePolyToPoly(double dfMaxAngleStepSizeDegrees = 0,
  730. const char* const* papszOptions = NULL) const;
  731. // ISpatialRelation
  732. virtual OGRBoolean Equals( OGRGeometry * ) const;
  733. virtual OGRBoolean Intersects( const OGRGeometry * ) const;
  734. virtual OGRBoolean Contains( const OGRGeometry * ) const;
  735. // Non standard
  736. virtual void setCoordinateDimension( int nDimension );
  737. OGRErr addRing( OGRCurve * );
  738. OGRErr addRingDirectly( OGRCurve * );
  739. OGRCurve *getExteriorRingCurve();
  740. const OGRCurve *getExteriorRingCurve() const;
  741. int getNumInteriorRings() const;
  742. OGRCurve *getInteriorRingCurve( int );
  743. const OGRCurve *getInteriorRingCurve( int ) const;
  744. OGRCurve *stealExteriorRingCurve();
  745. virtual void swapXY();
  746. };
  747. /************************************************************************/
  748. /* OGRPolygon */
  749. /************************************************************************/
  750. /**
  751. * Concrete class representing polygons.
  752. *
  753. * Note that the OpenGIS simple features polygons consist of one outer
  754. * ring (linearring), and zero or more inner rings. A polygon cannot represent disconnected
  755. * regions (such as multiple islands in a political body). The
  756. * OGRMultiPolygon must be used for this.
  757. */
  758. class CPL_DLL OGRPolygon : public OGRCurvePolygon
  759. {
  760. protected:
  761. friend class OGRMultiSurface;
  762. virtual int checkRing( OGRCurve * poNewRing ) const;
  763. OGRErr importFromWKTListOnly( char ** ppszInput, int bHasZ, int bHasM,
  764. OGRRawPoint*& paoPoints, int& nMaxPoints,
  765. double*& padfZ );
  766. static OGRCurvePolygon* CastToCurvePolygon(OGRPolygon* poPoly);
  767. virtual OGRSurfaceCasterToPolygon GetCasterToPolygon() const;
  768. virtual OGRSurfaceCasterToCurvePolygon GetCasterToCurvePolygon() const;
  769. public:
  770. OGRPolygon();
  771. virtual ~OGRPolygon();
  772. // Non standard (OGRGeometry).
  773. virtual const char *getGeometryName() const;
  774. virtual OGRwkbGeometryType getGeometryType() const;
  775. virtual OGRBoolean hasCurveGeometry(int bLookForNonLinear = FALSE) const;
  776. virtual OGRGeometry* getCurveGeometry(const char* const* papszOptions = NULL) const;
  777. virtual OGRGeometry* getLinearGeometry(double dfMaxAngleStepSizeDegrees = 0,
  778. const char* const* papszOptions = NULL) const;
  779. // ISurface Interface
  780. virtual int PointOnSurface( OGRPoint * poPoint ) const;
  781. // IWks Interface
  782. virtual int WkbSize() const;
  783. virtual OGRErr importFromWkb( unsigned char *, int = -1, OGRwkbVariant=wkbVariantOldOgc );
  784. virtual OGRErr exportToWkb( OGRwkbByteOrder, unsigned char *, OGRwkbVariant=wkbVariantOldOgc ) const;
  785. virtual OGRErr importFromWkt( char ** );
  786. virtual OGRErr exportToWkt( char ** ppszDstText, OGRwkbVariant=wkbVariantOldOgc ) const;
  787. // ICurvePolygon
  788. virtual OGRPolygon* CurvePolyToPoly(double dfMaxAngleStepSizeDegrees = 0,
  789. const char* const* papszOptions = NULL) const;
  790. OGRLinearRing *getExteriorRing();
  791. const OGRLinearRing *getExteriorRing() const;
  792. OGRLinearRing *getInteriorRing( int );
  793. const OGRLinearRing *getInteriorRing( int ) const;
  794. OGRLinearRing *stealExteriorRing();
  795. OGRLinearRing *stealInteriorRing(int);
  796. OGRBoolean IsPointOnSurface( const OGRPoint * ) const;
  797. virtual void closeRings();
  798. };
  799. /************************************************************************/
  800. /* OGRGeometryCollection */
  801. /************************************************************************/
  802. /**
  803. * A collection of 1 or more geometry objects.
  804. *
  805. * All geometries must share a common spatial reference system, and
  806. * Subclasses may impose additional restrictions on the contents.
  807. */
  808. class CPL_DLL OGRGeometryCollection : public OGRGeometry
  809. {
  810. OGRErr importFromWkbInternal( unsigned char * pabyData, int nSize, int nRecLevel,
  811. OGRwkbVariant );
  812. OGRErr importFromWktInternal( char **ppszInput, int nRecLevel );
  813. protected:
  814. int nGeomCount;
  815. OGRGeometry **papoGeoms;
  816. OGRErr exportToWktInternal( char ** ppszDstText,
  817. OGRwkbVariant eWkbVariant,
  818. const char* pszSkipPrefix ) const;
  819. virtual OGRBoolean isCompatibleSubType( OGRwkbGeometryType ) const;
  820. static OGRGeometryCollection* TransferMembersAndDestroy(OGRGeometryCollection* poSrc,
  821. OGRGeometryCollection* poDst);
  822. public:
  823. OGRGeometryCollection();
  824. virtual ~OGRGeometryCollection();
  825. // Non standard (OGRGeometry).
  826. virtual const char *getGeometryName() const;
  827. virtual OGRwkbGeometryType getGeometryType() const;
  828. virtual OGRGeometry *clone() const;
  829. virtual void empty();
  830. virtual OGRErr transform( OGRCoordinateTransformation *poCT );
  831. virtual void flattenTo2D();
  832. virtual OGRBoolean IsEmpty() const;
  833. virtual void segmentize(double dfMaxLength);
  834. virtual OGRBoolean hasCurveGeometry(int bLookForNonLinear = FALSE) const;
  835. virtual OGRGeometry* getCurveGeometry(const char* const* papszOptions = NULL) const;
  836. virtual OGRGeometry* getLinearGeometry(double dfMaxAngleStepSizeDegrees = 0, const char* const* papszOptions = NULL) const;
  837. // IWks Interface
  838. virtual int WkbSize() const;
  839. virtual OGRErr importFromWkb( unsigned char *, int = -1, OGRwkbVariant=wkbVariantOldOgc );
  840. virtual OGRErr exportToWkb( OGRwkbByteOrder, unsigned char *, OGRwkbVariant=wkbVariantOldOgc ) const;
  841. virtual OGRErr importFromWkt( char ** );
  842. virtual OGRErr exportToWkt( char ** ppszDstText, OGRwkbVariant=wkbVariantOldOgc ) const;
  843. virtual double get_Length() const;
  844. virtual double get_Area() const;
  845. // IGeometry methods
  846. virtual int getDimension() const;
  847. virtual void getEnvelope( OGREnvelope * psEnvelope ) const;
  848. virtual void getEnvelope( OGREnvelope3D * psEnvelope ) const;
  849. // IGeometryCollection
  850. int getNumGeometries() const;
  851. OGRGeometry *getGeometryRef( int );
  852. const OGRGeometry *getGeometryRef( int ) const;
  853. // ISpatialRelation
  854. virtual OGRBoolean Equals( OGRGeometry * ) const;
  855. // Non standard
  856. virtual void setCoordinateDimension( int nDimension );
  857. virtual OGRErr addGeometry( const OGRGeometry * );
  858. virtual OGRErr addGeometryDirectly( OGRGeometry * );
  859. virtual OGRErr removeGeometry( int iIndex, int bDelete = TRUE );
  860. void closeRings();
  861. virtual void swapXY();
  862. };
  863. /************************************************************************/
  864. /* OGRMultiSurface */
  865. /************************************************************************/
  866. /**
  867. * A collection of non-overlapping OGRSurface.
  868. *
  869. * @since GDAL 2.0
  870. */
  871. class CPL_DLL OGRMultiSurface : public OGRGeometryCollection
  872. {
  873. protected:
  874. virtual OGRBoolean isCompatibleSubType( OGRwkbGeometryType ) const;
  875. public:
  876. OGRMultiSurface();
  877. virtual ~OGRMultiSurface();
  878. // Non standard (OGRGeometry).
  879. virtual const char *getGeometryName() const;
  880. virtual OGRwkbGeometryType getGeometryType() const;
  881. virtual OGRErr importFromWkt( char ** );
  882. virtual OGRErr exportToWkt( char **, OGRwkbVariant=wkbVariantOldOgc ) const;
  883. // IMultiSurface methods
  884. virtual OGRErr PointOnSurface( OGRPoint * poPoint ) const;
  885. // IGeometry methods
  886. virtual int getDimension() const;
  887. // Non standard
  888. virtual OGRBoolean hasCurveGeometry(int bLookForNonLinear = FALSE) const;
  889. static OGRMultiPolygon* CastToMultiPolygon(OGRMultiSurface* poMS);
  890. };
  891. /************************************************************************/
  892. /* OGRMultiPolygon */
  893. /************************************************************************/
  894. /**
  895. * A collection of non-overlapping OGRPolygon.
  896. */
  897. class CPL_DLL OGRMultiPolygon : public OGRMultiSurface
  898. {
  899. protected:
  900. virtual OGRBoolean isCompatibleSubType( OGRwkbGeometryType ) const;
  901. public:
  902. OGRMultiPolygon();
  903. virtual ~OGRMultiPolygon();
  904. // Non standard (OGRGeometry).
  905. virtual const char *getGeometryName() const;
  906. virtual OGRwkbGeometryType getGeometryType() const;
  907. virtual OGRErr exportToWkt( char **, OGRwkbVariant=wkbVariantOldOgc ) const;
  908. // IMultiSurface methods
  909. virtual OGRErr PointOnSurface( OGRPoint * poPoint ) const;
  910. // Non standard
  911. virtual OGRBoolean hasCurveGeometry(int bLookForNonLinear = FALSE) const;
  912. static OGRMultiSurface* CastToMultiSurface(OGRMultiPolygon* poMP);
  913. };
  914. /************************************************************************/
  915. /* OGRMultiPoint */
  916. /************************************************************************/
  917. /**
  918. * A collection of OGRPoint.
  919. */
  920. class CPL_DLL OGRMultiPoint : public OGRGeometryCollection
  921. {
  922. private:
  923. OGRErr importFromWkt_Bracketed( char **, int bHasM, int bHasZ );
  924. protected:
  925. virtual OGRBoolean isCompatibleSubType( OGRwkbGeometryType ) const;
  926. public:
  927. OGRMultiPoint();
  928. virtual ~OGRMultiPoint();
  929. // Non standard (OGRGeometry).
  930. virtual const char *getGeometryName() const;
  931. virtual OGRwkbGeometryType getGeometryType() const;
  932. virtual OGRErr importFromWkt( char ** );
  933. virtual OGRErr exportToWkt( char **, OGRwkbVariant=wkbVariantOldOgc ) const;
  934. // IGeometry methods
  935. virtual int getDimension() const;
  936. // Non standard
  937. virtual OGRBoolean hasCurveGeometry(int bLookForNonLinear = FALSE) const;
  938. };
  939. /************************************************************************/
  940. /* OGRMultiCurve */
  941. /************************************************************************/
  942. /**
  943. * A collection of OGRCurve.
  944. *
  945. * @since GDAL 2.0
  946. */
  947. class CPL_DLL OGRMultiCurve : public OGRGeometryCollection
  948. {
  949. protected:
  950. static OGRErr addCurveDirectlyFromWkt( OGRGeometry* poSelf, OGRCurve* poCurve );
  951. virtual OGRBoolean isCompatibleSubType( OGRwkbGeometryType ) const;
  952. public:
  953. OGRMultiCurve();
  954. virtual ~OGRMultiCurve();
  955. // Non standard (OGRGeometry).
  956. virtual const char *getGeometryName() const;
  957. virtual OGRwkbGeometryType getGeometryType() const;
  958. virtual OGRErr importFromWkt( char ** );
  959. virtual OGRErr exportToWkt( char **, OGRwkbVariant=wkbVariantOldOgc ) const;
  960. // IGeometry methods
  961. virtual int getDimension() const;
  962. // Non standard
  963. virtual OGRBoolean hasCurveGeometry(int bLookForNonLinear = FALSE) const;
  964. static OGRMultiLineString* CastToMultiLineString(OGRMultiCurve* poMC);
  965. };
  966. /************************************************************************/
  967. /* OGRMultiLineString */
  968. /************************************************************************/
  969. /**
  970. * A collection of OGRLineString.
  971. */
  972. class CPL_DLL OGRMultiLineString : public OGRMultiCurve
  973. {
  974. protected:
  975. virtual OGRBoolean isCompatibleSubType( OGRwkbGeometryType ) const;
  976. public:
  977. OGRMultiLineString();
  978. virtual ~OGRMultiLineString();
  979. // Non standard (OGRGeometry).
  980. virtual const char *getGeometryName() const;
  981. virtual OGRwkbGeometryType getGeometryType() const;
  982. virtual OGRErr exportToWkt( char **, OGRwkbVariant=wkbVariantOldOgc ) const;
  983. // Non standard
  984. virtual OGRBoolean hasCurveGeometry(int bLookForNonLinear = FALSE) const;
  985. static OGRMultiCurve* CastToMultiCurve(OGRMultiLineString* poMLS);
  986. };
  987. /************************************************************************/
  988. /* OGRGeometryFactory */
  989. /************************************************************************/
  990. /**
  991. * Create geometry objects from well known text/binary.
  992. */
  993. class CPL_DLL OGRGeometryFactory
  994. {
  995. static OGRErr createFromFgfInternal( unsigned char *pabyData,
  996. OGRSpatialReference * poSR,
  997. OGRGeometry **ppoReturn,
  998. int nBytes,
  999. int *pnBytesConsumed,
  1000. int nRecLevel );
  1001. public:
  1002. static OGRErr createFromWkb( unsigned char *, OGRSpatialReference *,
  1003. OGRGeometry **, int = -1, OGRwkbVariant=wkbVariantOldOgc );
  1004. static OGRErr createFromWkt( char **, OGRSpatialReference *,
  1005. OGRGeometry ** );
  1006. static OGRErr createFromFgf( unsigned char *, OGRSpatialReference *,
  1007. OGRGeometry **, int = -1, int * = NULL );
  1008. static OGRGeometry *createFromGML( const char * );
  1009. static OGRGeometry *createFromGEOS( GEOSContextHandle_t hGEOSCtxt, GEOSGeom );
  1010. static void destroyGeometry( OGRGeometry * );
  1011. static OGRGeometry *createGeometry( OGRwkbGeometryType );
  1012. static OGRGeometry * forceToPolygon( OGRGeometry * );
  1013. static OGRGeometry * forceToLineString( OGRGeometry *, bool bOnlyInOrder = true );
  1014. static OGRGeometry * forceToMultiPolygon( OGRGeometry * );
  1015. static OGRGeometry * forceToMultiPoint( OGRGeometry * );
  1016. static OGRGeometry * forceToMultiLineString( OGRGeometry * );
  1017. static OGRGeometry * forceTo( OGRGeometry* poGeom,
  1018. OGRwkbGeometryType eTargetType,
  1019. const char*const* papszOptions = NULL );
  1020. static OGRGeometry * organizePolygons( OGRGeometry **papoPolygons,
  1021. int nPolygonCount,
  1022. int *pbResultValidGeometry,
  1023. const char **papszOptions = NULL);
  1024. static int haveGEOS();
  1025. static OGRGeometry* transformWithOptions( const OGRGeometry* poSrcGeom,
  1026. OGRCoordinateTransformation *poCT,
  1027. char** papszOptions );
  1028. static OGRGeometry*
  1029. approximateArcAngles( double dfX, double dfY, double dfZ,
  1030. double dfPrimaryRadius, double dfSecondaryAxis,
  1031. double dfRotation,
  1032. double dfStartAngle, double dfEndAngle,
  1033. double dfMaxAngleStepSizeDegrees );
  1034. static int GetCurveParmeters(double x0, double y0,
  1035. double x1, double y1,
  1036. double x2, double y2,
  1037. double& R, double& cx, double& cy,
  1038. double& alpha0, double& alpha1, double& alpha2 );
  1039. static OGRLineString* curveToLineString( double x0, double y0, double z0,
  1040. double x1, double y1, double z1,
  1041. double x2, double y2, double z2,
  1042. int bHasZ,
  1043. double dfMaxAngleStepSizeDegrees,
  1044. const char*const* papszOptions = NULL );
  1045. static OGRCurve* curveFromLineString(const OGRLineString* poLS,
  1046. const char*const* papszOptions = NULL);
  1047. };
  1048. OGRwkbGeometryType CPL_DLL OGRFromOGCGeomType( const char *pszGeomType );
  1049. const char CPL_DLL * OGRToOGCGeomType( OGRwkbGeometryType eGeomType );
  1050. /* Prepared geometry API (needs GEOS >= 3.1.0) */
  1051. typedef struct _OGRPreparedGeometry OGRPreparedGeometry;
  1052. int OGRHasPreparedGeometrySupport();
  1053. OGRPreparedGeometry* OGRCreatePreparedGeometry( const OGRGeometry* poGeom );
  1054. void OGRDestroyPreparedGeometry( OGRPreparedGeometry* poPreparedGeom );
  1055. int OGRPreparedGeometryIntersects( const OGRPreparedGeometry* poPreparedGeom,
  1056. const OGRGeometry* poOtherGeom );
  1057. #endif /* ndef _OGR_GEOMETRY_H_INCLUDED */