Skip to content

Commit ed1d08d

Browse files
committedJun 17, 2014
Fix #10605 (round corners when using simple line with offset)
1 parent fb5cca2 commit ed1d08d

File tree

4 files changed

+60
-10
lines changed

4 files changed

+60
-10
lines changed
 

‎python/core/qgsgeometry.sip

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,21 @@ 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. */
317+
/** Returns a buffer region around the geometry, with additional style options.
318+
* @param segments For round joins, number of segments to approximate quarter-circle
319+
* @param endCapStyle Round (1) / Flat (2) / Square (3) end cap style
320+
* @param joinStyle Round (1) / Mitre (2) / Bevel (3) join style
321+
* @param mitreLimit Limit on the mitre ratio used for very sharp corners
322+
* @note added in 2.4
323+
* @note needs GEOS >= 3.3 - otherwise always returns 0
324+
*/
325+
QgsGeometry* buffer( double distance, int segments, int endCapStyle, int joinStyle, double mitreLimit ) /Factory/;
326+
327+
/** Returns an offset line at a given distance and side from an input line.
328+
* See buffer() method for details on parameters.
329+
* @note added in 2.4
330+
* @note needs GEOS >= 3.3 - otherwise always returns 0
331+
*/
318332
QgsGeometry* offsetCurve( double distance, int segments, int joinStyle, double mitreLimit ) /Factory/;
319333

320334
/** Returns a simplified version of this geometry using a specified tolerance value */

‎src/core/qgsgeometry.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5594,10 +5594,30 @@ QgsGeometry* QgsGeometry::buffer( double distance, int segments )
55945594
CATCH_GEOS( 0 )
55955595
}
55965596

5597+
QgsGeometry*QgsGeometry::buffer( double distance, int segments, int endCapStyle, int joinStyle, double mitreLimit )
5598+
{
55975599
#if defined(GEOS_VERSION_MAJOR) && defined(GEOS_VERSION_MINOR) && \
55985600
((GEOS_VERSION_MAJOR>3) || ((GEOS_VERSION_MAJOR==3) && (GEOS_VERSION_MINOR>=3)))
5601+
if ( mDirtyGeos )
5602+
exportWkbToGeos();
5603+
5604+
if ( !mGeos )
5605+
return 0;
5606+
5607+
try
5608+
{
5609+
return fromGeosGeom( GEOSBufferWithStyle( mGeos, distance, segments, endCapStyle, joinStyle, mitreLimit ) );
5610+
}
5611+
CATCH_GEOS( 0 )
5612+
#else
5613+
return 0;
5614+
#endif
5615+
}
5616+
55995617
QgsGeometry* QgsGeometry::offsetCurve( double distance, int segments, int joinStyle, double mitreLimit )
56005618
{
5619+
#if defined(GEOS_VERSION_MAJOR) && defined(GEOS_VERSION_MINOR) && \
5620+
((GEOS_VERSION_MAJOR>3) || ((GEOS_VERSION_MAJOR==3) && (GEOS_VERSION_MINOR>=3)))
56015621
if ( mDirtyGeos )
56025622
exportWkbToGeos();
56035623

@@ -5609,8 +5629,10 @@ QgsGeometry* QgsGeometry::offsetCurve( double distance, int segments, int joinSt
56095629
return fromGeosGeom( GEOSOffsetCurve( mGeos, distance, segments, joinStyle, mitreLimit ) );
56105630
}
56115631
CATCH_GEOS( 0 )
5612-
}
5632+
#else
5633+
return 0;
56135634
#endif
5635+
}
56145636

56155637
QgsGeometry* QgsGeometry::simplify( double tolerance )
56165638
{

‎src/core/qgsgeometry.h

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

358-
#if defined(GEOS_VERSION_MAJOR) && defined(GEOS_VERSION_MINOR) && \
359-
((GEOS_VERSION_MAJOR>3) || ((GEOS_VERSION_MAJOR==3) && (GEOS_VERSION_MINOR>=3)))
360-
/** Returns an offset line at a given distance and side from an input line (uses GEOS)
361-
@note added in 2.3
362-
@note only available with GEOS >= 3.3
363-
*/
358+
/** Returns a buffer region around the geometry, with additional style options.
359+
* @param segments For round joins, number of segments to approximate quarter-circle
360+
* @param endCapStyle Round (1) / Flat (2) / Square (3) end cap style
361+
* @param joinStyle Round (1) / Mitre (2) / Bevel (3) join style
362+
* @param mitreLimit Limit on the mitre ratio used for very sharp corners
363+
* @note added in 2.4
364+
* @note needs GEOS >= 3.3 - otherwise always returns 0
365+
*/
366+
QgsGeometry* buffer( double distance, int segments, int endCapStyle, int joinStyle, double mitreLimit );
367+
368+
/** Returns an offset line at a given distance and side from an input line.
369+
* See buffer() method for details on parameters.
370+
* @note added in 2.4
371+
* @note needs GEOS >= 3.3 - otherwise always returns 0
372+
*/
364373
QgsGeometry* offsetCurve( double distance, int segments, int joinStyle, double mitreLimit );
365-
#endif
366374

367375
/** Returns a simplified version of this geometry using a specified tolerance value */
368376
QgsGeometry* simplify( double tolerance );

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,13 @@ QList<QPolygonF> offsetLine( QPolygonF polyline, double dist, QGis::GeometryType
708708
QgsGeometry* tempGeometry = ( geometryType == QGis::Polygon ) ? QgsGeometry::fromPolygon( QgsPolygon() << tempPolyline ) : QgsGeometry::fromPolyline( tempPolyline );
709709
if ( tempGeometry )
710710
{
711-
QgsGeometry* offsetGeom = ( geometryType == QGis::Polygon ) ? tempGeometry->buffer( -dist, 8 /*quadSegments*/ ) : tempGeometry->offsetCurve( dist, 8 /*quadSegments*/, 0 /*joinStyle*/, 5.0 /*mitreLimit*/ );
711+
int quadSegments = 0; // we want mitre joins, not round joins
712+
double mitreLimit = 2.0; // the default value in GEOS (5.0) allows for fairly sharp endings
713+
QgsGeometry* offsetGeom = 0;
714+
if ( geometryType == QGis::Polygon )
715+
offsetGeom = tempGeometry->buffer( -dist, quadSegments, GEOSBUF_CAP_FLAT, GEOSBUF_JOIN_MITRE, mitreLimit );
716+
else
717+
offsetGeom = tempGeometry->offsetCurve( dist, quadSegments, GEOSBUF_JOIN_MITRE, mitreLimit );
712718

713719
if ( offsetGeom )
714720
{

0 commit comments

Comments
 (0)
Please sign in to comment.