mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
Merge pull request #1451 from ahuarte47/Issue_OffsetCurve_API
Replace GEOS function calls by QgsGeometry class methods
This commit is contained in:
commit
9d8a84247d
@ -314,6 +314,9 @@ class QgsGeometry
|
||||
of segments used to approximate curves */
|
||||
QgsGeometry* buffer( double distance, int segments ) /Factory/;
|
||||
|
||||
/** Returns an offset line at a given distance and side from an input line. */
|
||||
QgsGeometry* offsetCurve( double distance, int segments, int joinStyle, double mitreLimit ) /Factory/;
|
||||
|
||||
/** Returns a simplified version of this geometry using a specified tolerance value */
|
||||
QgsGeometry* simplify( double tolerance ) /Factory/;
|
||||
|
||||
|
@ -5594,6 +5594,21 @@ QgsGeometry* QgsGeometry::buffer( double distance, int segments )
|
||||
CATCH_GEOS( 0 )
|
||||
}
|
||||
|
||||
QgsGeometry* QgsGeometry::offsetCurve( double distance, int segments, int joinStyle, double mitreLimit )
|
||||
{
|
||||
if ( mDirtyGeos )
|
||||
exportWkbToGeos();
|
||||
|
||||
if ( !mGeos || this->type() != QGis::Line )
|
||||
return 0;
|
||||
|
||||
try
|
||||
{
|
||||
return fromGeosGeom( GEOSOffsetCurve( mGeos, distance, segments, joinStyle, mitreLimit ) );
|
||||
}
|
||||
CATCH_GEOS( 0 )
|
||||
}
|
||||
|
||||
QgsGeometry* QgsGeometry::simplify( double tolerance )
|
||||
{
|
||||
if ( mDirtyGeos )
|
||||
|
@ -355,6 +355,9 @@ class CORE_EXPORT QgsGeometry
|
||||
of segments used to approximate curves */
|
||||
QgsGeometry* buffer( double distance, int segments );
|
||||
|
||||
/** Returns an offset line at a given distance and side from an input line. */
|
||||
QgsGeometry* offsetCurve( double distance, int segments, int joinStyle, double mitreLimit );
|
||||
|
||||
/** Returns a simplified version of this geometry using a specified tolerance value */
|
||||
QgsGeometry* simplify( double tolerance );
|
||||
|
||||
|
@ -1927,7 +1927,13 @@ void QgsPalLayerSettings::registerFeature( QgsFeature& f, const QgsRenderContext
|
||||
// fix invalid polygons
|
||||
if ( geom->type() == QGis::Polygon && !geom->isGeosValid() )
|
||||
{
|
||||
geom->fromGeos( GEOSBuffer( geom->asGeos(), 0, 0 ) );
|
||||
QgsGeometry* bufferGeom = geom->buffer( 0, 0 );
|
||||
if ( !bufferGeom )
|
||||
{
|
||||
return;
|
||||
}
|
||||
geom = bufferGeom;
|
||||
clonedGeometry.reset( geom );
|
||||
}
|
||||
|
||||
// CLIP the geometry if it is bigger than the extent
|
||||
@ -1938,11 +1944,13 @@ void QgsPalLayerSettings::registerFeature( QgsFeature& f, const QgsRenderContext
|
||||
do_clip = !extentGeom->contains( geom );
|
||||
if ( do_clip )
|
||||
{
|
||||
geom = geom->intersection( extentGeom ); // creates new geometry
|
||||
if ( !geom )
|
||||
QgsGeometry* clipGeom = geom->intersection( extentGeom ); // creates new geometry
|
||||
if ( !clipGeom )
|
||||
{
|
||||
return;
|
||||
}
|
||||
geom = clipGeom;
|
||||
clonedGeometry.reset( geom );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -705,15 +705,15 @@ QList<QPolygonF> offsetLine( QPolygonF polyline, double dist, QGis::GeometryType
|
||||
for ( i = 0; i < pointCount; ++i, tempPtr++ )
|
||||
tempPolyline[i] = QgsPoint( tempPtr->rx(), tempPtr->ry() );
|
||||
|
||||
QgsGeometry * tempGeometry = ( geometryType == QGis::Polygon ) ? QgsGeometry::fromPolygon( QgsPolygon() << tempPolyline ) : QgsGeometry::fromPolyline( tempPolyline );
|
||||
QgsGeometry* tempGeometry = ( geometryType == QGis::Polygon ) ? QgsGeometry::fromPolygon( QgsPolygon() << tempPolyline ) : QgsGeometry::fromPolyline( tempPolyline );
|
||||
if ( tempGeometry )
|
||||
{
|
||||
const GEOSGeometry* geosGeom = tempGeometry->asGeos();
|
||||
GEOSGeometry* offsetGeom = ( geometryType == QGis::Polygon ) ? GEOSBuffer( geosGeom, -dist, 8 /*quadSegments*/ ) : GEOSOffsetCurve( geosGeom, dist, 8 /*quadSegments*/, 0 /*joinStyle*/, 5.0 /*mitreLimit*/ );
|
||||
QgsGeometry* offsetGeom = ( geometryType == QGis::Polygon ) ? tempGeometry->buffer( -dist, 8 /*quadSegments*/ ) : tempGeometry->offsetCurve( dist, 8 /*quadSegments*/, 0 /*joinStyle*/, 5.0 /*mitreLimit*/ );
|
||||
|
||||
if ( offsetGeom )
|
||||
{
|
||||
tempGeometry->fromGeos( offsetGeom );
|
||||
delete tempGeometry;
|
||||
tempGeometry = offsetGeom;
|
||||
|
||||
if ( QGis::flatType( tempGeometry->wkbType() ) == QGis::WKBLineString )
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user