[Gdal-dev] FW: ogr: create? new geometries
Frank Warmerdam
warmerdam at pobox.com
Tue Jul 8 09:35:09 EDT 2003
Nico Hardebol wrote:
> but within ogr I can only find OGRGeometryFactory in which new geometries
> objects can be created from well known bin/txt. But no double arrays of X
> and Y coord. can be offered from which a new geometry is built - true?
> Possibly I'm missing something important, I can imagine that this type of
> functionaly is not included since may major problems with spatial
> relationships / topology arises.
> Do I have to build a new geometry with the use of creatFromWKB/WKT() - but
> then I can't find a c++ api with some basic functions to build (opengis
> OLE/COM specifications?).
> OR do you advice me to keep it simple and continue with shapelib - without
> the great advantages of ogr (e.a. reading several file formats / postgis
> PostgreSQL functionality).
Nico,
There is no general approach to getting all the vertices and modifying them
for any geometry type. For complete generality you will need to implement
support for points, linestrings, polygons, and collections. Each class has
specific methods for getting the points, or child objects.
For OGRPoint:
// IPoint
double getX() { return x; }
double getY() { return y; }
double getZ() { return z; }
// Non standard
void setX( double xIn ) { x = xIn; }
void setY( double yIn ) { y = yIn; }
void setZ( double zIn ) { z = zIn; }
For LineString (and LinearRing):
// ILineString methods
int getNumPoints() { return nPointCount; }
void getPoint( int, OGRPoint * );
double getX( int i ) { return paoPoints[i].x; }
double getY( int i ) { return paoPoints[i].y; }
double getZ( int i );
// non standard.
void setNumPoints( int );
void setPoint( int, OGRPoint * );
void setPoint( int, double, double, double = 0.0 );
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 );
For OGRPolygon:
// Non standard
void addRing( OGRLinearRing * );
void addRingDirectly( OGRLinearRing * );
OGRLinearRing *getExteriorRing();
int getNumInteriorRings();
OGRLinearRing *getInteriorRing( int );
and for OGRGeometryCollection (and all the specific types):
// IGeometryCollection
int getNumGeometries();
OGRGeometry *getGeometryRef( int );
// Non standard
virtual OGRErr addGeometry( OGRGeometry * );
virtual OGRErr addGeometryDirectly( OGRGeometry * );
virtual OGRErr removeGeometry( int iIndex, int bDelete = TRUE );
To create new empty geometries of a particular class you can either
instantiate them directly (ie. new OGRLineString()) or use the
geometry factory (ie. OGRGeometryFactory::createGeometry(wkbLineString)).
Also, you may find it more convenient to just clone your source geometries
with the OGRGeometry::clone() method and then update the new copy in place.
Best regards,
--
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush | Geospatial Programmer for Rent
More information about the Gdal-dev
mailing list