Skip to content

Commit

Permalink
Replace GEOS function calls by QgsGeometry class methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ahuarte47 committed Jun 13, 2014
1 parent 95687a2 commit aaf4ca3
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 4 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
11 changes: 10 additions & 1 deletion src/core/qgspallabeling.cpp
Expand Up @@ -1927,7 +1927,16 @@ 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 )
{
size_t wkbSize = bufferGeom->wkbSize();
unsigned char* wkb = ( unsigned char* )malloc( wkbSize );
memcpy( wkb, bufferGeom->asWkb(), wkbSize );
geom->fromWkb( wkb, wkbSize );
delete bufferGeom;
}
}

// CLIP the geometry if it is bigger than the extent
Expand Down
6 changes: 3 additions & 3 deletions src/core/symbology-ng/qgssymbollayerv2utils.cpp
Expand Up @@ -708,12 +708,12 @@ QList<QPolygonF> offsetLine( QPolygonF polyline, double dist, QGis::GeometryType
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 aaf4ca3

Please sign in to comment.