Skip to content

Commit 9d8a842

Browse files
committedJun 15, 2014
Merge pull request #1451 from ahuarte47/Issue_OffsetCurve_API
Replace GEOS function calls by QgsGeometry class methods
2 parents 9e3f921 + ea34bef commit 9d8a842

File tree

5 files changed

+36
-7
lines changed

5 files changed

+36
-7
lines changed
 

‎python/core/qgsgeometry.sip

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,9 @@ class QgsGeometry
314314
of segments used to approximate curves */
315315
QgsGeometry* buffer( double distance, int segments ) /Factory/;
316316

317+
/** Returns an offset line at a given distance and side from an input line. */
318+
QgsGeometry* offsetCurve( double distance, int segments, int joinStyle, double mitreLimit ) /Factory/;
319+
317320
/** Returns a simplified version of this geometry using a specified tolerance value */
318321
QgsGeometry* simplify( double tolerance ) /Factory/;
319322

‎src/core/qgsgeometry.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5594,6 +5594,21 @@ QgsGeometry* QgsGeometry::buffer( double distance, int segments )
55945594
CATCH_GEOS( 0 )
55955595
}
55965596

5597+
QgsGeometry* QgsGeometry::offsetCurve( double distance, int segments, int joinStyle, double mitreLimit )
5598+
{
5599+
if ( mDirtyGeos )
5600+
exportWkbToGeos();
5601+
5602+
if ( !mGeos || this->type() != QGis::Line )
5603+
return 0;
5604+
5605+
try
5606+
{
5607+
return fromGeosGeom( GEOSOffsetCurve( mGeos, distance, segments, joinStyle, mitreLimit ) );
5608+
}
5609+
CATCH_GEOS( 0 )
5610+
}
5611+
55975612
QgsGeometry* QgsGeometry::simplify( double tolerance )
55985613
{
55995614
if ( mDirtyGeos )

‎src/core/qgsgeometry.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,9 @@ class CORE_EXPORT QgsGeometry
355355
of segments used to approximate curves */
356356
QgsGeometry* buffer( double distance, int segments );
357357

358+
/** Returns an offset line at a given distance and side from an input line. */
359+
QgsGeometry* offsetCurve( double distance, int segments, int joinStyle, double mitreLimit );
360+
358361
/** Returns a simplified version of this geometry using a specified tolerance value */
359362
QgsGeometry* simplify( double tolerance );
360363

‎src/core/qgspallabeling.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1927,7 +1927,13 @@ void QgsPalLayerSettings::registerFeature( QgsFeature& f, const QgsRenderContext
19271927
// fix invalid polygons
19281928
if ( geom->type() == QGis::Polygon && !geom->isGeosValid() )
19291929
{
1930-
geom->fromGeos( GEOSBuffer( geom->asGeos(), 0, 0 ) );
1930+
QgsGeometry* bufferGeom = geom->buffer( 0, 0 );
1931+
if ( !bufferGeom )
1932+
{
1933+
return;
1934+
}
1935+
geom = bufferGeom;
1936+
clonedGeometry.reset( geom );
19311937
}
19321938

19331939
// CLIP the geometry if it is bigger than the extent
@@ -1938,11 +1944,13 @@ void QgsPalLayerSettings::registerFeature( QgsFeature& f, const QgsRenderContext
19381944
do_clip = !extentGeom->contains( geom );
19391945
if ( do_clip )
19401946
{
1941-
geom = geom->intersection( extentGeom ); // creates new geometry
1942-
if ( !geom )
1947+
QgsGeometry* clipGeom = geom->intersection( extentGeom ); // creates new geometry
1948+
if ( !clipGeom )
19431949
{
19441950
return;
19451951
}
1952+
geom = clipGeom;
1953+
clonedGeometry.reset( geom );
19461954
}
19471955
}
19481956

‎src/core/symbology-ng/qgssymbollayerv2utils.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -705,15 +705,15 @@ QList<QPolygonF> offsetLine( QPolygonF polyline, double dist, QGis::GeometryType
705705
for ( i = 0; i < pointCount; ++i, tempPtr++ )
706706
tempPolyline[i] = QgsPoint( tempPtr->rx(), tempPtr->ry() );
707707

708-
QgsGeometry * tempGeometry = ( geometryType == QGis::Polygon ) ? QgsGeometry::fromPolygon( QgsPolygon() << tempPolyline ) : QgsGeometry::fromPolyline( tempPolyline );
708+
QgsGeometry* tempGeometry = ( geometryType == QGis::Polygon ) ? QgsGeometry::fromPolygon( QgsPolygon() << tempPolyline ) : QgsGeometry::fromPolyline( tempPolyline );
709709
if ( tempGeometry )
710710
{
711-
const GEOSGeometry* geosGeom = tempGeometry->asGeos();
712-
GEOSGeometry* offsetGeom = ( geometryType == QGis::Polygon ) ? GEOSBuffer( geosGeom, -dist, 8 /*quadSegments*/ ) : GEOSOffsetCurve( geosGeom, dist, 8 /*quadSegments*/, 0 /*joinStyle*/, 5.0 /*mitreLimit*/ );
711+
QgsGeometry* offsetGeom = ( geometryType == QGis::Polygon ) ? tempGeometry->buffer( -dist, 8 /*quadSegments*/ ) : tempGeometry->offsetCurve( dist, 8 /*quadSegments*/, 0 /*joinStyle*/, 5.0 /*mitreLimit*/ );
713712

714713
if ( offsetGeom )
715714
{
716-
tempGeometry->fromGeos( offsetGeom );
715+
delete tempGeometry;
716+
tempGeometry = offsetGeom;
717717

718718
if ( QGis::flatType( tempGeometry->wkbType() ) == QGis::WKBLineString )
719719
{

0 commit comments

Comments
 (0)
Please sign in to comment.