Skip to content

Commit

Permalink
restore behavior of QgsGeometry::combine on line strings (fixes #13274)
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Oct 5, 2015
1 parent 52e7628 commit ac3f390
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
3 changes: 0 additions & 3 deletions src/core/geometry/qgsgeometry.cpp
Expand Up @@ -2297,6 +2297,3 @@ QDataStream& operator>>( QDataStream& in, QgsGeometry& geometry )
geometry.fromWkb(( unsigned char* )data, byteArray.size() );
return in;
}



18 changes: 16 additions & 2 deletions src/core/geometry/qgsgeos.cpp
Expand Up @@ -1083,8 +1083,22 @@ QgsAbstractGeometryV2* QgsGeos::overlay( const QgsAbstractGeometryV2& geom, Over
opGeom.reset( GEOSDifference_r( geosinit.ctxt, mGeos, geosGeom.get() ) );
break;
case UNION:
opGeom.reset( GEOSUnion_r( geosinit.ctxt, mGeos, geosGeom.get() ) );
break;
{
GEOSGeometry *unionGeometry = GEOSUnion_r( geosinit.ctxt, mGeos, geosGeom.get() );

if ( unionGeometry && GEOSGeomTypeId_r( geosinit.ctxt, unionGeometry ) == GEOS_MULTILINESTRING )
{
GEOSGeometry *mergedLines = GEOSLineMerge_r( geosinit.ctxt, unionGeometry );
if ( mergedLines )
{
GEOSGeom_destroy_r( geosinit.ctxt, unionGeometry );
unionGeometry = mergedLines;
}
}

opGeom.reset( unionGeometry );
}
break;
case SYMDIFFERENCE:
opGeom.reset( GEOSSymDifference_r( geosinit.ctxt, mGeos, geosGeom.get() ) );
break;
Expand Down
12 changes: 12 additions & 0 deletions tests/src/python/test_qgsgeometry.py
Expand Up @@ -1377,5 +1377,17 @@ def testRegression13055(self):
wkt = p.exportToWkt()
assert compareWkt(expWkt, wkt), "testRegression13055 failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt)

def testRegression13274(self):
""" See http://hub.qgis.org/issues/13274
Testing that two combined linestrings produce another line string if possible
"""
a = QgsGeometry.fromWkt('LineString (0 0, 1 0)')
b = QgsGeometry.fromWkt('LineString (1 0, 2 0)')
c = a.combine(b)

expWkt = 'LineString (0 0, 1 0, 2 0)'
wkt = c.exportToWkt()
assert compareWkt(expWkt, wkt), "testRegression13274 failed: mismatch Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt)

if __name__ == '__main__':
unittest.main()

0 comments on commit ac3f390

Please sign in to comment.