Skip to content
Permalink
Browse files
Replace GEOS function calls by QgsGeometry class methods
  • Loading branch information
ahuarte47 committed Jun 13, 2014
1 parent 95687a2 commit aaf4ca382183f71bc7fcdb58412bd5307225cc96
@@ -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,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
@@ -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 )
{

0 comments on commit aaf4ca3

Please sign in to comment.