Skip to content

Commit

Permalink
API cleanups for qgsgeometry
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@9515 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
timlinux committed Oct 22, 2008
1 parent 7c54dc0 commit 394993e
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 43 deletions.
16 changes: 8 additions & 8 deletions python/core/qgsgeometry.sip
Original file line number Diff line number Diff line change
Expand Up @@ -59,25 +59,25 @@ class QgsGeometry
Set the geometry, feeding in the buffer containing OGC Well-Known Binary and the buffer's length.
This class will take ownership of the buffer.
*/
void setWkbAndOwnership(unsigned char * wkb /Array/, size_t length /ArraySize/);
void fromWkb(unsigned char * wkb /Array/, size_t length /ArraySize/);
%MethodCode
// create copy of Python's string and pass it to setWkbAndOwnership()
// create copy of Python's string and pass it to fromWkb()
unsigned char * copy = new unsigned char[a1];
memcpy(copy, a0, a1);
sipCpp->setWkbAndOwnership(copy, a1);
sipCpp->fromWkb(copy, a1);
%End

/**
Returns the buffer containing this geometry in WKB format.
You may wish to use in conjunction with wkbSize().
*/
SIP_PYOBJECT wkbBuffer();
SIP_PYOBJECT asWkb();
%MethodCode
sipRes = PyString_FromStringAndSize((const char *)sipCpp->wkbBuffer(), sipCpp->wkbSize());
sipRes = PyString_FromStringAndSize((const char *)sipCpp->asWkb(), sipCpp->wkbSize());
%End

/**
Returns the size of the WKB in wkbBuffer().
Returns the size of the WKB in asWkb().
*/
size_t wkbSize();

Expand All @@ -94,7 +94,7 @@ class QgsGeometry
Set the geometry, feeding in a geometry in GEOS format.
*/
// TODO: unsupported class... would be possible to use PyGEOS?
//void setGeos(geos::Geometry* geos);
//void fromGeos(geos::Geometry* geos);

double distance(QgsGeometry& geom);

Expand All @@ -116,7 +116,7 @@ class QgsGeometry
account the first vertex is equal to the last vertex (and will
skip equal vertex positions).
*/
void adjacentVerticies(int atVertex, int& beforeVertex /Out/, int& afterVertex /Out/);
void adjacentVertices(int atVertex, int& beforeVertex /Out/, int& afterVertex /Out/);

/** Insert a new vertex before the given vertex index,
* ring and item (first number is index 0)
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsdistancearea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ bool QgsDistanceArea::setEllipsoid( const QString& ellipsoid )

double QgsDistanceArea::measure( QgsGeometry* geometry )
{
unsigned char* wkb = geometry->wkbBuffer();
unsigned char* wkb = geometry->asWkb();
unsigned char* ptr;
unsigned int wkbType;
double res, resTotal = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ void QgsFeature::setGeometry( QgsGeometry* geom )
void QgsFeature::setGeometryAndOwnership( unsigned char *geom, size_t length )
{
QgsGeometry *g = new QgsGeometry();
g->setWkbAndOwnership( geom, length );
g->fromWkb( geom, length );
setGeometry( g );
}

Expand Down
12 changes: 6 additions & 6 deletions src/core/qgsgeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ static QgsGeometry *fromGeosGeom( GEOSGeometry *geom )
return 0;

QgsGeometry* g = new QgsGeometry;
g->setGeos( geom );
g->fromGeos( geom );
return g;
}

Expand Down Expand Up @@ -538,7 +538,7 @@ QgsGeometry & QgsGeometry::operator=( QgsGeometry const & rhs )
} // QgsGeometry::operator=( QgsGeometry const & rhs )


void QgsGeometry::setWkbAndOwnership( unsigned char * wkb, size_t length )
void QgsGeometry::fromWkb( unsigned char * wkb, size_t length )
{
// delete any existing WKB geometry before assigning new one
if ( mGeometry )
Expand All @@ -559,7 +559,7 @@ void QgsGeometry::setWkbAndOwnership( unsigned char * wkb, size_t length )
mDirtyGeos = TRUE;
}

unsigned char * QgsGeometry::wkbBuffer()
unsigned char * QgsGeometry::asWkb()
{
if ( mDirtyWkb )
{
Expand All @@ -583,7 +583,7 @@ size_t QgsGeometry::wkbSize()

QGis::WkbType QgsGeometry::wkbType()
{
unsigned char *geom = wkbBuffer(); // ensure that wkb representation exists
unsigned char *geom = asWkb(); // ensure that wkb representation exists
if ( geom )
{
unsigned int wkbType;
Expand Down Expand Up @@ -640,7 +640,7 @@ bool QgsGeometry::isMultipart()
}


void QgsGeometry::setGeos( GEOSGeometry* geos )
void QgsGeometry::fromGeos( GEOSGeometry* geos )
{
// TODO - make this more heap-friendly

Expand Down Expand Up @@ -939,7 +939,7 @@ QgsPoint QgsGeometry::closestVertex( const QgsPoint& point, int& atVertex, int&
}


void QgsGeometry::adjacentVerticies( int atVertex, int& beforeVertex, int& afterVertex )
void QgsGeometry::adjacentVertices( int atVertex, int& beforeVertex, int& afterVertex )
{
// TODO: implement with GEOS
if ( mDirtyWkb )
Expand Down
31 changes: 17 additions & 14 deletions src/core/qgsgeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,25 @@ class CORE_EXPORT QgsGeometry
static QgsGeometry* fromMultiPolygon( const QgsMultiPolygon& multipoly );
/** construct geometry from a rectangle */
static QgsGeometry* fromRect( const QgsRect& rect );
/**
Set the geometry, feeding in a geometry in GEOS format.
This class will take ownership of the buffer.
*/
void fromGeos( GEOSGeometry* geos );
/**
Set the geometry, feeding in the buffer containing OGC Well-Known Binary and the buffer's length.
This class will take ownership of the buffer.
*/
void fromWkb( unsigned char * wkb, size_t length );

/**
Returns the buffer containing this geometry in WKB format.
You may wish to use in conjunction with wkbSize().
*/
unsigned char * wkbBuffer();
unsigned char * asWkb();

/**
Returns the size of the WKB in wkbBuffer().
Returns the size of the WKB in asWkb().
*/
size_t wkbSize();

Expand All @@ -117,17 +127,7 @@ class CORE_EXPORT QgsGeometry
/** Returns true if wkb of the geometry is of WKBMulti* type */
bool isMultipart();

/**
Set the geometry, feeding in a geometry in GEOS format.
This class will take ownership of the buffer.
*/
void setGeos( GEOSGeometry* geos );

/**
Set the geometry, feeding in the buffer containing OGC Well-Known Binary and the buffer's length.
This class will take ownership of the buffer.
*/
void setWkbAndOwnership( unsigned char * wkb, size_t length );


double distance( QgsGeometry& geom );
Expand All @@ -151,7 +151,7 @@ class CORE_EXPORT QgsGeometry
account the first vertex is equal to the last vertex (and will
skip equal vertex positions).
*/
void adjacentVerticies( int atVertex, int& beforeVertex, int& afterVertex );
void adjacentVertices( int atVertex, int& beforeVertex, int& afterVertex );


/** Insert a new vertex before the given vertex index,
Expand Down Expand Up @@ -245,7 +245,10 @@ class CORE_EXPORT QgsGeometry
@param topological true if topological editing is enabled
@topologyTestPoints OUT: points that need to be tested for topological completeness in the dataset
@return 0 in case of success, 1 if geometry has not been split, error else*/
int splitGeometry( const QList<QgsPoint>& splitLine, QList<QgsGeometry*>& newGeometries, bool topological, QList<QgsPoint>& topologyTestPoints );
int splitGeometry( const QList<QgsPoint>& splitLine,
QList<QgsGeometry*>&newGeometries,
bool topological,
QList<QgsPoint>& topologyTestPoints );

/**Changes this geometry such that it does not intersect the other geometry
@param other geometry that should not be intersect
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgslabel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ QgsLabelAttributes *QgsLabel::layerAttributes( void )
void QgsLabel::labelPoint( std::vector<QgsPoint>& points, QgsFeature & feature )
{
QgsGeometry *geometry = feature.geometry();
unsigned char *geom = geometry->wkbBuffer();
unsigned char *geom = geometry->asWkb();
size_t geomlen = geometry->wkbSize();
QGis::WkbType wkbType = geometry->wkbType();
QgsPoint point;
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgsvectorfilewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ bool QgsVectorFileWriter::addFeature( QgsFeature& feature )

OGRGeometryH mGeom2 = createEmptyGeometry( geom->wkbType() );

OGRErr err = OGR_G_ImportFromWkb( mGeom2, geom->wkbBuffer(), geom->wkbSize() );
OGRErr err = OGR_G_ImportFromWkb( mGeom2, geom->asWkb(), geom->wkbSize() );
if ( err != OGRERR_NONE )
{
QgsDebugMsg( "Failed to import geometry from WKB: " + QString::number( err ) );
Expand All @@ -249,7 +249,7 @@ bool QgsVectorFileWriter::addFeature( QgsFeature& feature )
}
else
{
OGRErr err = OGR_G_ImportFromWkb( mGeom, geom->wkbBuffer(), geom->wkbSize() );
OGRErr err = OGR_G_ImportFromWkb( mGeom, geom->asWkb(), geom->wkbSize() );
if ( err != OGRERR_NONE )
{
QgsDebugMsg( "Failed to import geometry from WKB: " + QString::number( err ) );
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsvectorlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3301,7 +3301,7 @@ void QgsVectorLayer::drawFeature( QPainter* p,
#endif

QgsGeometry* geom = fet.geometry();
unsigned char* feature = geom->wkbBuffer();
unsigned char* feature = geom->asWkb();

QGis::WkbType wkbType = geom->wkbType();

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/interpolation/qgsinterpolator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ int QgsInterpolator::addVerticesToCache( QgsGeometry* geom, double attributeValu
}

bool hasZValue = false;
unsigned char* currentWkbPtr = geom->wkbBuffer();
unsigned char* currentWkbPtr = geom->asWkb();
vertexData theVertex; //the current vertex

QGis::WkbType wkbType = geom->wkbType();
Expand Down
6 changes: 3 additions & 3 deletions src/providers/gpx/qgsgpxprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ bool QgsGPXProvider::nextFeature( QgsFeature& feature )
//create QgsGeometry and use it for intersection test
//if geometry is to be fetched, it is attached to the feature, otherwise we delete it
QgsGeometry* theGeometry = new QgsGeometry();
theGeometry->setWkbAndOwnership(( unsigned char * )geo, 9 + 16 * nPoints );
theGeometry->fromWkb(( unsigned char * )geo, 9 + 16 * nPoints );
bool intersection = theGeometry->intersects( b );//use geos for precise intersection test

if ( !intersection )
Expand Down Expand Up @@ -344,7 +344,7 @@ bool QgsGPXProvider::nextFeature( QgsFeature& feature )
//create QgsGeometry and use it for intersection test
//if geometry is to be fetched, it is attached to the feature, otherwise we delete it
QgsGeometry* theGeometry = new QgsGeometry();
theGeometry->setWkbAndOwnership(( unsigned char * )geo, 9 + 16 * totalPoints );
theGeometry->fromWkb(( unsigned char * )geo, 9 + 16 * totalPoints );
bool intersection = theGeometry->intersects( b );//use geos for precise intersection test

if ( !intersection ) //no intersection, delete geometry and move on
Expand Down Expand Up @@ -522,7 +522,7 @@ bool QgsGPXProvider::addFeatures( QgsFeatureList & flist )

bool QgsGPXProvider::addFeature( QgsFeature& f )
{
unsigned char* geo = f.geometry()->wkbBuffer();
unsigned char* geo = f.geometry()->asWkb();
QGis::WkbType wkbType = f.geometry()->wkbType();
bool success = false;
GPSObject* obj = NULL;
Expand Down
4 changes: 2 additions & 2 deletions src/providers/ogr/qgsogrprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ bool QgsOgrProvider::addFeature( QgsFeature& f )
bool returnValue = true;
OGRFeatureDefnH fdef = OGR_L_GetLayerDefn( ogrLayer );
OGRFeatureH feature = OGR_F_Create( fdef );
unsigned char* wkb = f.geometry()->wkbBuffer();
unsigned char* wkb = f.geometry()->asWkb();

if ( f.geometry()->wkbSize() > 0 )
{
Expand Down Expand Up @@ -688,7 +688,7 @@ bool QgsOgrProvider::changeGeometryValues( QgsGeometryMap & geometry_map )
}

//create an OGRGeometry
if ( OGR_G_CreateFromWkb( it->wkbBuffer(),
if ( OGR_G_CreateFromWkb( it->asWkb(),
OGR_L_GetSpatialRef( ogrLayer ),
&theNewGeometry,
it->wkbSize() ) != OGRERR_NONE )
Expand Down
4 changes: 2 additions & 2 deletions src/providers/postgres/qgspostgresprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2075,7 +2075,7 @@ bool QgsPostgresProvider::changeAttributeValues( const QgsChangedAttributesMap &

void QgsPostgresProvider::appendGeomString( QgsGeometry *geom, QString &geomString ) const
{
unsigned char *buf = geom->wkbBuffer();
unsigned char *buf = geom->asWkb();
for ( uint i = 0; i < geom->wkbSize(); ++i )
{
if ( connectionRW->useWkbHex() )
Expand Down Expand Up @@ -2118,7 +2118,7 @@ bool QgsPostgresProvider::changeGeometryValues( QgsGeometryMap & geometry_map )

QgsDebugMsg( "iterating over the map of changed geometries..." );

if ( iter->wkbBuffer() )
if ( iter->asWkb() )
{
QgsDebugMsg( "iterating over feature id " + QString::number( iter.key() ) );

Expand Down
2 changes: 1 addition & 1 deletion src/providers/wfs/qgswfsprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ bool QgsWFSProvider::nextFeature( QgsFeature& feature )

//we need geometry anyway, e.g. for intersection tests
QgsGeometry* geometry = mFeatures[*mFeatureIterator]->geometry();
unsigned char *geom = geometry->wkbBuffer();
unsigned char *geom = geometry->asWkb();
int geomSize = geometry->wkbSize();
unsigned char* copiedGeom = new unsigned char[geomSize];
memcpy( copiedGeom, geom, geomSize );
Expand Down

0 comments on commit 394993e

Please sign in to comment.