mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-16 00:03:12 -04:00
Simplify QgsGeometryEngine code
This commit is contained in:
parent
e3787effc6
commit
b51a5f7b6f
@ -85,16 +85,28 @@ class QgsGeometryEngine
|
|||||||
%Docstring
|
%Docstring
|
||||||
:rtype: QgsAbstractGeometry
|
:rtype: QgsAbstractGeometry
|
||||||
%End
|
%End
|
||||||
virtual bool centroid( QgsPoint &pt, QString *errorMsg = 0 ) const = 0;
|
|
||||||
|
virtual QgsPoint *centroid( QString *errorMsg = 0 ) const = 0 /Factory/;
|
||||||
%Docstring
|
%Docstring
|
||||||
:rtype: bool
|
Calculates the centroid of this.
|
||||||
|
May return a `None`.
|
||||||
|
|
||||||
|
.. versionadded:: 3.0
|
||||||
|
:rtype: QgsPoint
|
||||||
%End
|
%End
|
||||||
virtual bool pointOnSurface( QgsPoint &pt, QString *errorMsg = 0 ) const = 0;
|
|
||||||
|
virtual QgsPoint *pointOnSurface( QString *errorMsg = 0 ) const = 0 /Factory/;
|
||||||
%Docstring
|
%Docstring
|
||||||
:rtype: bool
|
Calculate a point that is guaranteed to be on the surface of this.
|
||||||
|
May return a `None`.
|
||||||
|
|
||||||
|
.. versionadded:: 3.0
|
||||||
|
:rtype: QgsPoint
|
||||||
%End
|
%End
|
||||||
|
|
||||||
virtual QgsAbstractGeometry *convexHull( QString *errorMsg = 0 ) const = 0 /Factory/;
|
virtual QgsAbstractGeometry *convexHull( QString *errorMsg = 0 ) const = 0 /Factory/;
|
||||||
%Docstring
|
%Docstring
|
||||||
|
Calculate the convex hull of this.
|
||||||
:rtype: QgsAbstractGeometry
|
:rtype: QgsAbstractGeometry
|
||||||
%End
|
%End
|
||||||
|
|
||||||
|
@ -1581,16 +1581,8 @@ QgsGeometry QgsGeometry::centroid() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
QgsGeos geos( d->geometry );
|
QgsGeos geos( d->geometry );
|
||||||
std::unique_ptr<QgsPoint> centroid( new QgsPoint() );
|
|
||||||
QString error;
|
return QgsGeometry( geos.centroid( &d->error ) );
|
||||||
bool ok = geos.centroid( *centroid.get(), &error );
|
|
||||||
if ( !ok )
|
|
||||||
{
|
|
||||||
QgsGeometry geom;
|
|
||||||
geom.d->error = error;
|
|
||||||
return geom;
|
|
||||||
}
|
|
||||||
return QgsGeometry( centroid.release() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QgsGeometry QgsGeometry::pointOnSurface() const
|
QgsGeometry QgsGeometry::pointOnSurface() const
|
||||||
@ -1601,17 +1593,8 @@ QgsGeometry QgsGeometry::pointOnSurface() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
QgsGeos geos( d->geometry );
|
QgsGeos geos( d->geometry );
|
||||||
std::unique_ptr<QgsPoint>pt( new QgsPoint() );
|
|
||||||
|
|
||||||
QString error;
|
return QgsGeometry( geos.pointOnSurface( &d->error ) );
|
||||||
bool ok = geos.pointOnSurface( *pt.get(), &error );
|
|
||||||
if ( !ok )
|
|
||||||
{
|
|
||||||
QgsGeometry geom;
|
|
||||||
geom.d->error = error;
|
|
||||||
return geom;
|
|
||||||
}
|
|
||||||
return QgsGeometry( pt.release() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QgsGeometry QgsGeometry::poleOfInaccessibility( double precision, double *distanceToBoundary ) const
|
QgsGeometry QgsGeometry::poleOfInaccessibility( double precision, double *distanceToBoundary ) const
|
||||||
|
@ -75,8 +75,26 @@ class CORE_EXPORT QgsGeometryEngine
|
|||||||
virtual QgsAbstractGeometry *simplify( double tolerance, QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
|
virtual QgsAbstractGeometry *simplify( double tolerance, QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
|
||||||
virtual QgsAbstractGeometry *interpolate( double distance, QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
|
virtual QgsAbstractGeometry *interpolate( double distance, QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
|
||||||
virtual QgsAbstractGeometry *envelope( QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
|
virtual QgsAbstractGeometry *envelope( QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
|
||||||
virtual bool centroid( QgsPoint &pt, QString *errorMsg = nullptr ) const = 0;
|
|
||||||
virtual bool pointOnSurface( QgsPoint &pt, QString *errorMsg = nullptr ) const = 0;
|
/**
|
||||||
|
* Calculates the centroid of this.
|
||||||
|
* May return a `nullptr`.
|
||||||
|
*
|
||||||
|
* \since QGIS 3.0 the centroid is returned
|
||||||
|
*/
|
||||||
|
virtual QgsPoint *centroid( QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculate a point that is guaranteed to be on the surface of this.
|
||||||
|
* May return a `nullptr`.
|
||||||
|
*
|
||||||
|
* \since QGIS 3.0 the centroid is returned
|
||||||
|
*/
|
||||||
|
virtual QgsPoint *pointOnSurface( QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculate the convex hull of this.
|
||||||
|
*/
|
||||||
virtual QgsAbstractGeometry *convexHull( QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
|
virtual QgsAbstractGeometry *convexHull( QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1503,36 +1503,30 @@ QgsAbstractGeometry *QgsGeos::interpolate( double distance, QString *errorMsg )
|
|||||||
return fromGeos( geos.get() );
|
return fromGeos( geos.get() );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QgsGeos::centroid( QgsPoint &pt, QString *errorMsg ) const
|
QgsPoint *QgsGeos::centroid( QString *errorMsg ) const
|
||||||
{
|
{
|
||||||
if ( !mGeos )
|
if ( !mGeos )
|
||||||
{
|
{
|
||||||
return false;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
GEOSGeomScopedPtr geos;
|
GEOSGeomScopedPtr geos;
|
||||||
|
double x;
|
||||||
|
double y;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
geos.reset( GEOSGetCentroid_r( geosinit.ctxt, mGeos ) );
|
geos.reset( GEOSGetCentroid_r( geosinit.ctxt, mGeos ) );
|
||||||
}
|
|
||||||
CATCH_GEOS_WITH_ERRMSG( false );
|
|
||||||
|
|
||||||
if ( !geos )
|
if ( !geos )
|
||||||
{
|
return nullptr;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
double x, y;
|
|
||||||
GEOSGeomGetX_r( geosinit.ctxt, geos.get(), &x );
|
GEOSGeomGetX_r( geosinit.ctxt, geos.get(), &x );
|
||||||
GEOSGeomGetY_r( geosinit.ctxt, geos.get(), &y );
|
GEOSGeomGetY_r( geosinit.ctxt, geos.get(), &y );
|
||||||
pt.setX( x );
|
|
||||||
pt.setY( y );
|
|
||||||
}
|
}
|
||||||
CATCH_GEOS_WITH_ERRMSG( false );
|
CATCH_GEOS_WITH_ERRMSG( nullptr );
|
||||||
|
|
||||||
return true;
|
return new QgsPoint( x, y );
|
||||||
}
|
}
|
||||||
|
|
||||||
QgsAbstractGeometry *QgsGeos::envelope( QString *errorMsg ) const
|
QgsAbstractGeometry *QgsGeos::envelope( QString *errorMsg ) const
|
||||||
@ -1550,13 +1544,16 @@ QgsAbstractGeometry *QgsGeos::envelope( QString *errorMsg ) const
|
|||||||
return fromGeos( geos.get() );
|
return fromGeos( geos.get() );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QgsGeos::pointOnSurface( QgsPoint &pt, QString *errorMsg ) const
|
QgsPoint *QgsGeos::pointOnSurface( QString *errorMsg ) const
|
||||||
{
|
{
|
||||||
if ( !mGeos )
|
if ( !mGeos )
|
||||||
{
|
{
|
||||||
return false;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double x;
|
||||||
|
double y;
|
||||||
|
|
||||||
GEOSGeomScopedPtr geos;
|
GEOSGeomScopedPtr geos;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -1564,19 +1561,15 @@ bool QgsGeos::pointOnSurface( QgsPoint &pt, QString *errorMsg ) const
|
|||||||
|
|
||||||
if ( !geos || GEOSisEmpty_r( geosinit.ctxt, geos.get() ) != 0 )
|
if ( !geos || GEOSisEmpty_r( geosinit.ctxt, geos.get() ) != 0 )
|
||||||
{
|
{
|
||||||
return false;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
double x, y;
|
|
||||||
GEOSGeomGetX_r( geosinit.ctxt, geos.get(), &x );
|
GEOSGeomGetX_r( geosinit.ctxt, geos.get(), &x );
|
||||||
GEOSGeomGetY_r( geosinit.ctxt, geos.get(), &y );
|
GEOSGeomGetY_r( geosinit.ctxt, geos.get(), &y );
|
||||||
|
|
||||||
pt.setX( x );
|
|
||||||
pt.setY( y );
|
|
||||||
}
|
}
|
||||||
CATCH_GEOS_WITH_ERRMSG( false );
|
CATCH_GEOS_WITH_ERRMSG( nullptr );
|
||||||
|
|
||||||
return true;
|
return new QgsPoint( x, y );
|
||||||
}
|
}
|
||||||
|
|
||||||
QgsAbstractGeometry *QgsGeos::convexHull( QString *errorMsg ) const
|
QgsAbstractGeometry *QgsGeos::convexHull( QString *errorMsg ) const
|
||||||
|
@ -79,8 +79,8 @@ class CORE_EXPORT QgsGeos: public QgsGeometryEngine
|
|||||||
QgsAbstractGeometry *simplify( double tolerance, QString *errorMsg = nullptr ) const override;
|
QgsAbstractGeometry *simplify( double tolerance, QString *errorMsg = nullptr ) const override;
|
||||||
QgsAbstractGeometry *interpolate( double distance, QString *errorMsg = nullptr ) const override;
|
QgsAbstractGeometry *interpolate( double distance, QString *errorMsg = nullptr ) const override;
|
||||||
QgsAbstractGeometry *envelope( QString *errorMsg = nullptr ) const override;
|
QgsAbstractGeometry *envelope( QString *errorMsg = nullptr ) const override;
|
||||||
bool centroid( QgsPoint &pt, QString *errorMsg = nullptr ) const override;
|
QgsPoint *centroid( QString *errorMsg = nullptr ) const override;
|
||||||
bool pointOnSurface( QgsPoint &pt, QString *errorMsg = nullptr ) const override;
|
QgsPoint *pointOnSurface( QString *errorMsg = nullptr ) const override;
|
||||||
QgsAbstractGeometry *convexHull( QString *errorMsg = nullptr ) const override;
|
QgsAbstractGeometry *convexHull( QString *errorMsg = nullptr ) const override;
|
||||||
double distance( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const override;
|
double distance( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const override;
|
||||||
bool intersects( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const override;
|
bool intersects( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const override;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user