Skip to content

Commit

Permalink
- fix issue 7244
Browse files Browse the repository at this point in the history
  • Loading branch information
vmora committed Jul 11, 2013
1 parent 20b45c3 commit 5256b80
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 21 deletions.
24 changes: 8 additions & 16 deletions src/core/qgsgeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5401,22 +5401,6 @@ int QgsGeometry::splitPolygonGeometry( GEOSGeometry* splitLine, QList<QgsGeometr
return 2; //an error occured during noding
}

#if defined(GEOS_VERSION_MAJOR) && defined(GEOS_VERSION_MINOR) && \
((GEOS_VERSION_MAJOR>3) || ((GEOS_VERSION_MAJOR==3) && (GEOS_VERSION_MINOR>=1)))
GEOSGeometry *cutEdges = GEOSPolygonizer_getCutEdges( &nodedGeometry, 1 );
if ( cutEdges )
{
if ( numberOfGeometries( cutEdges ) > 0 )
{
GEOSGeom_destroy( cutEdges );
GEOSGeom_destroy( nodedGeometry );
return 3;
}

GEOSGeom_destroy( cutEdges );
}
#endif

GEOSGeometry *polygons = GEOSPolygonize( &nodedGeometry, 1 );
if ( !polygons || numberOfGeometries( polygons ) == 0 )
{
Expand Down Expand Up @@ -5486,6 +5470,14 @@ int QgsGeometry::splitPolygonGeometry( GEOSGeometry* splitLine, QList<QgsGeometr
mDirtyWkb = true;
}

for ( int i = 1; i < testedGeometries.size(); ++i )
{
if ( GEOSisValid( testedGeometries[i] ) != 1 )
{
return 3;
}
}

for ( int i = 1; i < testedGeometries.size(); ++i )
{
newGeometries << fromGeosGeom( testedGeometries[i] );
Expand Down
28 changes: 23 additions & 5 deletions tests/src/python/test_qgsissue7244.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,19 @@ def setUpClass(cls):
sql += str(i+1) + " " + str(j) + ","
sql += str(i+1) + " " + str(j+1) + ","
sql += str(i) + " " + str(j+1) + ","
sql += str(i) + " " + str(j)
sql += str(i) + " " + str(j)
sql += ")),"
sql = sql[:-1] # remove last comma
sql += ")', 4326))"
cur.execute(sql)


sql = "CREATE TABLE test_pg (id SERIAL PRIMARY KEY, name STRING NOT NULL)"
cur.execute(sql)
sql = "SELECT AddGeometryColumn('test_pg', 'geometry', 4326, 'POLYGON', 'XY')"
cur.execute(sql)
sql = "INSERT INTO test_pg (name, geometry) "
sql += "VALUES ('polygon with interior ring', GeomFromText('POLYGON((0 0,3 0,3 3,0 3,0 0),(1 1,1 2,2 2,2 1,1 1))', 4326))"
cur.execute(sql)
con.commit()
con.close()

Expand All @@ -85,16 +92,27 @@ def tearDown(self):
pass

def test_SplitMultipolygon(self):
"""Create spatialite database"""
"""Split multipolygon"""
layer = QgsVectorLayer("dbname=test.sqlite table=test_mpg (geometry)", "test_mpg", "spatialite")
assert(layer.isValid())
assert(layer.hasGeometryType())
layer.featureCount() == 1 or die("we should have 1 features")
layer.featureCount() == 1 or die("wrong number of features")
layer.startEditing()
layer.splitFeatures([QgsPoint(0.5, -0.5), QgsPoint(0.5, 1.5)], 0)==0 or die("error in split of one polygon of multipolygon")
layer.splitFeatures([QgsPoint(2.5, -0.5), QgsPoint(2.5, 4)], 0)==0 or die("error in split of two polygons of multipolygon at a time")
layer.commitChanges() or die("this commit should work")
#layer.featureCount() == 9 or die("we should have 9 features after 2 split")
layer.featureCount() == 7 or die("wrong number of features after 2 split")

def test_SplitTruToCreateCutEdge(self):
"""Try to creat a cut edge"""
layer = QgsVectorLayer("dbname=test.sqlite table=test_pg (geometry)", "test_pg", "spatialite")
assert(layer.isValid())
assert(layer.hasGeometryType())
layer.featureCount() == 1 or die("wrong number of features")
layer.startEditing()
layer.splitFeatures([QgsPoint(1.5, -0.5), QgsPoint(1.5, 1.5)], 0)==0 or die("error when trying to create an invalid polygon in split")
layer.commitChanges() or die("this commit should work")
layer.featureCount() == 1 or die("wrong number of features, polygon should be unafected by cut")



Expand Down

0 comments on commit 5256b80

Please sign in to comment.