mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -04:00
API cleanups for qgsgeometry
git-svn-id: http://svn.osgeo.org/qgis/trunk@9515 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
parent
7c54dc07e2
commit
394993ea8f
@ -59,25 +59,25 @@ class QgsGeometry
|
|||||||
Set the geometry, feeding in the buffer containing OGC Well-Known Binary and the buffer's length.
|
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.
|
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
|
%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];
|
unsigned char * copy = new unsigned char[a1];
|
||||||
memcpy(copy, a0, a1);
|
memcpy(copy, a0, a1);
|
||||||
sipCpp->setWkbAndOwnership(copy, a1);
|
sipCpp->fromWkb(copy, a1);
|
||||||
%End
|
%End
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Returns the buffer containing this geometry in WKB format.
|
Returns the buffer containing this geometry in WKB format.
|
||||||
You may wish to use in conjunction with wkbSize().
|
You may wish to use in conjunction with wkbSize().
|
||||||
*/
|
*/
|
||||||
SIP_PYOBJECT wkbBuffer();
|
SIP_PYOBJECT asWkb();
|
||||||
%MethodCode
|
%MethodCode
|
||||||
sipRes = PyString_FromStringAndSize((const char *)sipCpp->wkbBuffer(), sipCpp->wkbSize());
|
sipRes = PyString_FromStringAndSize((const char *)sipCpp->asWkb(), sipCpp->wkbSize());
|
||||||
%End
|
%End
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Returns the size of the WKB in wkbBuffer().
|
Returns the size of the WKB in asWkb().
|
||||||
*/
|
*/
|
||||||
size_t wkbSize();
|
size_t wkbSize();
|
||||||
|
|
||||||
@ -94,7 +94,7 @@ class QgsGeometry
|
|||||||
Set the geometry, feeding in a geometry in GEOS format.
|
Set the geometry, feeding in a geometry in GEOS format.
|
||||||
*/
|
*/
|
||||||
// TODO: unsupported class... would be possible to use PyGEOS?
|
// TODO: unsupported class... would be possible to use PyGEOS?
|
||||||
//void setGeos(geos::Geometry* geos);
|
//void fromGeos(geos::Geometry* geos);
|
||||||
|
|
||||||
double distance(QgsGeometry& geom);
|
double distance(QgsGeometry& geom);
|
||||||
|
|
||||||
@ -116,7 +116,7 @@ class QgsGeometry
|
|||||||
account the first vertex is equal to the last vertex (and will
|
account the first vertex is equal to the last vertex (and will
|
||||||
skip equal vertex positions).
|
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,
|
/** Insert a new vertex before the given vertex index,
|
||||||
* ring and item (first number is index 0)
|
* ring and item (first number is index 0)
|
||||||
|
@ -176,7 +176,7 @@ bool QgsDistanceArea::setEllipsoid( const QString& ellipsoid )
|
|||||||
|
|
||||||
double QgsDistanceArea::measure( QgsGeometry* geometry )
|
double QgsDistanceArea::measure( QgsGeometry* geometry )
|
||||||
{
|
{
|
||||||
unsigned char* wkb = geometry->wkbBuffer();
|
unsigned char* wkb = geometry->asWkb();
|
||||||
unsigned char* ptr;
|
unsigned char* ptr;
|
||||||
unsigned int wkbType;
|
unsigned int wkbType;
|
||||||
double res, resTotal = 0;
|
double res, resTotal = 0;
|
||||||
|
@ -184,7 +184,7 @@ void QgsFeature::setGeometry( QgsGeometry* geom )
|
|||||||
void QgsFeature::setGeometryAndOwnership( unsigned char *geom, size_t length )
|
void QgsFeature::setGeometryAndOwnership( unsigned char *geom, size_t length )
|
||||||
{
|
{
|
||||||
QgsGeometry *g = new QgsGeometry();
|
QgsGeometry *g = new QgsGeometry();
|
||||||
g->setWkbAndOwnership( geom, length );
|
g->fromWkb( geom, length );
|
||||||
setGeometry( g );
|
setGeometry( g );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -392,7 +392,7 @@ static QgsGeometry *fromGeosGeom( GEOSGeometry *geom )
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
QgsGeometry* g = new QgsGeometry;
|
QgsGeometry* g = new QgsGeometry;
|
||||||
g->setGeos( geom );
|
g->fromGeos( geom );
|
||||||
return g;
|
return g;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -538,7 +538,7 @@ QgsGeometry & QgsGeometry::operator=( QgsGeometry const & rhs )
|
|||||||
} // 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
|
// delete any existing WKB geometry before assigning new one
|
||||||
if ( mGeometry )
|
if ( mGeometry )
|
||||||
@ -559,7 +559,7 @@ void QgsGeometry::setWkbAndOwnership( unsigned char * wkb, size_t length )
|
|||||||
mDirtyGeos = TRUE;
|
mDirtyGeos = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char * QgsGeometry::wkbBuffer()
|
unsigned char * QgsGeometry::asWkb()
|
||||||
{
|
{
|
||||||
if ( mDirtyWkb )
|
if ( mDirtyWkb )
|
||||||
{
|
{
|
||||||
@ -583,7 +583,7 @@ size_t QgsGeometry::wkbSize()
|
|||||||
|
|
||||||
QGis::WkbType QgsGeometry::wkbType()
|
QGis::WkbType QgsGeometry::wkbType()
|
||||||
{
|
{
|
||||||
unsigned char *geom = wkbBuffer(); // ensure that wkb representation exists
|
unsigned char *geom = asWkb(); // ensure that wkb representation exists
|
||||||
if ( geom )
|
if ( geom )
|
||||||
{
|
{
|
||||||
unsigned int wkbType;
|
unsigned int wkbType;
|
||||||
@ -640,7 +640,7 @@ bool QgsGeometry::isMultipart()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void QgsGeometry::setGeos( GEOSGeometry* geos )
|
void QgsGeometry::fromGeos( GEOSGeometry* geos )
|
||||||
{
|
{
|
||||||
// TODO - make this more heap-friendly
|
// TODO - make this more heap-friendly
|
||||||
|
|
||||||
@ -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
|
// TODO: implement with GEOS
|
||||||
if ( mDirtyWkb )
|
if ( mDirtyWkb )
|
||||||
|
@ -96,15 +96,25 @@ class CORE_EXPORT QgsGeometry
|
|||||||
static QgsGeometry* fromMultiPolygon( const QgsMultiPolygon& multipoly );
|
static QgsGeometry* fromMultiPolygon( const QgsMultiPolygon& multipoly );
|
||||||
/** construct geometry from a rectangle */
|
/** construct geometry from a rectangle */
|
||||||
static QgsGeometry* fromRect( const QgsRect& rect );
|
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.
|
Returns the buffer containing this geometry in WKB format.
|
||||||
You may wish to use in conjunction with wkbSize().
|
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();
|
size_t wkbSize();
|
||||||
|
|
||||||
@ -117,17 +127,7 @@ class CORE_EXPORT QgsGeometry
|
|||||||
/** Returns true if wkb of the geometry is of WKBMulti* type */
|
/** Returns true if wkb of the geometry is of WKBMulti* type */
|
||||||
bool isMultipart();
|
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 );
|
double distance( QgsGeometry& geom );
|
||||||
@ -151,7 +151,7 @@ class CORE_EXPORT QgsGeometry
|
|||||||
account the first vertex is equal to the last vertex (and will
|
account the first vertex is equal to the last vertex (and will
|
||||||
skip equal vertex positions).
|
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,
|
/** Insert a new vertex before the given vertex index,
|
||||||
@ -245,7 +245,10 @@ class CORE_EXPORT QgsGeometry
|
|||||||
@param topological true if topological editing is enabled
|
@param topological true if topological editing is enabled
|
||||||
@topologyTestPoints OUT: points that need to be tested for topological completeness in the dataset
|
@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*/
|
@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
|
/**Changes this geometry such that it does not intersect the other geometry
|
||||||
@param other geometry that should not be intersect
|
@param other geometry that should not be intersect
|
||||||
|
@ -507,7 +507,7 @@ QgsLabelAttributes *QgsLabel::layerAttributes( void )
|
|||||||
void QgsLabel::labelPoint( std::vector<QgsPoint>& points, QgsFeature & feature )
|
void QgsLabel::labelPoint( std::vector<QgsPoint>& points, QgsFeature & feature )
|
||||||
{
|
{
|
||||||
QgsGeometry *geometry = feature.geometry();
|
QgsGeometry *geometry = feature.geometry();
|
||||||
unsigned char *geom = geometry->wkbBuffer();
|
unsigned char *geom = geometry->asWkb();
|
||||||
size_t geomlen = geometry->wkbSize();
|
size_t geomlen = geometry->wkbSize();
|
||||||
QGis::WkbType wkbType = geometry->wkbType();
|
QGis::WkbType wkbType = geometry->wkbType();
|
||||||
QgsPoint point;
|
QgsPoint point;
|
||||||
|
@ -236,7 +236,7 @@ bool QgsVectorFileWriter::addFeature( QgsFeature& feature )
|
|||||||
|
|
||||||
OGRGeometryH mGeom2 = createEmptyGeometry( geom->wkbType() );
|
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 )
|
if ( err != OGRERR_NONE )
|
||||||
{
|
{
|
||||||
QgsDebugMsg( "Failed to import geometry from WKB: " + QString::number( err ) );
|
QgsDebugMsg( "Failed to import geometry from WKB: " + QString::number( err ) );
|
||||||
@ -249,7 +249,7 @@ bool QgsVectorFileWriter::addFeature( QgsFeature& feature )
|
|||||||
}
|
}
|
||||||
else
|
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 )
|
if ( err != OGRERR_NONE )
|
||||||
{
|
{
|
||||||
QgsDebugMsg( "Failed to import geometry from WKB: " + QString::number( err ) );
|
QgsDebugMsg( "Failed to import geometry from WKB: " + QString::number( err ) );
|
||||||
|
@ -3301,7 +3301,7 @@ void QgsVectorLayer::drawFeature( QPainter* p,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
QgsGeometry* geom = fet.geometry();
|
QgsGeometry* geom = fet.geometry();
|
||||||
unsigned char* feature = geom->wkbBuffer();
|
unsigned char* feature = geom->asWkb();
|
||||||
|
|
||||||
QGis::WkbType wkbType = geom->wkbType();
|
QGis::WkbType wkbType = geom->wkbType();
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ int QgsInterpolator::addVerticesToCache( QgsGeometry* geom, double attributeValu
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool hasZValue = false;
|
bool hasZValue = false;
|
||||||
unsigned char* currentWkbPtr = geom->wkbBuffer();
|
unsigned char* currentWkbPtr = geom->asWkb();
|
||||||
vertexData theVertex; //the current vertex
|
vertexData theVertex; //the current vertex
|
||||||
|
|
||||||
QGis::WkbType wkbType = geom->wkbType();
|
QGis::WkbType wkbType = geom->wkbType();
|
||||||
|
@ -229,7 +229,7 @@ bool QgsGPXProvider::nextFeature( QgsFeature& feature )
|
|||||||
//create QgsGeometry and use it for intersection test
|
//create QgsGeometry and use it for intersection test
|
||||||
//if geometry is to be fetched, it is attached to the feature, otherwise we delete it
|
//if geometry is to be fetched, it is attached to the feature, otherwise we delete it
|
||||||
QgsGeometry* theGeometry = new QgsGeometry();
|
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
|
bool intersection = theGeometry->intersects( b );//use geos for precise intersection test
|
||||||
|
|
||||||
if ( !intersection )
|
if ( !intersection )
|
||||||
@ -344,7 +344,7 @@ bool QgsGPXProvider::nextFeature( QgsFeature& feature )
|
|||||||
//create QgsGeometry and use it for intersection test
|
//create QgsGeometry and use it for intersection test
|
||||||
//if geometry is to be fetched, it is attached to the feature, otherwise we delete it
|
//if geometry is to be fetched, it is attached to the feature, otherwise we delete it
|
||||||
QgsGeometry* theGeometry = new QgsGeometry();
|
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
|
bool intersection = theGeometry->intersects( b );//use geos for precise intersection test
|
||||||
|
|
||||||
if ( !intersection ) //no intersection, delete geometry and move on
|
if ( !intersection ) //no intersection, delete geometry and move on
|
||||||
@ -522,7 +522,7 @@ bool QgsGPXProvider::addFeatures( QgsFeatureList & flist )
|
|||||||
|
|
||||||
bool QgsGPXProvider::addFeature( QgsFeature& f )
|
bool QgsGPXProvider::addFeature( QgsFeature& f )
|
||||||
{
|
{
|
||||||
unsigned char* geo = f.geometry()->wkbBuffer();
|
unsigned char* geo = f.geometry()->asWkb();
|
||||||
QGis::WkbType wkbType = f.geometry()->wkbType();
|
QGis::WkbType wkbType = f.geometry()->wkbType();
|
||||||
bool success = false;
|
bool success = false;
|
||||||
GPSObject* obj = NULL;
|
GPSObject* obj = NULL;
|
||||||
|
@ -477,7 +477,7 @@ bool QgsOgrProvider::addFeature( QgsFeature& f )
|
|||||||
bool returnValue = true;
|
bool returnValue = true;
|
||||||
OGRFeatureDefnH fdef = OGR_L_GetLayerDefn( ogrLayer );
|
OGRFeatureDefnH fdef = OGR_L_GetLayerDefn( ogrLayer );
|
||||||
OGRFeatureH feature = OGR_F_Create( fdef );
|
OGRFeatureH feature = OGR_F_Create( fdef );
|
||||||
unsigned char* wkb = f.geometry()->wkbBuffer();
|
unsigned char* wkb = f.geometry()->asWkb();
|
||||||
|
|
||||||
if ( f.geometry()->wkbSize() > 0 )
|
if ( f.geometry()->wkbSize() > 0 )
|
||||||
{
|
{
|
||||||
@ -688,7 +688,7 @@ bool QgsOgrProvider::changeGeometryValues( QgsGeometryMap & geometry_map )
|
|||||||
}
|
}
|
||||||
|
|
||||||
//create an OGRGeometry
|
//create an OGRGeometry
|
||||||
if ( OGR_G_CreateFromWkb( it->wkbBuffer(),
|
if ( OGR_G_CreateFromWkb( it->asWkb(),
|
||||||
OGR_L_GetSpatialRef( ogrLayer ),
|
OGR_L_GetSpatialRef( ogrLayer ),
|
||||||
&theNewGeometry,
|
&theNewGeometry,
|
||||||
it->wkbSize() ) != OGRERR_NONE )
|
it->wkbSize() ) != OGRERR_NONE )
|
||||||
|
@ -2075,7 +2075,7 @@ bool QgsPostgresProvider::changeAttributeValues( const QgsChangedAttributesMap &
|
|||||||
|
|
||||||
void QgsPostgresProvider::appendGeomString( QgsGeometry *geom, QString &geomString ) const
|
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 )
|
for ( uint i = 0; i < geom->wkbSize(); ++i )
|
||||||
{
|
{
|
||||||
if ( connectionRW->useWkbHex() )
|
if ( connectionRW->useWkbHex() )
|
||||||
@ -2118,7 +2118,7 @@ bool QgsPostgresProvider::changeGeometryValues( QgsGeometryMap & geometry_map )
|
|||||||
|
|
||||||
QgsDebugMsg( "iterating over the map of changed geometries..." );
|
QgsDebugMsg( "iterating over the map of changed geometries..." );
|
||||||
|
|
||||||
if ( iter->wkbBuffer() )
|
if ( iter->asWkb() )
|
||||||
{
|
{
|
||||||
QgsDebugMsg( "iterating over feature id " + QString::number( iter.key() ) );
|
QgsDebugMsg( "iterating over feature id " + QString::number( iter.key() ) );
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ bool QgsWFSProvider::nextFeature( QgsFeature& feature )
|
|||||||
|
|
||||||
//we need geometry anyway, e.g. for intersection tests
|
//we need geometry anyway, e.g. for intersection tests
|
||||||
QgsGeometry* geometry = mFeatures[*mFeatureIterator]->geometry();
|
QgsGeometry* geometry = mFeatures[*mFeatureIterator]->geometry();
|
||||||
unsigned char *geom = geometry->wkbBuffer();
|
unsigned char *geom = geometry->asWkb();
|
||||||
int geomSize = geometry->wkbSize();
|
int geomSize = geometry->wkbSize();
|
||||||
unsigned char* copiedGeom = new unsigned char[geomSize];
|
unsigned char* copiedGeom = new unsigned char[geomSize];
|
||||||
memcpy( copiedGeom, geom, geomSize );
|
memcpy( copiedGeom, geom, geomSize );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user