- 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 13316 2007-12-11 04:47:57Z 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;
    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 ) 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     // ISpatialRelation
    00122     virtual OGRBoolean  Intersects( OGRGeometry * ) const;
    00123     virtual OGRBoolean  Equals( OGRGeometry * ) const = 0;
    00124     virtual OGRBoolean  Disjoint( const OGRGeometry * ) const;
    00125     virtual OGRBoolean  Touches( const OGRGeometry * ) const;
    00126     virtual OGRBoolean  Crosses( const OGRGeometry * ) const;
    00127     virtual OGRBoolean  Within( const OGRGeometry * ) const;
    00128     virtual OGRBoolean  Contains( const OGRGeometry * ) const;
    00129     virtual OGRBoolean  Overlaps( const OGRGeometry * ) const;
    00130 //    virtual OGRBoolean  Relate( const OGRGeometry *, const char * ) const;
    00131
    00132     virtual OGRGeometry *getBoundary() const;
    00133     virtual double  Distance( const OGRGeometry * ) const;
    00134     virtual OGRGeometry *ConvexHull() const;
    00135     virtual OGRGeometry *Buffer( double dfDist, int nQuadSegs = 30 ) const;
    00136     virtual OGRGeometry *Intersection( const OGRGeometry *) const;
    00137     virtual OGRGeometry *Union( const OGRGeometry * ) const;
    00138     virtual OGRGeometry *Difference( const OGRGeometry * ) const;
    00139     virtual OGRGeometry *SymmetricDifference( const OGRGeometry * ) const;
    00140
    00141     // backward compatibility methods.
    00142     OGRBoolean  Intersect( OGRGeometry * ) const;
    00143     OGRBoolean  Equal( OGRGeometry * ) const;
    00144
    00145     // Special HACK for DB2 7.2 support
    00146     static int bGenerate_DB2_V72_BYTE_ORDER;
    00147 };
    00148
    00149 /************************************************************************/
    00150 /*                               OGRPoint                               */
    00151 /************************************************************************/
    00152
    00159 class CPL_DLL OGRPoint : public OGRGeometry
    00160 {
    00161     double      x;
    00162     double      y;
    00163     double      z;
    00164
    00165   public:
    00166                 OGRPoint();
    00167                 OGRPoint( double x, double y );
    00168                 OGRPoint( double x, double y, double z );
    00169     virtual     ~OGRPoint();
    00170
    00171     // IWks Interface
    00172     virtual int WkbSize() const;
    00173     virtual OGRErr importFromWkb( unsigned char *, int=-1 );
    00174     virtual OGRErr exportToWkb( OGRwkbByteOrder, unsigned char * ) const;
    00175     virtual OGRErr importFromWkt( char ** );
    00176     virtual OGRErr exportToWkt( char ** ppszDstText ) const;
    00177
    00178     // IGeometry
    00179     virtual int getDimension() const;
    00180     virtual OGRGeometry *clone() const;
    00181     virtual void empty();
    00182     virtual void getEnvelope( OGREnvelope * psEnvelope ) const;
    00183
    00184     // IPoint
    00185     double      getX() const { return x; }
    00186     double      getY() const { return y; }
    00187     double      getZ() const { return z; }
    00188
    00189     // Non standard
    00190     virtual void setCoordinateDimension( int nDimension );
    00191     void        setX( double xIn ) { x = xIn; }
    00192     void        setY( double yIn ) { y = yIn; }
    00193     void        setZ( double zIn ) { z = zIn; nCoordDimension=3; }
    00194
    00195     // ISpatialRelation
    00196     virtual OGRBoolean  Equals( OGRGeometry * ) const;
    00197
    00198     // Non standard from OGRGeometry
    00199     virtual const char *getGeometryName() const;
    00200     virtual OGRwkbGeometryType getGeometryType() const;
    00201     virtual OGRErr  transform( OGRCoordinateTransformation *poCT );
    00202     virtual void flattenTo2D();
    00203
    00204 };
    00205
    00206 /************************************************************************/
    00207 /*                               OGRCurve                               */
    00208 /************************************************************************/
    00209
    00214 class CPL_DLL OGRCurve : public OGRGeometry
    00215 {
    00216   public:
    00217             OGRCurve();
    00218     virtual ~OGRCurve();
    00219     // ICurve methods
    00220     virtual double get_Length() const = 0;
    00221     virtual void StartPoint(OGRPoint *) const = 0;
    00222     virtual void EndPoint(OGRPoint *) const = 0;
    00223     virtual int  get_IsClosed() const;
    00224     virtual void Value( double, OGRPoint * ) const = 0;
    00225
    00226 };
    00227
    00228 /************************************************************************/
    00229 /*                            OGRLineString                             */
    00230 /************************************************************************/
    00231
    00236 class CPL_DLL OGRLineString : public OGRCurve
    00237 {
    00238   protected:
    00239     int         nPointCount;
    00240     OGRRawPoint *paoPoints;
    00241     double      *padfZ;
    00242
    00243     void        Make3D();
    00244     void        Make2D();
    00245
    00246   public:
    00247                 OGRLineString();
    00248     virtual     ~OGRLineString();
    00249
    00250     // IWks Interface
    00251     virtual int WkbSize() const;
    00252     virtual OGRErr importFromWkb( unsigned char *, int = -1 );
    00253     virtual OGRErr exportToWkb( OGRwkbByteOrder, unsigned char * ) const;
    00254     virtual OGRErr importFromWkt( char ** );
    00255     virtual OGRErr exportToWkt( char ** ppszDstText ) const;
    00256
    00257     // IGeometry interface
    00258     virtual int getDimension() const;
    00259     virtual OGRGeometry *clone() const;
    00260     virtual void empty();
    00261     virtual void getEnvelope( OGREnvelope * psEnvelope ) const;
    00262
    00263     // ICurve methods
    00264     virtual double get_Length() const;
    00265     virtual void StartPoint(OGRPoint *) const;
    00266     virtual void EndPoint(OGRPoint *) const;
    00267     virtual void Value( double, OGRPoint * ) const;
    00268
    00269     // ILineString methods
    00270     int         getNumPoints() const { return nPointCount; }
    00271     void        getPoint( int, OGRPoint * ) const;
    00272     double      getX( int i ) const { return paoPoints[i].x; }
    00273     double      getY( int i ) const { return paoPoints[i].y; }
    00274     double      getZ( int i ) const;
    00275
    00276     // ISpatialRelation
    00277     virtual OGRBoolean  Equals( OGRGeometry * ) const;
    00278
    00279     // non standard.
    00280     virtual void setCoordinateDimension( int nDimension );
    00281     void        setNumPoints( int );
    00282     void        setPoint( int, OGRPoint * );
    00283     void        setPoint( int, double, double );
    00284     void        setPoint( int, double, double, double );
    00285     void        setPoints( int, OGRRawPoint *, double * = NULL );
    00286     void        setPoints( int, double * padfX, double * padfY,
    00287                            double *padfZ = NULL );
    00288     void        addPoint( OGRPoint * );
    00289     void        addPoint( double, double );
    00290     void        addPoint( double, double, double );
    00291
    00292     void        getPoints( OGRRawPoint *, double * = NULL ) const;
    00293
    00294     void        addSubLineString( const OGRLineString *,
    00295                                   int nStartVertex = 0, int nEndVertex = -1 );
    00296
    00297     // non-standard from OGRGeometry
    00298     virtual OGRwkbGeometryType getGeometryType() const;
    00299     virtual const char *getGeometryName() const;
    00300     virtual OGRErr  transform( OGRCoordinateTransformation *poCT );
    00301     virtual void flattenTo2D();
    00302
    00303 };
    00304
    00305 /************************************************************************/
    00306 /*                            OGRLinearRing                             */
    00307 /************************************************************************/
    00308
    00327 class CPL_DLL OGRLinearRing : public OGRLineString
    00328 {
    00329   private:
    00330     friend class OGRPolygon;
    00331
    00332     // These are not IWks compatible ... just a convenience for OGRPolygon.
    00333     virtual int _WkbSize( int b3D ) const;
    00334     virtual OGRErr _importFromWkb( OGRwkbByteOrder, int b3D,
    00335                                    unsigned char *, int=-1 );
    00336     virtual OGRErr _exportToWkb( OGRwkbByteOrder, int b3D,
    00337                                  unsigned char * ) const;
    00338
    00339   public:
    00340                         OGRLinearRing();
    00341                         OGRLinearRing( OGRLinearRing * );
    00342                         ~OGRLinearRing();
    00343
    00344     // Non standard.
    00345     virtual const char *getGeometryName() const;
    00346     virtual OGRGeometry *clone() const;
    00347     virtual int isClockwise() const;
    00348     virtual void reverseWindingOrder();
    00349     virtual void closeRings();
    00350     virtual double get_Area() const;
    00351     OGRBoolean isPointInRing(const OGRPoint* pt) const;
    00352
    00353     // IWks Interface - Note this isnt really a first class object
    00354     // for the purposes of WKB form.  These methods always fail since this
    00355     // object cant be serialized on its own.
    00356     virtual int WkbSize() const;
    00357     virtual OGRErr importFromWkb( unsigned char *, int=-1 );
    00358     virtual OGRErr exportToWkb( OGRwkbByteOrder, unsigned char * ) const;
    00359 };
    00360
    00361 /************************************************************************/
    00362 /*                              OGRSurface                              */
    00363 /************************************************************************/
    00364
    00369 class CPL_DLL OGRSurface : public OGRGeometry
    00370 {
    00371   public:
    00372     virtual double      get_Area() const = 0;
    00373     virtual OGRErr      Centroid( OGRPoint * poPoint ) const = 0;
    00374     virtual OGRErr      PointOnSurface( OGRPoint * poPoint ) const = 0;
    00375 };
    00376
    00377 /************************************************************************/
    00378 /*                              OGRPolygon                              */
    00379 /************************************************************************/
    00380
    00390 class CPL_DLL OGRPolygon : public OGRSurface
    00391 {
    00392     int         nRingCount;
    00393     OGRLinearRing **papoRings;
    00394
    00395   public:
    00396                 OGRPolygon();
    00397     virtual     ~OGRPolygon();
    00398
    00399     // Non standard (OGRGeometry).
    00400     virtual const char *getGeometryName() const;
    00401     virtual OGRwkbGeometryType getGeometryType() const;
    00402     virtual OGRGeometry *clone() const;
    00403     virtual void empty();
    00404     virtual OGRErr  transform( OGRCoordinateTransformation *poCT );
    00405     virtual void flattenTo2D();
    00406
    00407     // ISurface Interface
    00408     virtual double      get_Area() const;
    00409     virtual int         Centroid( OGRPoint * poPoint ) const;
    00410     virtual int         PointOnSurface( OGRPoint * poPoint ) const;
    00411
    00412     // IWks Interface
    00413     virtual int WkbSize() const;
    00414     virtual OGRErr importFromWkb( unsigned char *, int = -1 );
    00415     virtual OGRErr exportToWkb( OGRwkbByteOrder, unsigned char * ) const;
    00416     virtual OGRErr importFromWkt( char ** );
    00417     virtual OGRErr exportToWkt( char ** ppszDstText ) const;
    00418
    00419     // IGeometry
    00420     virtual int getDimension() const;
    00421     virtual void getEnvelope( OGREnvelope * psEnvelope ) const;
    00422
    00423     // ISpatialRelation
    00424     virtual OGRBoolean  Equals( OGRGeometry * ) const;
    00425
    00426     // Non standard
    00427     virtual void setCoordinateDimension( int nDimension );
    00428
    00429     void        addRing( OGRLinearRing * );
    00430     void        addRingDirectly( OGRLinearRing * );
    00431
    00432     OGRLinearRing *getExteriorRing();
    00433     const OGRLinearRing *getExteriorRing() const;
    00434     int         getNumInteriorRings() const;
    00435     OGRLinearRing *getInteriorRing( int );
    00436     const OGRLinearRing *getInteriorRing( int ) const;
    00437
    00438     OGRBoolean IsPointOnSurface( const OGRPoint * ) const;
    00439
    00440     virtual void closeRings();
    00441 };
    00442
    00443 /************************************************************************/
    00444 /*                        OGRGeometryCollection                         */
    00445 /************************************************************************/
    00446
    00454 class CPL_DLL OGRGeometryCollection : public OGRGeometry
    00455 {
    00456     int         nGeomCount;
    00457     OGRGeometry **papoGeoms;
    00458
    00459     int         nCoordinateDimension;
    00460
    00461   public:
    00462                 OGRGeometryCollection();
    00463     virtual     ~OGRGeometryCollection();
    00464
    00465     // Non standard (OGRGeometry).
    00466     virtual const char *getGeometryName() const;
    00467     virtual OGRwkbGeometryType getGeometryType() const;
    00468     virtual OGRGeometry *clone() const;
    00469     virtual void empty();
    00470     virtual OGRErr  transform( OGRCoordinateTransformation *poCT );
    00471     virtual void flattenTo2D();
    00472
    00473     // IWks Interface
    00474     virtual int WkbSize() const;
    00475     virtual OGRErr importFromWkb( unsigned char *, int = -1 );
    00476     virtual OGRErr exportToWkb( OGRwkbByteOrder, unsigned char * ) const;
    00477     virtual OGRErr importFromWkt( char ** );
    00478     virtual OGRErr exportToWkt( char ** ppszDstText ) const;
    00479
    00480     virtual double get_Area() const;
    00481
    00482     // IGeometry methods
    00483     virtual int getDimension() const;
    00484     virtual void getEnvelope( OGREnvelope * psEnvelope ) const;
    00485
    00486     // IGeometryCollection
    00487     int         getNumGeometries() const;
    00488     OGRGeometry *getGeometryRef( int );
    00489     const OGRGeometry *getGeometryRef( int ) const;
    00490
    00491     // ISpatialRelation
    00492     virtual OGRBoolean  Equals( OGRGeometry * ) const;
    00493
    00494     // Non standard
    00495     virtual void setCoordinateDimension( int nDimension );
    00496     virtual OGRErr addGeometry( const OGRGeometry * );
    00497     virtual OGRErr addGeometryDirectly( OGRGeometry * );
    00498     virtual OGRErr removeGeometry( int iIndex, int bDelete = TRUE );
    00499
    00500     void closeRings();
    00501 };
    00502
    00503 /************************************************************************/
    00504 /*                           OGRMultiPolygon                            */
    00505 /************************************************************************/
    00506
    00514 class CPL_DLL OGRMultiPolygon : public OGRGeometryCollection
    00515 {
    00516   public:
    00517             OGRMultiPolygon();
    00518     // Non standard (OGRGeometry).
    00519     virtual const char *getGeometryName() const;
    00520     virtual OGRwkbGeometryType getGeometryType() const;
    00521     virtual OGRGeometry *clone() const;
    00522     virtual OGRErr importFromWkt( char ** );
    00523     virtual OGRErr exportToWkt( char ** ) const;
    00524
    00525     // Non standard
    00526     virtual OGRErr addGeometryDirectly( OGRGeometry * );
    00527
    00528     virtual double  get_Area() const;
    00529 };
    00530
    00531 /************************************************************************/
    00532 /*                            OGRMultiPoint                             */
    00533 /************************************************************************/
    00534
    00539 class CPL_DLL OGRMultiPoint : public OGRGeometryCollection
    00540 {
    00541   private:
    00542     OGRErr  importFromWkt_Bracketed( char ** );
    00543
    00544   public:
    00545             OGRMultiPoint();
    00546     // Non standard (OGRGeometry).
    00547     virtual const char *getGeometryName() const;
    00548     virtual OGRwkbGeometryType getGeometryType() const;
    00549     virtual OGRGeometry *clone() const;
    00550     virtual OGRErr importFromWkt( char ** );
    00551     virtual OGRErr exportToWkt( char ** ) const;
    00552
    00553     // Non standard
    00554     virtual OGRErr addGeometryDirectly( OGRGeometry * );
    00555 };
    00556
    00557 /************************************************************************/
    00558 /*                          OGRMultiLineString                          */
    00559 /************************************************************************/
    00560
    00565 class CPL_DLL OGRMultiLineString : public OGRGeometryCollection
    00566 {
    00567   public:
    00568             OGRMultiLineString();
    00569             ~OGRMultiLineString();
    00570     // Non standard (OGRGeometry).
    00571     virtual const char *getGeometryName() const;
    00572     virtual OGRwkbGeometryType getGeometryType() const;
    00573     virtual OGRGeometry *clone() const;
    00574     virtual OGRErr importFromWkt( char ** );
    00575     virtual OGRErr exportToWkt( char ** ) const;
    00576
    00577     // Non standard
    00578     virtual OGRErr addGeometryDirectly( OGRGeometry * );
    00579 };
    00580
    00581
    00582 /************************************************************************/
    00583 /*                          OGRGeometryFactory                          */
    00584 /************************************************************************/
    00585
    00590 class CPL_DLL OGRGeometryFactory
    00591 {
    00592   public:
    00593     static OGRErr createFromWkb( unsigned char *, OGRSpatialReference *,
    00594                                  OGRGeometry **, int = -1 );
    00595     static OGRErr createFromWkt( char **, OGRSpatialReference *,
    00596                                  OGRGeometry ** );
    00597     static OGRGeometry *createFromGML( const char * );
    00598     static OGRGeometry *createFromGEOS( GEOSGeom );
    00599
    00600     static void   destroyGeometry( OGRGeometry * );
    00601     static OGRGeometry *createGeometry( OGRwkbGeometryType );
    00602
    00603     static OGRGeometry * forceToPolygon( OGRGeometry * );
    00604     static OGRGeometry * forceToMultiPolygon( OGRGeometry * );
    00605     static OGRGeometry * forceToMultiPoint( OGRGeometry * );
    00606     static OGRGeometry * forceToMultiLineString( OGRGeometry * );
    00607
    00608     static OGRGeometry * organizePolygons( OGRGeometry **papoPolygons,
    00609                                            int nPolygonCount,
    00610                                            int *pbResultValidGeometry );
    00611
    00612     static void *getGEOSGeometryFactory();
    00613
    00614     static int haveGEOS();
    00615
    00616 };
    00617
    00618 #endif /* ndef _OGR_GEOMETRY_H_INCLUDED */

Generated for GDAL by 1.5.1.