@@ -682,8 +682,7 @@ static QList<QPolygonF> makeOffsetGeometry( const QgsPolygon& polygon )
682
682
}
683
683
#endif
684
684
685
-
686
- QList<QPolygonF> offsetLine ( QPolygonF polyline, double dist )
685
+ QList<QPolygonF> offsetLine ( QPolygonF polyline, double dist, QGis::GeometryType geometryType )
687
686
{
688
687
QList<QPolygonF> resultLine;
689
688
@@ -701,19 +700,16 @@ QList<QPolygonF> offsetLine( QPolygonF polyline, double dist )
701
700
702
701
unsigned int i, pointCount = polyline.count ();
703
702
704
- bool isaLinearRing = false ;
705
- if ( polyline[0 ].x () == polyline[ pointCount - 1 ].x () && polyline[0 ].y () == polyline[ pointCount - 1 ].y () ) isaLinearRing = true ;
706
-
707
703
QgsPolyline tempPolyline ( pointCount );
708
704
QPointF* tempPtr = polyline.data ();
709
705
for ( i = 0 ; i < pointCount; ++i, tempPtr++ )
710
706
tempPolyline[i] = QgsPoint ( tempPtr->rx (), tempPtr->ry () );
711
707
712
- QgsGeometry* tempGeometry = isaLinearRing ? QgsGeometry::fromPolygon ( QgsPolygon () << tempPolyline ) : QgsGeometry::fromPolyline ( tempPolyline );
708
+ QgsGeometry * tempGeometry = ( geometryType == QGis::Polygon ) ? QgsGeometry::fromPolygon ( QgsPolygon () << tempPolyline ) : QgsGeometry::fromPolyline ( tempPolyline );
713
709
if ( tempGeometry )
714
710
{
715
711
const GEOSGeometry* geosGeom = tempGeometry->asGeos ();
716
- GEOSGeometry* offsetGeom = isaLinearRing ? GEOSBuffer ( geosGeom, -dist, 8 /* quadSegments*/ ) : GEOSOffsetCurve ( geosGeom, dist, 8 /* quadSegments*/ , 0 /* joinStyle*/ , 5.0 /* mitreLimit*/ );
712
+ GEOSGeometry* offsetGeom = ( geometryType == QGis::Polygon ) ? GEOSBuffer ( geosGeom, -dist, 8 /* quadSegments*/ ) : GEOSOffsetCurve ( geosGeom, dist, 8 /* quadSegments*/ , 0 /* joinStyle*/ , 5.0 /* mitreLimit*/ );
717
713
718
714
if ( offsetGeom )
719
715
{
@@ -803,6 +799,21 @@ QList<QPolygonF> offsetLine( QPolygonF polyline, double dist )
803
799
804
800
#endif
805
801
}
802
+ QList<QPolygonF> offsetLine ( QPolygonF polyline, double dist )
803
+ {
804
+ QGis::GeometryType geometryType = QGis::Point ;
805
+ int pointCount = polyline.count ();
806
+
807
+ if ( pointCount > 3 && polyline[ 0 ].x () == polyline[ pointCount - 1 ].x () && polyline[ 0 ].y () == polyline[ pointCount - 1 ].y () )
808
+ {
809
+ geometryType = QGis::Polygon;
810
+ }
811
+ else if ( pointCount > 1 )
812
+ {
813
+ geometryType = QGis::Line;
814
+ }
815
+ return offsetLine ( polyline, dist, geometryType );
816
+ }
806
817
807
818
// ///
808
819
0 commit comments