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

- File List
- File Members

# ogr_geometry.h

Go to the documentation of this file.

    00001 /******************************************************************************
    00002  * $Id: ogr_geometry.h 10646 2007-01-18 02:38:10Z warmerdam $
    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 { return 0; }
    00088     virtual OGRBoolean  IsSimple() const { return 1; }
    00089     virtual void        empty() = 0;
    00090     virtual OGRGeometry *clone() const = 0;
    00091     virtual void getEnvelope( OGREnvelope * psEnvelope ) const = 0;
    00092
    00093     // IWks Interface
    00094     virtual int WkbSize() const = 0;
    00095     virtual OGRErr importFromWkb( unsigned char *, int=-1 )=0;
    00096     virtual OGRErr exportToWkb( OGRwkbByteOrder, unsigned char * ) const = 0;
    00097     virtual OGRErr importFromWkt( char ** ppszInput ) = 0;
    00098     virtual OGRErr exportToWkt( char ** ppszDstText ) const = 0;
    00099
    00100     // non-standard
    00101     virtual OGRwkbGeometryType getGeometryType() const = 0;
    00102     virtual const char *getGeometryName() const = 0;
    00103     virtual void   dumpReadable( FILE *, const char * = NULL ) const;
    00104     virtual void   flattenTo2D() = 0;
    00105     virtual char * exportToGML() const;
    00106     virtual GEOSGeom exportToGEOS() const;
    00107     virtual void closeRings();
    00108
    00109     virtual void setCoordinateDimension( int nDimension );
    00110
    00111     void    assignSpatialReference( OGRSpatialReference * poSR );
    00112     OGRSpatialReference *getSpatialReference( void ) const { return poSRS; }
    00113
    00114     virtual OGRErr  transform( OGRCoordinateTransformation *poCT ) = 0;
    00115     OGRErr  transformTo( OGRSpatialReference *poSR );
    00116
    00117     // ISpatialRelation
    00118     virtual OGRBoolean  Intersects( OGRGeometry * ) const;
    00119     virtual OGRBoolean  Equals( OGRGeometry * ) const = 0;
    00120     virtual OGRBoolean  Disjoint( const OGRGeometry * ) const;
    00121     virtual OGRBoolean  Touches( const OGRGeometry * ) const;
    00122     virtual OGRBoolean  Crosses( const OGRGeometry * ) const;
    00123     virtual OGRBoolean  Within( const OGRGeometry * ) const;
    00124     virtual OGRBoolean  Contains( const OGRGeometry * ) const;
    00125     virtual OGRBoolean  Overlaps( const OGRGeometry * ) const;
    00126 //    virtual OGRBoolean  Relate( const OGRGeometry *, const char * ) const;
    00127
    00128     virtual OGRGeometry *getBoundary() const;
    00129     virtual double  Distance( const OGRGeometry * ) const;
    00130     virtual OGRGeometry *ConvexHull() const;
    00131     virtual OGRGeometry *Buffer( double dfDist, int nQuadSegs = 30 ) const;
    00132     virtual OGRGeometry *Intersection( const OGRGeometry *) const;
    00133     virtual OGRGeometry *Union( const OGRGeometry * ) const;
    00134     virtual OGRGeometry *Difference( const OGRGeometry * ) const;
    00135     virtual OGRGeometry *SymmetricDifference( const OGRGeometry * ) const;
    00136
    00137     // backward compatibility methods.
    00138     OGRBoolean  Intersect( OGRGeometry * ) const;
    00139     OGRBoolean  Equal( OGRGeometry * ) const;
    00140
    00141     // Special HACK for DB2 7.2 support
    00142     static int bGenerate_DB2_V72_BYTE_ORDER;
    00143 };
    00144
    00145 /************************************************************************/
    00146 /*                               OGRPoint                               */
    00147 /************************************************************************/
    00148
    00155 class CPL_DLL OGRPoint : public OGRGeometry
    00156 {
    00157     double      x;
    00158     double      y;
    00159     double      z;
    00160
    00161   public:
    00162                 OGRPoint();
    00163                 OGRPoint( double x, double y );
    00164                 OGRPoint( double x, double y, double z );
    00165     virtual     ~OGRPoint();
    00166
    00167     // IWks Interface
    00168     virtual int WkbSize() const;
    00169     virtual OGRErr importFromWkb( unsigned char *, int=-1 );
    00170     virtual OGRErr exportToWkb( OGRwkbByteOrder, unsigned char * ) const;
    00171     virtual OGRErr importFromWkt( char ** );
    00172     virtual OGRErr exportToWkt( char ** ppszDstText ) const;
    00173
    00174     // IGeometry
    00175     virtual int getDimension() const;
    00176     virtual OGRGeometry *clone() const;
    00177     virtual void empty();
    00178     virtual void getEnvelope( OGREnvelope * psEnvelope ) const;
    00179
    00180     // IPoint
    00181     double      getX() const { return x; }
    00182     double      getY() const { return y; }
    00183     double      getZ() const { return z; }
    00184
    00185     // Non standard
    00186     virtual void setCoordinateDimension( int nDimension );
    00187     void        setX( double xIn ) { x = xIn; }
    00188     void        setY( double yIn ) { y = yIn; }
    00189     void        setZ( double zIn ) { z = zIn; nCoordDimension=3; }
    00190
    00191     // ISpatialRelation
    00192     virtual OGRBoolean  Equals( OGRGeometry * ) const;
    00193
    00194     // Non standard from OGRGeometry
    00195     virtual const char *getGeometryName() const;
    00196     virtual OGRwkbGeometryType getGeometryType() const;
    00197     virtual OGRErr  transform( OGRCoordinateTransformation *poCT );
    00198     virtual void flattenTo2D();
    00199
    00200 };
    00201
    00202 /************************************************************************/
    00203 /*                               OGRCurve                               */
    00204 /************************************************************************/
    00205
    00210 class CPL_DLL OGRCurve : public OGRGeometry
    00211 {
    00212   public:
    00213             OGRCurve();
    00214     virtual ~OGRCurve();
    00215     // ICurve methods
    00216     virtual double get_Length() const = 0;
    00217     virtual void StartPoint(OGRPoint *) const = 0;
    00218     virtual void EndPoint(OGRPoint *) const = 0;
    00219     virtual int  get_IsClosed() const;
    00220     virtual void Value( double, OGRPoint * ) const = 0;
    00221
    00222 };
    00223
    00224 /************************************************************************/
    00225 /*                            OGRLineString                             */
    00226 /************************************************************************/
    00227
    00232 class CPL_DLL OGRLineString : public OGRCurve
    00233 {
    00234   protected:
    00235     int         nPointCount;
    00236     OGRRawPoint *paoPoints;
    00237     double      *padfZ;
    00238
    00239     void        Make3D();
    00240     void        Make2D();
    00241
    00242   public:
    00243                 OGRLineString();
    00244     virtual     ~OGRLineString();
    00245
    00246     // IWks Interface
    00247     virtual int WkbSize() const;
    00248     virtual OGRErr importFromWkb( unsigned char *, int = -1 );
    00249     virtual OGRErr exportToWkb( OGRwkbByteOrder, unsigned char * ) const;
    00250     virtual OGRErr importFromWkt( char ** );
    00251     virtual OGRErr exportToWkt( char ** ppszDstText ) const;
    00252
    00253     // IGeometry interface
    00254     virtual int getDimension() const;
    00255     virtual OGRGeometry *clone() const;
    00256     virtual void empty();
    00257     virtual void getEnvelope( OGREnvelope * psEnvelope ) const;
    00258
    00259     // ICurve methods
    00260     virtual double get_Length() const;
    00261     virtual void StartPoint(OGRPoint *) const;
    00262     virtual void EndPoint(OGRPoint *) const;
    00263     virtual void Value( double, OGRPoint * ) const;
    00264
    00265     // ILineString methods
    00266     int         getNumPoints() const { return nPointCount; }
    00267     void        getPoint( int, OGRPoint * ) const;
    00268     double      getX( int i ) const { return paoPoints[i].x; }
    00269     double      getY( int i ) const { return paoPoints[i].y; }
    00270     double      getZ( int i ) const;
    00271
    00272     // ISpatialRelation
    00273     virtual OGRBoolean  Equals( OGRGeometry * ) const;
    00274
    00275     // non standard.
    00276     virtual void setCoordinateDimension( int nDimension );
    00277     void        setNumPoints( int );
    00278     void        setPoint( int, OGRPoint * );
    00279     void        setPoint( int, double, double );
    00280     void        setPoint( int, double, double, double );
    00281     void        setPoints( int, OGRRawPoint *, double * = NULL );
    00282     void        setPoints( int, double * padfX, double * padfY,
    00283                            double *padfZ = NULL );
    00284     void        addPoint( OGRPoint * );
    00285     void        addPoint( double, double );
    00286     void        addPoint( double, double, double );
    00287
    00288     void        getPoints( OGRRawPoint *, double * = NULL ) const;
    00289
    00290     void        addSubLineString( const OGRLineString *,
    00291                                   int nStartVertex = 0, int nEndVertex = -1 );
    00292
    00293     // non-standard from OGRGeometry
    00294     virtual OGRwkbGeometryType getGeometryType() const;
    00295     virtual const char *getGeometryName() const;
    00296     virtual OGRErr  transform( OGRCoordinateTransformation *poCT );
    00297     virtual void flattenTo2D();
    00298
    00299 };
    00300
    00301 /************************************************************************/
    00302 /*                            OGRLinearRing                             */
    00303 /*                                                                      */
    00304 /*      This is an alias for OGRLineString for now.                     */
    00305 /************************************************************************/
    00306
    00315 class CPL_DLL OGRLinearRing : public OGRLineString
    00316 {
    00317   private:
    00318     friend class OGRPolygon;
    00319
    00320     // These are not IWks compatible ... just a convenience for OGRPolygon.
    00321     virtual int _WkbSize( int b3D ) const;
    00322     virtual OGRErr _importFromWkb( OGRwkbByteOrder, int b3D,
    00323                                    unsigned char *, int=-1 );
    00324     virtual OGRErr _exportToWkb( OGRwkbByteOrder, int b3D,
    00325                                  unsigned char * ) const;
    00326
    00327   public:
    00328                         OGRLinearRing();
    00329                         OGRLinearRing( OGRLinearRing * );
    00330                         ~OGRLinearRing();
    00331
    00332     // Non standard.
    00333     virtual const char *getGeometryName() const;
    00334     virtual OGRGeometry *clone() const;
    00335     virtual int isClockwise() const;
    00336     virtual void closeRings();
    00337     virtual double get_Area() const;
    00338     OGRBoolean isPointInRing(const OGRPoint* pt) const;
    00339
    00340     // IWks Interface - Note this isnt really a first class object
    00341     // for the purposes of WKB form.  These methods always fail since this
    00342     // object cant be serialized on its own.
    00343     virtual int WkbSize() const;
    00344     virtual OGRErr importFromWkb( unsigned char *, int=-1 );
    00345     virtual OGRErr exportToWkb( OGRwkbByteOrder, unsigned char * ) const;
    00346 };
    00347
    00348 /************************************************************************/
    00349 /*                              OGRSurface                              */
    00350 /************************************************************************/
    00351
    00356 class CPL_DLL OGRSurface : public OGRGeometry
    00357 {
    00358   public:
    00359     virtual double      get_Area() const = 0;
    00360     virtual OGRErr      Centroid( OGRPoint * poPoint ) const = 0;
    00361     virtual OGRErr      PointOnSurface( OGRPoint * poPoint ) const = 0;
    00362 };
    00363
    00364 /************************************************************************/
    00365 /*                              OGRPolygon                              */
    00366 /************************************************************************/
    00367
    00377 class CPL_DLL OGRPolygon : public OGRSurface
    00378 {
    00379     int         nRingCount;
    00380     OGRLinearRing **papoRings;
    00381
    00382   public:
    00383                 OGRPolygon();
    00384     virtual     ~OGRPolygon();
    00385
    00386     // Non standard (OGRGeometry).
    00387     virtual const char *getGeometryName() const;
    00388     virtual OGRwkbGeometryType getGeometryType() const;
    00389     virtual OGRGeometry *clone() const;
    00390     virtual void empty();
    00391     virtual OGRErr  transform( OGRCoordinateTransformation *poCT );
    00392     virtual void flattenTo2D();
    00393
    00394     // ISurface Interface
    00395     virtual double      get_Area() const;
    00396     virtual int         Centroid( OGRPoint * poPoint ) const;
    00397     virtual int         PointOnSurface( OGRPoint * poPoint ) const;
    00398
    00399     // IWks Interface
    00400     virtual int WkbSize() const;
    00401     virtual OGRErr importFromWkb( unsigned char *, int = -1 );
    00402     virtual OGRErr exportToWkb( OGRwkbByteOrder, unsigned char * ) const;
    00403     virtual OGRErr importFromWkt( char ** );
    00404     virtual OGRErr exportToWkt( char ** ppszDstText ) const;
    00405
    00406     // IGeometry
    00407     virtual int getDimension() const;
    00408     virtual void getEnvelope( OGREnvelope * psEnvelope ) const;
    00409
    00410     // ISpatialRelation
    00411     virtual OGRBoolean  Equals( OGRGeometry * ) const;
    00412
    00413     // Non standard
    00414     virtual void setCoordinateDimension( int nDimension );
    00415
    00416     void        addRing( OGRLinearRing * );
    00417     void        addRingDirectly( OGRLinearRing * );
    00418
    00419     OGRLinearRing *getExteriorRing();
    00420     const OGRLinearRing *getExteriorRing() const;
    00421     int         getNumInteriorRings() const;
    00422     OGRLinearRing *getInteriorRing( int );
    00423     const OGRLinearRing *getInteriorRing( int ) const;
    00424
    00425     OGRBoolean IsPointOnSurface( const OGRPoint * ) const;
    00426
    00427     virtual void closeRings();
    00428 };
    00429
    00430 /************************************************************************/
    00431 /*                        OGRGeometryCollection                         */
    00432 /************************************************************************/
    00433
    00441 class CPL_DLL OGRGeometryCollection : public OGRGeometry
    00442 {
    00443     int         nGeomCount;
    00444     OGRGeometry **papoGeoms;
    00445
    00446     int         nCoordinateDimension;
    00447
    00448   public:
    00449                 OGRGeometryCollection();
    00450     virtual     ~OGRGeometryCollection();
    00451
    00452     // Non standard (OGRGeometry).
    00453     virtual const char *getGeometryName() const;
    00454     virtual OGRwkbGeometryType getGeometryType() const;
    00455     virtual OGRGeometry *clone() const;
    00456     virtual void empty();
    00457     virtual OGRErr  transform( OGRCoordinateTransformation *poCT );
    00458     virtual void flattenTo2D();
    00459
    00460     // IWks Interface
    00461     virtual int WkbSize() const;
    00462     virtual OGRErr importFromWkb( unsigned char *, int = -1 );
    00463     virtual OGRErr exportToWkb( OGRwkbByteOrder, unsigned char * ) const;
    00464     virtual OGRErr importFromWkt( char ** );
    00465     virtual OGRErr exportToWkt( char ** ppszDstText ) const;
    00466
    00467     // IGeometry methods
    00468     virtual int getDimension() const;
    00469     virtual void getEnvelope( OGREnvelope * psEnvelope ) const;
    00470
    00471     // IGeometryCollection
    00472     int         getNumGeometries() const;
    00473     OGRGeometry *getGeometryRef( int );
    00474     const OGRGeometry *getGeometryRef( int ) const;
    00475
    00476     // ISpatialRelation
    00477     virtual OGRBoolean  Equals( OGRGeometry * ) const;
    00478
    00479     // Non standard
    00480     virtual void setCoordinateDimension( int nDimension );
    00481     virtual OGRErr addGeometry( const OGRGeometry * );
    00482     virtual OGRErr addGeometryDirectly( OGRGeometry * );
    00483     virtual OGRErr removeGeometry( int iIndex, int bDelete = TRUE );
    00484
    00485     void closeRings();
    00486 };
    00487
    00488 /************************************************************************/
    00489 /*                           OGRMultiPolygon                            */
    00490 /************************************************************************/
    00491
    00499 class CPL_DLL OGRMultiPolygon : public OGRGeometryCollection
    00500 {
    00501   public:
    00502             OGRMultiPolygon();
    00503     // Non standard (OGRGeometry).
    00504     virtual const char *getGeometryName() const;
    00505     virtual OGRwkbGeometryType getGeometryType() const;
    00506     virtual OGRGeometry *clone() const;
    00507     virtual OGRErr importFromWkt( char ** );
    00508     virtual OGRErr exportToWkt( char ** ) const;
    00509
    00510     // Non standard
    00511     virtual OGRErr addGeometryDirectly( OGRGeometry * );
    00512
    00513     double  get_Area() const;
    00514 };
    00515
    00516 /************************************************************************/
    00517 /*                            OGRMultiPoint                             */
    00518 /************************************************************************/
    00519
    00524 class CPL_DLL OGRMultiPoint : public OGRGeometryCollection
    00525 {
    00526   private:
    00527     OGRErr  importFromWkt_Bracketed( char ** );
    00528
    00529   public:
    00530             OGRMultiPoint();
    00531     // Non standard (OGRGeometry).
    00532     virtual const char *getGeometryName() const;
    00533     virtual OGRwkbGeometryType getGeometryType() const;
    00534     virtual OGRGeometry *clone() const;
    00535     virtual OGRErr importFromWkt( char ** );
    00536     virtual OGRErr exportToWkt( char ** ) const;
    00537
    00538     // Non standard
    00539     virtual OGRErr addGeometryDirectly( OGRGeometry * );
    00540 };
    00541
    00542 /************************************************************************/
    00543 /*                          OGRMultiLineString                          */
    00544 /************************************************************************/
    00545
    00550 class CPL_DLL OGRMultiLineString : public OGRGeometryCollection
    00551 {
    00552   public:
    00553             OGRMultiLineString();
    00554             ~OGRMultiLineString();
    00555     // Non standard (OGRGeometry).
    00556     virtual const char *getGeometryName() const;
    00557     virtual OGRwkbGeometryType getGeometryType() const;
    00558     virtual OGRGeometry *clone() const;
    00559     virtual OGRErr importFromWkt( char ** );
    00560     virtual OGRErr exportToWkt( char ** ) const;
    00561
    00562     // Non standard
    00563     virtual OGRErr addGeometryDirectly( OGRGeometry * );
    00564 };
    00565
    00566
    00567 /************************************************************************/
    00568 /*                          OGRGeometryFactory                          */
    00569 /************************************************************************/
    00570
    00575 class CPL_DLL OGRGeometryFactory
    00576 {
    00577   public:
    00578     static OGRErr createFromWkb( unsigned char *, OGRSpatialReference *,
    00579                                  OGRGeometry **, int = -1 );
    00580     static OGRErr createFromWkt( char **, OGRSpatialReference *,
    00581                                  OGRGeometry ** );
    00582     static OGRGeometry *createFromGML( const char * );
    00583     static OGRGeometry *createFromGEOS( GEOSGeom );
    00584
    00585     static void   destroyGeometry( OGRGeometry * );
    00586     static OGRGeometry *createGeometry( OGRwkbGeometryType );
    00587
    00588     static OGRGeometry * forceToPolygon( OGRGeometry * );
    00589     static OGRGeometry * forceToMultiPolygon( OGRGeometry * );
    00590     static OGRGeometry * forceToMultiPoint( OGRGeometry * );
    00591     static OGRGeometry * forceToMultiLineString( OGRGeometry * );
    00592
    00593     static void *getGEOSGeometryFactory();
    00594
    00595     static int haveGEOS();
    00596
    00597 };
    00598
    00599 #endif /* ndef _OGR_GEOMETRY_H_INCLUDED */

Generated for GDAL by 1.5.1.