Skip to content

Commit

Permalink
upgraded OGR geometry dimension handling
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.osgeo.org/gdal/trunk@7855 f0d54148-0727-0410-94bb-9a71ac55c965
  • Loading branch information
warmerdam committed Jul 20, 2005
1 parent 0723e6c commit 01bd219
Show file tree
Hide file tree
Showing 11 changed files with 287 additions and 131 deletions.
84 changes: 84 additions & 0 deletions ogr/ogr_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
******************************************************************************
*
* $Log$
* Revision 1.8 2005/07/20 01:43:51 fwarmerdam
* upgraded OGR geometry dimension handling
*
* Revision 1.7 2004/09/17 15:05:36 fwarmerdam
* added get_Area() support
*
Expand Down Expand Up @@ -275,6 +278,50 @@ void OGR_G_SetPoint( OGRGeometryH hGeom, int i,
}
}

/************************************************************************/
/* OGR_G_SetPoint_2D() */
/************************************************************************/
/**
* Set the location of a vertex in a point or linestring geometry.
*
* If iPoint is larger than the number of existing
* points in the linestring, the point count will be increased to
* accomodate the request.
*
* @param hGeom handle to the geometry to add a vertex to.
* @param i the index of the vertex to assign (zero based) or
* zero for a point.
* @param dfX input X coordinate to assign.
* @param dfY input Y coordinate to assign.
*/

void OGR_G_SetPoint_2D( OGRGeometryH hGeom, int i,
double dfX, double dfY )

{
switch( wkbFlatten(((OGRGeometry *) hGeom)->getGeometryType()) )
{
case wkbPoint:
{
CPLAssert( i == 0 );
if( i == 0 )
{
((OGRPoint *) hGeom)->setX( dfX );
((OGRPoint *) hGeom)->setY( dfY );
}
}
break;

case wkbLineString:
((OGRLineString *) hGeom)->setPoint( i, dfX, dfY );
break;

default:
CPLAssert( FALSE );
break;
}
}

/************************************************************************/
/* OGR_G_AddPoint() */
/************************************************************************/
Expand Down Expand Up @@ -314,6 +361,43 @@ void OGR_G_AddPoint( OGRGeometryH hGeom,
}
}

/************************************************************************/
/* OGR_G_AddPoint() */
/************************************************************************/
/**
* Add a point to a geometry (line string or point).
*
* The vertex count of the line string is increased by one, and assigned from
* the passed location value.
*
* @param hGeom handle to the geometry to add a point to.
* @param dfX x coordinate of point to add.
* @param dfY y coordinate of point to add.
*/

void OGR_G_AddPoint_2D( OGRGeometryH hGeom,
double dfX, double dfY )

{
switch( wkbFlatten(((OGRGeometry *) hGeom)->getGeometryType()) )
{
case wkbPoint:
{
((OGRPoint *) hGeom)->setX( dfX );
((OGRPoint *) hGeom)->setY( dfY );
}
break;

case wkbLineString:
((OGRLineString *) hGeom)->addPoint( dfX, dfY );
break;

default:
CPLAssert( FALSE );
break;
}
}

/************************************************************************/
/* OGR_G_GetGeometryCount() */
/************************************************************************/
Expand Down
7 changes: 7 additions & 0 deletions ogr/ogr_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
******************************************************************************
*
* $Log$
* Revision 1.26 2005/07/20 01:43:51 fwarmerdam
* upgraded OGR geometry dimension handling
*
* Revision 1.25 2005/02/22 12:37:26 fwarmerdam
* rename Equal/Intersect to Equals/Intersects
*
Expand Down Expand Up @@ -147,6 +150,7 @@ OGRGeometryH CPL_DLL OGR_G_CreateGeometry( OGRwkbGeometryType );

int CPL_DLL OGR_G_GetDimension( OGRGeometryH );
int CPL_DLL OGR_G_GetCoordinateDimension( OGRGeometryH );
void CPL_DLL OGR_G_SetCoordinateDimension( OGRGeometryH, int );
OGRGeometryH CPL_DLL OGR_G_Clone( OGRGeometryH );
void CPL_DLL OGR_G_GetEnvelope( OGRGeometryH, OGREnvelope * );
OGRErr CPL_DLL OGR_G_ImportFromWkb( OGRGeometryH, unsigned char *, int );
Expand Down Expand Up @@ -211,7 +215,10 @@ void CPL_DLL OGR_G_GetPoint( OGRGeometryH, int iPoint,
double *, double *, double * );
void CPL_DLL OGR_G_SetPoint( OGRGeometryH, int iPoint,
double, double, double );
void CPL_DLL OGR_G_SetPoint_2D( OGRGeometryH, int iPoint,
double, double );
void CPL_DLL OGR_G_AddPoint( OGRGeometryH, double, double, double );
void CPL_DLL OGR_G_AddPoint_2D( OGRGeometryH, double, double );

/* Methods for getting/setting rings and members collections */

Expand Down
26 changes: 18 additions & 8 deletions ogr/ogr_geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
******************************************************************************
*
* $Log$
* Revision 1.54 2005/07/20 01:43:51 fwarmerdam
* upgraded OGR geometry dimension handling
*
* Revision 1.53 2005/03/25 06:31:12 fwarmerdam
* added addSubLineString
*
Expand Down Expand Up @@ -242,14 +245,17 @@ class CPL_DLL OGRGeometry
{
private:
OGRSpatialReference * poSRS; // may be NULL

protected:
int nCoordDimension;

public:
OGRGeometry();
virtual ~OGRGeometry();

// standard IGeometry
virtual int getDimension() const = 0;
virtual int getCoordinateDimension() const = 0;
virtual int getCoordinateDimension() const;
virtual OGRBoolean IsEmpty() const { return 0; }
virtual OGRBoolean IsSimple() const { return 1; }
virtual void empty() = 0;
Expand All @@ -272,6 +278,8 @@ class CPL_DLL OGRGeometry
virtual geos::Geometry *exportToGEOS() const;
virtual void closeRings();

virtual void setCoordinateDimension( int nDimension );

void assignSpatialReference( OGRSpatialReference * poSR );
OGRSpatialReference *getSpatialReference( void ) const { return poSRS; }

Expand Down Expand Up @@ -336,7 +344,6 @@ class CPL_DLL OGRPoint : public OGRGeometry

// IGeometry
virtual int getDimension() const;
virtual int getCoordinateDimension() const;
virtual OGRGeometry *clone() const;
virtual void empty();
virtual void getEnvelope( OGREnvelope * psEnvelope ) const;
Expand All @@ -349,7 +356,7 @@ class CPL_DLL OGRPoint : public OGRGeometry
// Non standard
void setX( double xIn ) { x = xIn; }
void setY( double yIn ) { y = yIn; }
void setZ( double zIn ) { z = zIn; }
void setZ( double zIn ) { z = zIn; nCoordDimension=3; }

// ISpatialRelation
virtual OGRBoolean Equals( OGRGeometry * ) const;
Expand Down Expand Up @@ -415,7 +422,6 @@ class CPL_DLL OGRLineString : public OGRCurve

// IGeometry interface
virtual int getDimension() const;
virtual int getCoordinateDimension() const;
virtual OGRGeometry *clone() const;
virtual void empty();
virtual void getEnvelope( OGREnvelope * psEnvelope ) const;
Expand All @@ -437,14 +443,17 @@ class CPL_DLL OGRLineString : public OGRCurve
virtual OGRBoolean Equals( OGRGeometry * ) const;

// non standard.
virtual void setCoordinateDimension( int nDimension );
void setNumPoints( int );
void setPoint( int, OGRPoint * );
void setPoint( int, double, double, double = 0.0 );
void setPoint( int, double, double );
void setPoint( int, double, double, double );
void setPoints( int, OGRRawPoint *, double * = NULL );
void setPoints( int, double * padfX, double * padfY,
double *padfZ = NULL );
void addPoint( OGRPoint * );
void addPoint( double, double, double = 0.0 );
void addPoint( double, double );
void addPoint( double, double, double );

void addSubLineString( const OGRLineString *,
int nStartVertex = 0, int nEndVertex = -1 );
Expand Down Expand Up @@ -563,13 +572,14 @@ class CPL_DLL OGRPolygon : public OGRSurface

// IGeometry
virtual int getDimension() const;
virtual int getCoordinateDimension() const;
virtual void getEnvelope( OGREnvelope * psEnvelope ) const;

// ISpatialRelation
virtual OGRBoolean Equals( OGRGeometry * ) const;

// Non standard
virtual void setCoordinateDimension( int nDimension );

void addRing( OGRLinearRing * );
void addRingDirectly( OGRLinearRing * );

Expand Down Expand Up @@ -621,7 +631,6 @@ class CPL_DLL OGRGeometryCollection : public OGRGeometry

// IGeometry methods
virtual int getDimension() const;
virtual int getCoordinateDimension() const;
virtual void getEnvelope( OGREnvelope * psEnvelope ) const;

// IGeometryCollection
Expand All @@ -633,6 +642,7 @@ class CPL_DLL OGRGeometryCollection : public OGRGeometry
virtual OGRBoolean Equals( OGRGeometry * ) const;

// Non standard
virtual void setCoordinateDimension( int nDimension );
virtual OGRErr addGeometry( const OGRGeometry * );
virtual OGRErr addGeometryDirectly( OGRGeometry * );
virtual OGRErr removeGeometry( int iIndex, int bDelete = TRUE );
Expand Down
12 changes: 8 additions & 4 deletions ogr/ogr_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
******************************************************************************
*
* $Log$
* Revision 1.8 2005/07/20 01:43:51 fwarmerdam
* upgraded OGR geometry dimension handling
*
* Revision 1.7 2001/11/01 17:01:28 warmerda
* pass output buffer into OGRMakeWktCoordinate
*
Expand Down Expand Up @@ -78,11 +81,12 @@
const char CPL_DLL * OGRWktReadToken( const char * pszInput, char * pszToken );

const char CPL_DLL * OGRWktReadPoints( const char * pszInput,
OGRRawPoint **ppaoPoints, double **ppadfZ,
int * pnMaxPoints,
int * pnReadPoints );
OGRRawPoint **ppaoPoints,
double **ppadfZ,
int * pnMaxPoints,
int * pnReadPoints );

void CPL_DLL OGRMakeWktCoordinate( char *, double, double, double );
void CPL_DLL OGRMakeWktCoordinate( char *, double, double, double, int );
#endif

#endif /* ndef _OGR_P_H_INCLUDED */
47 changes: 45 additions & 2 deletions ogr/ogrgeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
******************************************************************************
*
* $Log$
* Revision 1.31 2005/07/20 01:43:51 fwarmerdam
* upgraded OGR geometry dimension handling
*
* Revision 1.30 2005/04/18 15:42:17 fwarmerdam
* fix geos exception catching
*
Expand Down Expand Up @@ -148,6 +151,7 @@ OGRGeometry::OGRGeometry()

{
poSRS = NULL;
nCoordDimension = 2;
}

/************************************************************************/
Expand Down Expand Up @@ -570,9 +574,10 @@ int OGR_G_GetDimension( OGRGeometryH hGeom )
return ((OGRGeometry *) hGeom)->getDimension();
}

/************************************************************************/
/* getCoordinateDimension() */
/************************************************************************/
/**
* \fn int OGRGeometry::getCoordinateDimension() const;
*
* Get the dimension of the coordinates in this object.
*
* This method corresponds to the SFCOM IGeometry::GetDimension() method.
Expand All @@ -583,6 +588,12 @@ int OGR_G_GetDimension( OGRGeometryH hGeom )
* specified within a two dimensional space.
*/

int OGRGeometry::getCoordinateDimension() const

{
return nCoordDimension;
}

/************************************************************************/
/* OGR_G_GetCoordinateDimension() */
/************************************************************************/
Expand All @@ -607,6 +618,37 @@ int OGR_G_GetCoordinateDimension( OGRGeometryH hGeom )
return ((OGRGeometry *) hGeom)->getCoordinateDimension();
}

/************************************************************************/
/* setCoordinateDimension() */
/************************************************************************/

/**
* Set the coordinate dimension.
*
* This method sets the explicit coordinate dimension. Setting the coordinate
* dimension of a geometry to 2 should zero out any existing Z values. Setting
* the dimension of a geometry collection will not necessarily affect the
* children geometries.
*
* @param nNewDimension New coordinate dimension value, either 2 or 3.
*/

void OGRGeometry::setCoordinateDimension( int nNewDimension )

{
nCoordDimension = nNewDimension;
}

/************************************************************************/
/* OGR_G_SetCoordinateDimension() */
/************************************************************************/

void OGR_G_SetCoordinateDimension( OGRGeometryH hGeom, int nNewDimension)

{
((OGRGeometry *) hGeom)->setCoordinateDimension( nNewDimension );
}


/**
* \fn OGRBoolean OGRGeometry::IsEmpty() const;
Expand Down Expand Up @@ -2320,3 +2362,4 @@ void OGR_G_CloseRings( OGRGeometryH hGeom )
{
((OGRGeometry *) hGeom)->closeRings();
}

Loading

0 comments on commit 01bd219

Please sign in to comment.