Skip to content

Commit

Permalink
Merge pull request #1451 from ahuarte47/Issue_OffsetCurve_API
Browse files Browse the repository at this point in the history
Replace GEOS function calls by QgsGeometry class methods
  • Loading branch information
wonder-sk committed Jun 15, 2014
2 parents 9e3f921 + ea34bef commit 9d8a842
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 7 deletions.
3 changes: 3 additions & 0 deletions python/core/qgsgeometry.sip
Expand Up @@ -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/;

Expand Down
15 changes: 15 additions & 0 deletions src/core/qgsgeometry.cpp
Expand Up @@ -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 )
Expand Down
3 changes: 3 additions & 0 deletions src/core/qgsgeometry.h
Expand Up @@ -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 );

Expand Down
14 changes: 11 additions & 3 deletions src/core/qgspallabeling.cpp
Expand Up @@ -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
Expand All @@ -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 );
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/core/symbology-ng/qgssymbollayerv2utils.cpp
Expand Up @@ -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 )
{
Expand Down

0 comments on commit 9d8a842

Please sign in to comment.