OGR: ogr_geometry.h Source File

- Main Page
- Related Pages
- Classes
- Files
- Directories

- File List
- File Members

# ogr_geometry.h

Go to the documentation of this file.

    00001 /******************************************************************************
    00002  * $Id: ogr_geometry.h 15517 2008-10-11 18:34:03Z rouault $
    00003  *
    00004  * Project:  OpenGIS Simple Features Reference Implementation
    00005  * Purpose:  Classes for manipulating simple features that is not specific
    00006  *           to a particular interface technology.
    00007  * Author:   Frank Warmerdam, warmerdam@pobox.com
    00008  *
    00009  ******************************************************************************
    00010  * Copyright (c) 1999, Frank Warmerdam
    00011  *
    00012  * Permission is hereby granted, free of charge, to any person obtaining a
    00013  * copy of this software and associated documentation files (the "Software"),
    00014  * to deal in the Software without restriction, including without limitation
    00015  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
    00016  * and/or sell copies of the Software, and to permit persons to whom the
    00017  * Software is furnished to do so, subject to the following conditions:
    00018  *
    00019  * The above copyright notice and this permission notice shall be included
    00020  * in all copies or substantial portions of the Software.
    00021  *
    00022  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
    00023  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    00024  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
    00025  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    00026  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    00027  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
    00028  * DEALINGS IN THE SOFTWARE.
    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 /*                             OGRGeometry                              */
    00061 /************************************************************************/
    00062
    00072 class CPL_DLL OGRGeometry
    00073 {
    00074   private:
    00075     OGRSpatialReference * poSRS;                // may be NULL
    00076
    00077   protected:
    00078     int                   nCoordDimension;
    00079
    00080   public:
    00081                 OGRGeometry();
    00082     virtual     ~OGRGeometry();
    00083
    00084     // standard IGeometry
    00085     virtual int getDimension() const = 0;
    00086     virtual int getCoordinateDimension() const;
    00087     virtual OGRBoolean  IsEmpty() const = 0;
    00088     virtual OGRBoolean  IsValid() const;
    00089     virtual OGRBoolean  IsSimple() const;
    00090     virtual OGRBoolean  IsRing() const;
    00091     virtual void        empty() = 0;
    00092     virtual OGRGeometry *clone() const = 0;
    00093     virtual void getEnvelope( OGREnvelope * psEnvelope ) const = 0;
    00094
    00095     // IWks Interface
    00096     virtual int WkbSize() const = 0;
    00097     virtual OGRErr importFromWkb( unsigned char *, int=-1 )=0;
    00098     virtual OGRErr exportToWkb( OGRwkbByteOrder, unsigned char * ) const = 0;
    00099     virtual OGRErr importFromWkt( char ** ppszInput ) = 0;
    00100     virtual OGRErr exportToWkt( char ** ppszDstText ) const = 0;
    00101
    00102     // non-standard
    00103     virtual OGRwkbGeometryType getGeometryType() const = 0;
    00104     virtual const char *getGeometryName() const = 0;
    00105     virtual void   dumpReadable( FILE *, const char * = NULL, char** papszOptions = NULL ) const;
    00106     virtual void   flattenTo2D() = 0;
    00107     virtual char * exportToGML() const;
    00108         virtual char * exportToKML() const;
    00109     virtual char * exportToJson() const;
    00110     virtual GEOSGeom exportToGEOS() const;
    00111     virtual void closeRings();
    00112
    00113     virtual void setCoordinateDimension( int nDimension );
    00114
    00115     void    assignSpatialReference( OGRSpatialReference * poSR );
    00116     OGRSpatialReference *getSpatialReference( void ) const { return poSRS; }
    00117
    00118     virtual OGRErr  transform( OGRCoordinateTransformation *poCT ) = 0;
    00119     OGRErr  transformTo( OGRSpatialReference *poSR );
    00120
    00121     virtual void segmentize(double dfMaxLength);
    00122
    00123     // ISpatialRelation
    00124     virtual OGRBoolean  Intersects( OGRGeometry * ) const;
    00125     virtual OGRBoolean  Equals( OGRGeometry * ) const = 0;
    00126     virtual OGRBoolean  Disjoint( const OGRGeometry * ) const;
    00127     virtual OGRBoolean  Touches( const OGRGeometry * ) const;
    00128     virtual OGRBoolean  Crosses( const OGRGeometry * ) const;
    00129     virtual OGRBoolean  Within( const OGRGeometry * ) const;
    00130     virtual OGRBoolean  Contains( const OGRGeometry * ) const;
    00131     virtual OGRBoolean  Overlaps( const OGRGeometry * ) const;
    00132 //    virtual OGRBoolean  Relate( const OGRGeometry *, const char * ) const;
    00133
    00134     virtual OGRGeometry *getBoundary() const;
    00135     virtual double  Distance( const OGRGeometry * ) const;
    00136     virtual OGRGeometry *ConvexHull() const;
    00137     virtual OGRGeometry *Buffer( double dfDist, int nQuadSegs = 30 ) const;
    00138     virtual OGRGeometry *Intersection( const OGRGeometry *) const;
    00139     virtual OGRGeometry *Union( const OGRGeometry * ) const;
    00140     virtual OGRGeometry *Difference( const OGRGeometry * ) const;
    00141     virtual OGRGeometry *SymmetricDifference( const OGRGeometry * ) const;
    00142
    00143     // backward compatibility methods.
    00144     OGRBoolean  Intersect( OGRGeometry * ) const;
    00145     OGRBoolean  Equal( OGRGeometry * ) const;
    00146
    00147     // Special HACK for DB2 7.2 support
    00148     static int bGenerate_DB2_V72_BYTE_ORDER;
    00149 };
    00150
    00151 /************************************************************************/
    00152 /*                               OGRPoint                               */
    00153 /************************************************************************/
    00154
    00161 class CPL_DLL OGRPoint : public OGRGeometry
    00162 {
    00163     double      x;
    00164     double      y;
    00165     double      z;
    00166
    00167   public:
    00168                 OGRPoint();
    00169                 OGRPoint( double x, double y );
    00170                 OGRPoint( double x, double y, double z );
    00171     virtual     ~OGRPoint();
    00172
    00173     // IWks Interface
    00174     virtual int WkbSize() const;
    00175     virtual OGRErr importFromWkb( unsigned char *, int=-1 );
    00176     virtual OGRErr exportToWkb( OGRwkbByteOrder, unsigned char * ) const;
    00177     virtual OGRErr importFromWkt( char ** );
    00178     virtual OGRErr exportToWkt( char ** ppszDstText ) const;
    00179
    00180     // IGeometry
    00181     virtual int getDimension() const;
    00182     virtual OGRGeometry *clone() const;
    00183     virtual void empty();
    00184     virtual void getEnvelope( OGREnvelope * psEnvelope ) const;
    00185     virtual OGRBoolean  IsEmpty() const;
    00186
    00187     // IPoint
    00188     double      getX() const { return x; }
    00189     double      getY() const { return y; }
    00190     double      getZ() const { return z; }
    00191
    00192     // Non standard
    00193     virtual void setCoordinateDimension( int nDimension );
    00194     void        setX( double xIn ) { x = xIn; if (nCoordDimension == 0) nCoordDimension = 2; }
    00195     void        setY( double yIn ) { y = yIn; if (nCoordDimension == 0) nCoordDimension = 2; }
    00196     void        setZ( double zIn ) { z = zIn; nCoordDimension=3; }
    00197
    00198     // ISpatialRelation
    00199     virtual OGRBoolean  Equals( OGRGeometry * ) const;
    00200
    00201     // Non standard from OGRGeometry
    00202     virtual const char *getGeometryName() const;
    00203     virtual OGRwkbGeometryType getGeometryType() const;
    00204     virtual OGRErr  transform( OGRCoordinateTransformation *poCT );
    00205     virtual void flattenTo2D();
    00206 };
    00207
    00208 /************************************************************************/
    00209 /*                               OGRCurve                               */
    00210 /************************************************************************/
    00211
    00216 class CPL_DLL OGRCurve : public OGRGeometry
    00217 {
    00218   public:
    00219             OGRCurve();
    00220     virtual ~OGRCurve();
    00221     // ICurve methods
    00222     virtual double get_Length() const = 0;
    00223     virtual void StartPoint(OGRPoint *) const = 0;
    00224     virtual void EndPoint(OGRPoint *) const = 0;
    00225     virtual int  get_IsClosed() const;
    00226     virtual void Value( double, OGRPoint * ) const = 0;
    00227
    00228 };
    00229
    00230 /************************************************************************/
    00231 /*                            OGRLineString                             */
    00232 /************************************************************************/
    00233
    00238 class CPL_DLL OGRLineString : public OGRCurve
    00239 {
    00240   protected:
    00241     int         nPointCount;
    00242     OGRRawPoint *paoPoints;
    00243     double      *padfZ;
    00244
    00245     void        Make3D();
    00246     void        Make2D();
    00247
    00248   public:
    00249                 OGRLineString();
    00250     virtual     ~OGRLineString();
    00251
    00252     // IWks Interface
    00253     virtual int WkbSize() const;
    00254     virtual OGRErr importFromWkb( unsigned char *, int = -1 );
    00255     virtual OGRErr exportToWkb( OGRwkbByteOrder, unsigned char * ) const;
    00256     virtual OGRErr importFromWkt( char ** );
    00257     virtual OGRErr exportToWkt( char ** ppszDstText ) const;
    00258
    00259     // IGeometry interface
    00260     virtual int getDimension() const;
    00261     virtual OGRGeometry *clone() const;
    00262     virtual void empty();
    00263     virtual void getEnvelope( OGREnvelope * psEnvelope ) const;
    00264     virtual OGRBoolean  IsEmpty() const;
    00265
    00266     // ICurve methods
    00267     virtual double get_Length() const;
    00268     virtual void StartPoint(OGRPoint *) const;
    00269     virtual void EndPoint(OGRPoint *) const;
    00270     virtual void Value( double, OGRPoint * ) const;
    00271
    00272     // ILineString methods
    00273     int         getNumPoints() const { return nPointCount; }
    00274     void        getPoint( int, OGRPoint * ) const;
    00275     double      getX( int i ) const { return paoPoints[i].x; }
    00276     double      getY( int i ) const { return paoPoints[i].y; }
    00277     double      getZ( int i ) const;
    00278
    00279     // ISpatialRelation
    00280     virtual OGRBoolean  Equals( OGRGeometry * ) const;
    00281
    00282     // non standard.
    00283     virtual void setCoordinateDimension( int nDimension );
    00284     void        setNumPoints( int );
    00285     void        setPoint( int, OGRPoint * );
    00286     void        setPoint( int, double, double );
    00287     void        setPoint( int, double, double, double );
    00288     void        setPoints( int, OGRRawPoint *, double * = NULL );
    00289     void        setPoints( int, double * padfX, double * padfY,
    00290                            double *padfZ = NULL );
    00291     void        addPoint( OGRPoint * );
    00292     void        addPoint( double, double );
    00293     void        addPoint( double, double, double );
    00294
    00295     void        getPoints( OGRRawPoint *, double * = NULL ) const;
    00296
    00297     void        addSubLineString( const OGRLineString *,
    00298                                   int nStartVertex = 0, int nEndVertex = -1 );
    00299
    00300     // non-standard from OGRGeometry
    00301     virtual OGRwkbGeometryType getGeometryType() const;
    00302     virtual const char *getGeometryName() const;
    00303     virtual OGRErr  transform( OGRCoordinateTransformation *poCT );
    00304     virtual void flattenTo2D();
    00305     virtual void segmentize(double dfMaxLength);
    00306 };
    00307
    00308 /************************************************************************/
    00309 /*                            OGRLinearRing                             */
    00310 /************************************************************************/
    00311
    00330 class CPL_DLL OGRLinearRing : public OGRLineString
    00331 {
    00332   private:
    00333     friend class OGRPolygon;
    00334
    00335     // These are not IWks compatible ... just a convenience for OGRPolygon.
    00336     virtual int _WkbSize( int b3D ) const;
    00337     virtual OGRErr _importFromWkb( OGRwkbByteOrder, int b3D,
    00338                                    unsigned char *, int=-1 );
    00339     virtual OGRErr _exportToWkb( OGRwkbByteOrder, int b3D,
    00340                                  unsigned char * ) const;
    00341
    00342   public:
    00343                         OGRLinearRing();
    00344                         OGRLinearRing( OGRLinearRing * );
    00345                         ~OGRLinearRing();
    00346
    00347     // Non standard.
    00348     virtual const char *getGeometryName() const;
    00349     virtual OGRGeometry *clone() const;
    00350     virtual int isClockwise() const;
    00351     virtual void reverseWindingOrder();
    00352     virtual void closeRings();
    00353     virtual double get_Area() const;
    00354     OGRBoolean isPointInRing(const OGRPoint* pt, int bTestEnvelope = TRUE) const;
    00355     OGRBoolean isPointOnRingBoundary(const OGRPoint* pt, int bTestEnvelope = TRUE) const;
    00356
    00357     // IWks Interface - Note this isnt really a first class object
    00358     // for the purposes of WKB form.  These methods always fail since this
    00359     // object cant be serialized on its own.
    00360     virtual int WkbSize() const;
    00361     virtual OGRErr importFromWkb( unsigned char *, int=-1 );
    00362     virtual OGRErr exportToWkb( OGRwkbByteOrder, unsigned char * ) const;
    00363 };
    00364
    00365 /************************************************************************/
    00366 /*                              OGRSurface                              */
    00367 /************************************************************************/
    00368
    00373 class CPL_DLL OGRSurface : public OGRGeometry
    00374 {
    00375   public:
    00376     virtual double      get_Area() const = 0;
    00377     virtual OGRErr      Centroid( OGRPoint * poPoint ) const = 0;
    00378     virtual OGRErr      PointOnSurface( OGRPoint * poPoint ) const = 0;
    00379 };
    00380
    00381 /************************************************************************/
    00382 /*                              OGRPolygon                              */
    00383 /************************************************************************/
    00384
    00394 class CPL_DLL OGRPolygon : public OGRSurface
    00395 {
    00396     int         nRingCount;
    00397     OGRLinearRing **papoRings;
    00398
    00399   public:
    00400                 OGRPolygon();
    00401     virtual     ~OGRPolygon();
    00402
    00403     // Non standard (OGRGeometry).
    00404     virtual const char *getGeometryName() const;
    00405     virtual OGRwkbGeometryType getGeometryType() const;
    00406     virtual OGRGeometry *clone() const;
    00407     virtual void empty();
    00408     virtual OGRErr  transform( OGRCoordinateTransformation *poCT );
    00409     virtual void flattenTo2D();
    00410     virtual OGRBoolean  IsEmpty() const;
    00411     virtual void segmentize(double dfMaxLength);
    00412
    00413     // ISurface Interface
    00414     virtual double      get_Area() const;
    00415     virtual int         Centroid( OGRPoint * poPoint ) const;
    00416     virtual int         PointOnSurface( OGRPoint * poPoint ) const;
    00417
    00418     // IWks Interface
    00419     virtual int WkbSize() const;
    00420     virtual OGRErr importFromWkb( unsigned char *, int = -1 );
    00421     virtual OGRErr exportToWkb( OGRwkbByteOrder, unsigned char * ) const;
    00422     virtual OGRErr importFromWkt( char ** );
    00423     virtual OGRErr exportToWkt( char ** ppszDstText ) const;
    00424
    00425     // IGeometry
    00426     virtual int getDimension() const;
    00427     virtual void getEnvelope( OGREnvelope * psEnvelope ) const;
    00428
    00429     // ISpatialRelation
    00430     virtual OGRBoolean  Equals( OGRGeometry * ) const;
    00431
    00432     // Non standard
    00433     virtual void setCoordinateDimension( int nDimension );
    00434
    00435     void        addRing( OGRLinearRing * );
    00436     void        addRingDirectly( OGRLinearRing * );
    00437
    00438     OGRLinearRing *getExteriorRing();
    00439     const OGRLinearRing *getExteriorRing() const;
    00440     int         getNumInteriorRings() const;
    00441     OGRLinearRing *getInteriorRing( int );
    00442     const OGRLinearRing *getInteriorRing( int ) const;
    00443
    00444     OGRBoolean IsPointOnSurface( const OGRPoint * ) const;
    00445
    00446     virtual void closeRings();
    00447 };
    00448
    00449 /************************************************************************/
    00450 /*                        OGRGeometryCollection                         */
    00451 /************************************************************************/
    00452
    00460 class CPL_DLL OGRGeometryCollection : public OGRGeometry
    00461 {
    00462     int         nGeomCount;
    00463     OGRGeometry **papoGeoms;
    00464
    00465   public:
    00466                 OGRGeometryCollection();
    00467     virtual     ~OGRGeometryCollection();
    00468
    00469     // Non standard (OGRGeometry).
    00470     virtual const char *getGeometryName() const;
    00471     virtual OGRwkbGeometryType getGeometryType() const;
    00472     virtual OGRGeometry *clone() const;
    00473     virtual void empty();
    00474     virtual OGRErr  transform( OGRCoordinateTransformation *poCT );
    00475     virtual void flattenTo2D();
    00476     virtual OGRBoolean  IsEmpty() const;
    00477     virtual void segmentize(double dfMaxLength);
    00478
    00479     // IWks Interface
    00480     virtual int WkbSize() const;
    00481     virtual OGRErr importFromWkb( unsigned char *, int = -1 );
    00482     virtual OGRErr exportToWkb( OGRwkbByteOrder, unsigned char * ) const;
    00483     virtual OGRErr importFromWkt( char ** );
    00484     virtual OGRErr exportToWkt( char ** ppszDstText ) const;
    00485
    00486     virtual double get_Area() const;
    00487
    00488     // IGeometry methods
    00489     virtual int getDimension() const;
    00490     virtual void getEnvelope( OGREnvelope * psEnvelope ) const;
    00491
    00492     // IGeometryCollection
    00493     int         getNumGeometries() const;
    00494     OGRGeometry *getGeometryRef( int );
    00495     const OGRGeometry *getGeometryRef( int ) const;
    00496
    00497     // ISpatialRelation
    00498     virtual OGRBoolean  Equals( OGRGeometry * ) const;
    00499
    00500     // Non standard
    00501     virtual void setCoordinateDimension( int nDimension );
    00502     virtual OGRErr addGeometry( const OGRGeometry * );
    00503     virtual OGRErr addGeometryDirectly( OGRGeometry * );
    00504     virtual OGRErr removeGeometry( int iIndex, int bDelete = TRUE );
    00505
    00506     void closeRings();
    00507 };
    00508
    00509 /************************************************************************/
    00510 /*                           OGRMultiPolygon                            */
    00511 /************************************************************************/
    00512
    00520 class CPL_DLL OGRMultiPolygon : public OGRGeometryCollection
    00521 {
    00522   public:
    00523             OGRMultiPolygon();
    00524     // Non standard (OGRGeometry).
    00525     virtual const char *getGeometryName() const;
    00526     virtual OGRwkbGeometryType getGeometryType() const;
    00527     virtual OGRGeometry *clone() const;
    00528     virtual OGRErr importFromWkt( char ** );
    00529     virtual OGRErr exportToWkt( char ** ) const;
    00530
    00531     // Non standard
    00532     virtual OGRErr addGeometryDirectly( OGRGeometry * );
    00533
    00534     virtual double  get_Area() const;
    00535 };
    00536
    00537 /************************************************************************/
    00538 /*                            OGRMultiPoint                             */
    00539 /************************************************************************/
    00540
    00545 class CPL_DLL OGRMultiPoint : public OGRGeometryCollection
    00546 {
    00547   private:
    00548     OGRErr  importFromWkt_Bracketed( char ** );
    00549
    00550   public:
    00551             OGRMultiPoint();
    00552     // Non standard (OGRGeometry).
    00553     virtual const char *getGeometryName() const;
    00554     virtual OGRwkbGeometryType getGeometryType() const;
    00555     virtual OGRGeometry *clone() const;
    00556     virtual OGRErr importFromWkt( char ** );
    00557     virtual OGRErr exportToWkt( char ** ) const;
    00558
    00559     // Non standard
    00560     virtual OGRErr addGeometryDirectly( OGRGeometry * );
    00561 };
    00562
    00563 /************************************************************************/
    00564 /*                          OGRMultiLineString                          */
    00565 /************************************************************************/
    00566
    00571 class CPL_DLL OGRMultiLineString : public OGRGeometryCollection
    00572 {
    00573   public:
    00574             OGRMultiLineString();
    00575             ~OGRMultiLineString();
    00576     // Non standard (OGRGeometry).
    00577     virtual const char *getGeometryName() const;
    00578     virtual OGRwkbGeometryType getGeometryType() const;
    00579     virtual OGRGeometry *clone() const;
    00580     virtual OGRErr importFromWkt( char ** );
    00581     virtual OGRErr exportToWkt( char ** ) const;
    00582
    00583     // Non standard
    00584     virtual OGRErr addGeometryDirectly( OGRGeometry * );
    00585 };
    00586
    00587
    00588 /************************************************************************/
    00589 /*                          OGRGeometryFactory                          */
    00590 /************************************************************************/
    00591
    00596 class CPL_DLL OGRGeometryFactory
    00597 {
    00598   public:
    00599     static OGRErr createFromWkb( unsigned char *, OGRSpatialReference *,
    00600                                  OGRGeometry **, int = -1 );
    00601     static OGRErr createFromWkt( char **, OGRSpatialReference *,
    00602                                  OGRGeometry ** );
    00603     static OGRErr createFromFgf( unsigned char *, OGRSpatialReference *,
    00604                                  OGRGeometry **, int = -1, int * = NULL );
    00605     static OGRGeometry *createFromGML( const char * );
    00606     static OGRGeometry *createFromGEOS( GEOSGeom );
    00607
    00608     static void   destroyGeometry( OGRGeometry * );
    00609     static OGRGeometry *createGeometry( OGRwkbGeometryType );
    00610
    00611     static OGRGeometry * forceToPolygon( OGRGeometry * );
    00612     static OGRGeometry * forceToMultiPolygon( OGRGeometry * );
    00613     static OGRGeometry * forceToMultiPoint( OGRGeometry * );
    00614     static OGRGeometry * forceToMultiLineString( OGRGeometry * );
    00615
    00616     static OGRGeometry * organizePolygons( OGRGeometry **papoPolygons,
    00617                                            int nPolygonCount,
    00618                                            int *pbResultValidGeometry,
    00619                                            const char **papszOptions = NULL);
    00620
    00621     static void *getGEOSGeometryFactory();
    00622
    00623     static int haveGEOS();
    00624
    00625 };
    00626
    00627 #endif /* ndef _OGR_GEOMETRY_H_INCLUDED */

Generated for GDAL by 1.5.9.