Skip to content
Permalink
Browse files
Even more geos exceptions
  • Loading branch information
mhugent committed Jun 5, 2015
1 parent 476ee1d commit 1cd4fd6e73dfdc16ded5599b044d7da2c253ef79
Showing with 90 additions and 76 deletions.
  1. +90 −76 src/core/geometry/qgsgeos.cpp
@@ -188,9 +188,14 @@ QgsAbstractGeometryV2* QgsGeos::combine( const QList< const QgsAbstractGeometryV
geosGeometries[i] = asGeos( geomList.at( i ) );
}

GEOSGeometry* geomCollection = createGeosCollection( GEOS_GEOMETRYCOLLECTION, geosGeometries );
GEOSGeometry* geomUnion = GEOSUnaryUnion_r( geosinit.ctxt, geomCollection );
GEOSGeom_destroy_r( geosinit.ctxt, geomCollection );
GEOSGeometry* geomUnion = 0;
try
{
GEOSGeometry* geomCollection = createGeosCollection( GEOS_GEOMETRYCOLLECTION, geosGeometries );
geomUnion = GEOSUnaryUnion_r( geosinit.ctxt, geomCollection );
GEOSGeom_destroy_r( geosinit.ctxt, geomCollection );
}
CATCH_GEOS( 0 )

QgsAbstractGeometryV2* result = fromGeos( geomUnion );
GEOSGeom_destroy_r( geosinit.ctxt, geomUnion );
@@ -385,46 +390,51 @@ int QgsGeos::topologicalTestPointsSplit( const GEOSGeometry* splitLine, QList<Qg
return 1;
}

testPoints.clear();
GEOSGeometry* intersectionGeom = GEOSIntersection_r( geosinit.ctxt, mGeos, splitLine );
if ( !intersectionGeom )
return 1;

bool simple = false;
int nIntersectGeoms = 1;
if ( GEOSGeomTypeId_r( geosinit.ctxt, intersectionGeom ) == GEOS_LINESTRING
|| GEOSGeomTypeId_r( geosinit.ctxt, intersectionGeom ) == GEOS_POINT )
simple = true;
try
{
testPoints.clear();
GEOSGeometry* intersectionGeom = GEOSIntersection_r( geosinit.ctxt, mGeos, splitLine );
if ( !intersectionGeom )
return 1;

if ( !simple )
nIntersectGeoms = GEOSGetNumGeometries_r( geosinit.ctxt, intersectionGeom );
bool simple = false;
int nIntersectGeoms = 1;
if ( GEOSGeomTypeId_r( geosinit.ctxt, intersectionGeom ) == GEOS_LINESTRING
|| GEOSGeomTypeId_r( geosinit.ctxt, intersectionGeom ) == GEOS_POINT )
simple = true;

for ( int i = 0; i < nIntersectGeoms; ++i )
{
const GEOSGeometry* currentIntersectGeom;
if ( simple )
currentIntersectGeom = intersectionGeom;
else
currentIntersectGeom = GEOSGetGeometryN_r( geosinit.ctxt, intersectionGeom, i );
if ( !simple )
nIntersectGeoms = GEOSGetNumGeometries_r( geosinit.ctxt, intersectionGeom );

const GEOSCoordSequence* lineSequence = GEOSGeom_getCoordSeq_r( geosinit.ctxt, currentIntersectGeom );
unsigned int sequenceSize = 0;
double x, y;
if ( GEOSCoordSeq_getSize_r( geosinit.ctxt, lineSequence, &sequenceSize ) != 0 )
for ( int i = 0; i < nIntersectGeoms; ++i )
{
for ( unsigned int i = 0; i < sequenceSize; ++i )
const GEOSGeometry* currentIntersectGeom;
if ( simple )
currentIntersectGeom = intersectionGeom;
else
currentIntersectGeom = GEOSGetGeometryN_r( geosinit.ctxt, intersectionGeom, i );

const GEOSCoordSequence* lineSequence = GEOSGeom_getCoordSeq_r( geosinit.ctxt, currentIntersectGeom );
unsigned int sequenceSize = 0;
double x, y;
if ( GEOSCoordSeq_getSize_r( geosinit.ctxt, lineSequence, &sequenceSize ) != 0 )
{
if ( GEOSCoordSeq_getX_r( geosinit.ctxt, lineSequence, i, &x ) != 0 )
for ( unsigned int i = 0; i < sequenceSize; ++i )
{
if ( GEOSCoordSeq_getY_r( geosinit.ctxt, lineSequence, i, &y ) != 0 )
if ( GEOSCoordSeq_getX_r( geosinit.ctxt, lineSequence, i, &x ) != 0 )
{
testPoints.push_back( QgsPointV2( x, y ) );
if ( GEOSCoordSeq_getY_r( geosinit.ctxt, lineSequence, i, &y ) != 0 )
{
testPoints.push_back( QgsPointV2( x, y ) );
}
}
}
}
}
GEOSGeom_destroy_r( geosinit.ctxt, intersectionGeom );
}
GEOSGeom_destroy_r( geosinit.ctxt, intersectionGeom );
CATCH_GEOS( 1 )

return 0;
}

@@ -1526,61 +1536,65 @@ QgsAbstractGeometryV2* QgsGeos::reshapeGeometry( const QgsLineStringV2& reshapeW
}
else
{
//call reshape for each geometry part and replace mGeos with new geometry if reshape took place
bool reshapeTookPlace = false;
try
{
//call reshape for each geometry part and replace mGeos with new geometry if reshape took place
bool reshapeTookPlace = false;

GEOSGeometry* currentReshapeGeometry = 0;
GEOSGeometry** newGeoms = new GEOSGeometry*[numGeoms];
GEOSGeometry* currentReshapeGeometry = 0;
GEOSGeometry** newGeoms = new GEOSGeometry*[numGeoms];

for ( int i = 0; i < numGeoms; ++i )
{
if ( isLine )
currentReshapeGeometry = reshapeLine( GEOSGetGeometryN_r( geosinit.ctxt, mGeos, i ), reshapeLineGeos );
else
currentReshapeGeometry = reshapePolygon( GEOSGetGeometryN_r( geosinit.ctxt, mGeos, i ), reshapeLineGeos );
for ( int i = 0; i < numGeoms; ++i )
{
if ( isLine )
currentReshapeGeometry = reshapeLine( GEOSGetGeometryN_r( geosinit.ctxt, mGeos, i ), reshapeLineGeos );
else
currentReshapeGeometry = reshapePolygon( GEOSGetGeometryN_r( geosinit.ctxt, mGeos, i ), reshapeLineGeos );

if ( currentReshapeGeometry )
{
newGeoms[i] = currentReshapeGeometry;
reshapeTookPlace = true;
}
else
{
newGeoms[i] = GEOSGeom_clone_r( geosinit.ctxt, GEOSGetGeometryN( mGeos, i ) );
}
}
GEOSGeom_destroy_r( geosinit.ctxt, reshapeLineGeos );

if ( currentReshapeGeometry )
GEOSGeometry* newMultiGeom = 0;
if ( isLine )
{
newGeoms[i] = currentReshapeGeometry;
reshapeTookPlace = true;
newMultiGeom = GEOSGeom_createCollection_r( geosinit.ctxt, GEOS_MULTILINESTRING, newGeoms, numGeoms );
}
else
else //multipolygon
{
newGeoms[i] = GEOSGeom_clone_r( geosinit.ctxt, GEOSGetGeometryN( mGeos, i ) );
newMultiGeom = GEOSGeom_createCollection_r( geosinit.ctxt, GEOS_MULTIPOLYGON, newGeoms, numGeoms );
}
}
GEOSGeom_destroy_r( geosinit.ctxt, reshapeLineGeos );

GEOSGeometry* newMultiGeom = 0;
if ( isLine )
{
newMultiGeom = GEOSGeom_createCollection_r( geosinit.ctxt, GEOS_MULTILINESTRING, newGeoms, numGeoms );
}
else //multipolygon
{
newMultiGeom = GEOSGeom_createCollection_r( geosinit.ctxt, GEOS_MULTIPOLYGON, newGeoms, numGeoms );
}

delete[] newGeoms;
if ( !newMultiGeom )
{
if ( errorCode ) { *errorCode = 3; }
return 0;
}
delete[] newGeoms;
if ( !newMultiGeom )
{
if ( errorCode ) { *errorCode = 3; }
return 0;
}

if ( reshapeTookPlace )
{
if ( errorCode ) { *errorCode = 0; }
QgsAbstractGeometryV2* reshapedMultiGeom = fromGeos( newMultiGeom );
GEOSGeom_destroy_r( geosinit.ctxt, newMultiGeom );
return reshapedMultiGeom;
}
else
{
GEOSGeom_destroy_r( geosinit.ctxt, newMultiGeom );
if ( errorCode ) { *errorCode = 1; }
return 0;
if ( reshapeTookPlace )
{
if ( errorCode ) { *errorCode = 0; }
QgsAbstractGeometryV2* reshapedMultiGeom = fromGeos( newMultiGeom );
GEOSGeom_destroy_r( geosinit.ctxt, newMultiGeom );
return reshapedMultiGeom;
}
else
{
GEOSGeom_destroy_r( geosinit.ctxt, newMultiGeom );
if ( errorCode ) { *errorCode = 1; }
return 0;
}
}
CATCH_GEOS( 0 )
}
return 0;
}

4 comments on commit 1cd4fd6

@nirvn

This comment has been minimized.

Copy link
Contributor

@nirvn nirvn replied Jun 5, 2015

Hmm, I'll file an issue tomorrow but as of this commit, a multipolygon shapefile with one polygon fails to render its main part.

Possibly not related to this specific commit but it's a less-than-a-week regression.

@mhugent

This comment has been minimized.

Copy link
Contributor Author

@mhugent mhugent replied Jun 5, 2015

When you file the issue, please add a small testshape to reproduce.

@nirvn

This comment has been minimized.

Copy link
Contributor

@nirvn nirvn replied Jun 5, 2015

@mhugent, yep. I m not in front of my laptop atm but I think my build was as of the "more geos exception" commit, not this one. With a bit of luck this commit we're discussing on fixed the rendering :)

@nirvn

This comment has been minimized.

Copy link
Contributor

@nirvn nirvn replied Jun 6, 2015

@mhugent, I've compiled a new build that includes this commit, and the regression is still present. I therefore filed a bug and included the shapefile exhibiting the blocking regression: http://hub.qgis.org/issues/12896

Please sign in to comment.