00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef _OGR_GEOMETRY_H_INCLUDED
00032 #define _OGR_GEOMETRY_H_INCLUDED
00033
00034 #include "ogr_core.h"
00035 #include "ogr_spatialref.h"
00036
00046 class OGRRawPoint
00047 {
00048 public:
00049 OGRRawPoint()
00050 {
00051 x = y = 0.0;
00052 }
00053 double x;
00054 double y;
00055 };
00056
00057 typedef struct GEOSGeom_t *GEOSGeom;
00058
00059
00060
00061
00062
00080 class CPL_DLL OGRGeometry
00081 {
00082 private:
00083 OGRSpatialReference * poSRS;
00084
00085 protected:
00086 int nCoordDimension;
00087
00088 public:
00089 OGRGeometry();
00090 virtual ~OGRGeometry();
00091
00092
00093 virtual int getDimension() const = 0;
00094 virtual int getCoordinateDimension() const;
00095 virtual OGRBoolean IsEmpty() const = 0;
00096 virtual OGRBoolean IsValid() const;
00097 virtual OGRBoolean IsSimple() const;
00098 virtual OGRBoolean IsRing() const;
00099 virtual void empty() = 0;
00100 virtual OGRGeometry *clone() const = 0;
00101 virtual void getEnvelope( OGREnvelope * psEnvelope ) const = 0;
00102
00103
00104 virtual int WkbSize() const = 0;
00105 virtual OGRErr importFromWkb( unsigned char *, int=-1 )=0;
00106 virtual OGRErr exportToWkb( OGRwkbByteOrder, unsigned char * ) const = 0;
00107 virtual OGRErr importFromWkt( char ** ppszInput ) = 0;
00108 virtual OGRErr exportToWkt( char ** ppszDstText ) const = 0;
00109
00110
00111 virtual OGRwkbGeometryType getGeometryType() const = 0;
00112 virtual const char *getGeometryName() const = 0;
00113 virtual void dumpReadable( FILE *, const char * = NULL, char** papszOptions = NULL ) const;
00114 virtual void flattenTo2D() = 0;
00115 virtual char * exportToGML() const;
00116 virtual char * exportToKML() const;
00117 virtual char * exportToJson() const;
00118 virtual GEOSGeom exportToGEOS() const;
00119 virtual void closeRings();
00120
00121 virtual void setCoordinateDimension( int nDimension );
00122
00123 void assignSpatialReference( OGRSpatialReference * poSR );
00124 OGRSpatialReference *getSpatialReference( void ) const { return poSRS; }
00125
00126 virtual OGRErr transform( OGRCoordinateTransformation *poCT ) = 0;
00127 OGRErr transformTo( OGRSpatialReference *poSR );
00128
00129 virtual void segmentize(double dfMaxLength);
00130
00131
00132 virtual OGRBoolean Intersects( OGRGeometry * ) const;
00133 virtual OGRBoolean Equals( OGRGeometry * ) const = 0;
00134 virtual OGRBoolean Disjoint( const OGRGeometry * ) const;
00135 virtual OGRBoolean Touches( const OGRGeometry * ) const;
00136 virtual OGRBoolean Crosses( const OGRGeometry * ) const;
00137 virtual OGRBoolean Within( const OGRGeometry * ) const;
00138 virtual OGRBoolean Contains( const OGRGeometry * ) const;
00139 virtual OGRBoolean Overlaps( const OGRGeometry * ) const;
00140
00141
00142 virtual OGRGeometry *getBoundary() const;
00143 virtual double Distance( const OGRGeometry * ) const;
00144 virtual OGRGeometry *ConvexHull() const;
00145 virtual OGRGeometry *Buffer( double dfDist, int nQuadSegs = 30 ) const;
00146 virtual OGRGeometry *Intersection( const OGRGeometry *) const;
00147 virtual OGRGeometry *Union( const OGRGeometry * ) const;
00148 virtual OGRGeometry *Difference( const OGRGeometry * ) const;
00149 virtual OGRGeometry *SymmetricDifference( const OGRGeometry * ) const;
00150
00151
00152 OGRBoolean Intersect( OGRGeometry * ) const;
00153 OGRBoolean Equal( OGRGeometry * ) const;
00154
00155
00156 static int bGenerate_DB2_V72_BYTE_ORDER;
00157 };
00158
00159
00160
00161
00162
00169 class CPL_DLL OGRPoint : public OGRGeometry
00170 {
00171 double x;
00172 double y;
00173 double z;
00174
00175 public:
00176 OGRPoint();
00177 OGRPoint( double x, double y );
00178 OGRPoint( double x, double y, double z );
00179 virtual ~OGRPoint();
00180
00181
00182 virtual int WkbSize() const;
00183 virtual OGRErr importFromWkb( unsigned char *, int=-1 );
00184 virtual OGRErr exportToWkb( OGRwkbByteOrder, unsigned char * ) const;
00185 virtual OGRErr importFromWkt( char ** );
00186 virtual OGRErr exportToWkt( char ** ppszDstText ) const;
00187
00188
00189 virtual int getDimension() const;
00190 virtual OGRGeometry *clone() const;
00191 virtual void empty();
00192 virtual void getEnvelope( OGREnvelope * psEnvelope ) const;
00193 virtual OGRBoolean IsEmpty() const;
00194
00195
00196 double getX() const { return x; }
00197 double getY() const { return y; }
00198 double getZ() const { return z; }
00199
00200
00201 virtual void setCoordinateDimension( int nDimension );
00202 void setX( double xIn ) { x = xIn; if (nCoordDimension == 0) nCoordDimension = 2; }
00203 void setY( double yIn ) { y = yIn; if (nCoordDimension == 0) nCoordDimension = 2; }
00204 void setZ( double zIn ) { z = zIn; nCoordDimension=3; }
00205
00206
00207 virtual OGRBoolean Equals( OGRGeometry * ) const;
00208
00209
00210 virtual const char *getGeometryName() const;
00211 virtual OGRwkbGeometryType getGeometryType() const;
00212 virtual OGRErr transform( OGRCoordinateTransformation *poCT );
00213 virtual void flattenTo2D();
00214 };
00215
00216
00217
00218
00219
00224 class CPL_DLL OGRCurve : public OGRGeometry
00225 {
00226 public:
00227 OGRCurve();
00228 virtual ~OGRCurve();
00229
00230 virtual double get_Length() const = 0;
00231 virtual void StartPoint(OGRPoint *) const = 0;
00232 virtual void EndPoint(OGRPoint *) const = 0;
00233 virtual int get_IsClosed() const;
00234 virtual void Value( double, OGRPoint * ) const = 0;
00235
00236 };
00237
00238
00239
00240
00241
00246 class CPL_DLL OGRLineString : public OGRCurve
00247 {
00248 protected:
00249 int nPointCount;
00250 OGRRawPoint *paoPoints;
00251 double *padfZ;
00252
00253 void Make3D();
00254 void Make2D();
00255
00256 public:
00257 OGRLineString();
00258 virtual ~OGRLineString();
00259
00260
00261 virtual int WkbSize() const;
00262 virtual OGRErr importFromWkb( unsigned char *, int = -1 );
00263 virtual OGRErr exportToWkb( OGRwkbByteOrder, unsigned char * ) const;
00264 virtual OGRErr importFromWkt( char ** );
00265 virtual OGRErr exportToWkt( char ** ppszDstText ) const;
00266
00267
00268 virtual int getDimension() const;
00269 virtual OGRGeometry *clone() const;
00270 virtual void empty();
00271 virtual void getEnvelope( OGREnvelope * psEnvelope ) const;
00272 virtual OGRBoolean IsEmpty() const;
00273
00274
00275 virtual double get_Length() const;
00276 virtual void StartPoint(OGRPoint *) const;
00277 virtual void EndPoint(OGRPoint *) const;
00278 virtual void Value( double, OGRPoint * ) const;
00279
00280
00281 int getNumPoints() const { return nPointCount; }
00282 void getPoint( int, OGRPoint * ) const;
00283 double getX( int i ) const { return paoPoints[i].x; }
00284 double getY( int i ) const { return paoPoints[i].y; }
00285 double getZ( int i ) const;
00286
00287
00288 virtual OGRBoolean Equals( OGRGeometry * ) const;
00289
00290
00291 virtual void setCoordinateDimension( int nDimension );
00292 void setNumPoints( int );
00293 void setPoint( int, OGRPoint * );
00294 void setPoint( int, double, double );
00295 void setPoint( int, double, double, double );
00296 void setPoints( int, OGRRawPoint *, double * = NULL );
00297 void setPoints( int, double * padfX, double * padfY,
00298 double *padfZ = NULL );
00299 void addPoint( OGRPoint * );
00300 void addPoint( double, double );
00301 void addPoint( double, double, double );
00302
00303 void getPoints( OGRRawPoint *, double * = NULL ) const;
00304
00305 void addSubLineString( const OGRLineString *,
00306 int nStartVertex = 0, int nEndVertex = -1 );
00307
00308
00309 virtual OGRwkbGeometryType getGeometryType() const;
00310 virtual const char *getGeometryName() const;
00311 virtual OGRErr transform( OGRCoordinateTransformation *poCT );
00312 virtual void flattenTo2D();
00313 virtual void segmentize(double dfMaxLength);
00314 };
00315
00316
00317
00318
00319
00338 class CPL_DLL OGRLinearRing : public OGRLineString
00339 {
00340 private:
00341 friend class OGRPolygon;
00342
00343
00344 virtual int _WkbSize( int b3D ) const;
00345 virtual OGRErr _importFromWkb( OGRwkbByteOrder, int b3D,
00346 unsigned char *, int=-1 );
00347 virtual OGRErr _exportToWkb( OGRwkbByteOrder, int b3D,
00348 unsigned char * ) const;
00349
00350 public:
00351 OGRLinearRing();
00352 OGRLinearRing( OGRLinearRing * );
00353 ~OGRLinearRing();
00354
00355
00356 virtual const char *getGeometryName() const;
00357 virtual OGRGeometry *clone() const;
00358 virtual int isClockwise() const;
00359 virtual void reverseWindingOrder();
00360 virtual void closeRings();
00361 virtual double get_Area() const;
00362 OGRBoolean isPointInRing(const OGRPoint* pt, int bTestEnvelope = TRUE) const;
00363 OGRBoolean isPointOnRingBoundary(const OGRPoint* pt, int bTestEnvelope = TRUE) const;
00364
00365
00366
00367
00368 virtual int WkbSize() const;
00369 virtual OGRErr importFromWkb( unsigned char *, int=-1 );
00370 virtual OGRErr exportToWkb( OGRwkbByteOrder, unsigned char * ) const;
00371 };
00372
00373
00374
00375
00376
00381 class CPL_DLL OGRSurface : public OGRGeometry
00382 {
00383 public:
00384 virtual double get_Area() const = 0;
00385 virtual OGRErr Centroid( OGRPoint * poPoint ) const = 0;
00386 virtual OGRErr PointOnSurface( OGRPoint * poPoint ) const = 0;
00387 };
00388
00389
00390
00391
00392
00402 class CPL_DLL OGRPolygon : public OGRSurface
00403 {
00404 int nRingCount;
00405 OGRLinearRing **papoRings;
00406
00407 public:
00408 OGRPolygon();
00409 virtual ~OGRPolygon();
00410
00411
00412 virtual const char *getGeometryName() const;
00413 virtual OGRwkbGeometryType getGeometryType() const;
00414 virtual OGRGeometry *clone() const;
00415 virtual void empty();
00416 virtual OGRErr transform( OGRCoordinateTransformation *poCT );
00417 virtual void flattenTo2D();
00418 virtual OGRBoolean IsEmpty() const;
00419 virtual void segmentize(double dfMaxLength);
00420
00421
00422 virtual double get_Area() const;
00423 virtual int Centroid( OGRPoint * poPoint ) const;
00424 virtual int PointOnSurface( OGRPoint * poPoint ) const;
00425
00426
00427 virtual int WkbSize() const;
00428 virtual OGRErr importFromWkb( unsigned char *, int = -1 );
00429 virtual OGRErr exportToWkb( OGRwkbByteOrder, unsigned char * ) const;
00430 virtual OGRErr importFromWkt( char ** );
00431 virtual OGRErr exportToWkt( char ** ppszDstText ) const;
00432
00433
00434 virtual int getDimension() const;
00435 virtual void getEnvelope( OGREnvelope * psEnvelope ) const;
00436
00437
00438 virtual OGRBoolean Equals( OGRGeometry * ) const;
00439
00440
00441 virtual void setCoordinateDimension( int nDimension );
00442
00443 void addRing( OGRLinearRing * );
00444 void addRingDirectly( OGRLinearRing * );
00445
00446 OGRLinearRing *getExteriorRing();
00447 const OGRLinearRing *getExteriorRing() const;
00448 int getNumInteriorRings() const;
00449 OGRLinearRing *getInteriorRing( int );
00450 const OGRLinearRing *getInteriorRing( int ) const;
00451
00452 OGRBoolean IsPointOnSurface( const OGRPoint * ) const;
00453
00454 virtual void closeRings();
00455 };
00456
00457
00458
00459
00460
00468 class CPL_DLL OGRGeometryCollection : public OGRGeometry
00469 {
00470 int nGeomCount;
00471 OGRGeometry **papoGeoms;
00472
00473 public:
00474 OGRGeometryCollection();
00475 virtual ~OGRGeometryCollection();
00476
00477
00478 virtual const char *getGeometryName() const;
00479 virtual OGRwkbGeometryType getGeometryType() const;
00480 virtual OGRGeometry *clone() const;
00481 virtual void empty();
00482 virtual OGRErr transform( OGRCoordinateTransformation *poCT );
00483 virtual void flattenTo2D();
00484 virtual OGRBoolean IsEmpty() const;
00485 virtual void segmentize(double dfMaxLength);
00486
00487
00488 virtual int WkbSize() const;
00489 virtual OGRErr importFromWkb( unsigned char *, int = -1 );
00490 virtual OGRErr exportToWkb( OGRwkbByteOrder, unsigned char * ) const;
00491 virtual OGRErr importFromWkt( char ** );
00492 virtual OGRErr exportToWkt( char ** ppszDstText ) const;
00493
00494 virtual double get_Area() const;
00495
00496
00497 virtual int getDimension() const;
00498 virtual void getEnvelope( OGREnvelope * psEnvelope ) const;
00499
00500
00501 int getNumGeometries() const;
00502 OGRGeometry *getGeometryRef( int );
00503 const OGRGeometry *getGeometryRef( int ) const;
00504
00505
00506 virtual OGRBoolean Equals( OGRGeometry * ) const;
00507
00508
00509 virtual void setCoordinateDimension( int nDimension );
00510 virtual OGRErr addGeometry( const OGRGeometry * );
00511 virtual OGRErr addGeometryDirectly( OGRGeometry * );
00512 virtual OGRErr removeGeometry( int iIndex, int bDelete = TRUE );
00513
00514 void closeRings();
00515 };
00516
00517
00518
00519
00520
00528 class CPL_DLL OGRMultiPolygon : public OGRGeometryCollection
00529 {
00530 public:
00531 OGRMultiPolygon();
00532
00533 virtual const char *getGeometryName() const;
00534 virtual OGRwkbGeometryType getGeometryType() const;
00535 virtual OGRGeometry *clone() const;
00536 virtual OGRErr importFromWkt( char ** );
00537 virtual OGRErr exportToWkt( char ** ) const;
00538
00539
00540 virtual OGRErr addGeometryDirectly( OGRGeometry * );
00541
00542 virtual double get_Area() const;
00543 };
00544
00545
00546
00547
00548
00553 class CPL_DLL OGRMultiPoint : public OGRGeometryCollection
00554 {
00555 private:
00556 OGRErr importFromWkt_Bracketed( char ** );
00557
00558 public:
00559 OGRMultiPoint();
00560
00561 virtual const char *getGeometryName() const;
00562 virtual OGRwkbGeometryType getGeometryType() const;
00563 virtual OGRGeometry *clone() const;
00564 virtual OGRErr importFromWkt( char ** );
00565 virtual OGRErr exportToWkt( char ** ) const;
00566
00567
00568 virtual OGRErr addGeometryDirectly( OGRGeometry * );
00569 };
00570
00571
00572
00573
00574
00579 class CPL_DLL OGRMultiLineString : public OGRGeometryCollection
00580 {
00581 public:
00582 OGRMultiLineString();
00583 ~OGRMultiLineString();
00584
00585 virtual const char *getGeometryName() const;
00586 virtual OGRwkbGeometryType getGeometryType() const;
00587 virtual OGRGeometry *clone() const;
00588 virtual OGRErr importFromWkt( char ** );
00589 virtual OGRErr exportToWkt( char ** ) const;
00590
00591
00592 virtual OGRErr addGeometryDirectly( OGRGeometry * );
00593 };
00594
00595
00596
00597
00598
00599
00604 class CPL_DLL OGRGeometryFactory
00605 {
00606 public:
00607 static OGRErr createFromWkb( unsigned char *, OGRSpatialReference *,
00608 OGRGeometry **, int = -1 );
00609 static OGRErr createFromWkt( char **, OGRSpatialReference *,
00610 OGRGeometry ** );
00611 static OGRErr createFromFgf( unsigned char *, OGRSpatialReference *,
00612 OGRGeometry **, int = -1, int * = NULL );
00613 static OGRGeometry *createFromGML( const char * );
00614 static OGRGeometry *createFromGEOS( GEOSGeom );
00615
00616 static void destroyGeometry( OGRGeometry * );
00617 static OGRGeometry *createGeometry( OGRwkbGeometryType );
00618
00619 static OGRGeometry * forceToPolygon( OGRGeometry * );
00620 static OGRGeometry * forceToMultiPolygon( OGRGeometry * );
00621 static OGRGeometry * forceToMultiPoint( OGRGeometry * );
00622 static OGRGeometry * forceToMultiLineString( OGRGeometry * );
00623
00624 static OGRGeometry * organizePolygons( OGRGeometry **papoPolygons,
00625 int nPolygonCount,
00626 int *pbResultValidGeometry,
00627 const char **papszOptions = NULL);
00628
00629 static void *getGEOSGeometryFactory();
00630
00631 static int haveGEOS();
00632
00633 static OGRGeometry* transformWithOptions( const OGRGeometry* poSrcGeom,
00634 OGRCoordinateTransformation *poCT,
00635 char** papszOptions );
00636
00637 static OGRGeometry*
00638 approximateArcAngles( double dfX, double dfY, double dfZ,
00639 double dfPrimaryRadius, double dfSecondaryAxis,
00640 double dfRotation,
00641 double dfStartAngle, double dfEndAngle,
00642 double dfMaxAngleStepSizeDegrees );
00643 };
00644
00645 #endif