Fix fromGeos returning 0 for x/y on empty point

This commit is contained in:
Alessandro Pasotti 2021-02-04 18:52:38 +01:00 committed by Nyall Dawson
parent bdccd78c54
commit a89d564934
2 changed files with 8 additions and 0 deletions

View File

@ -1111,6 +1111,8 @@ std::unique_ptr<QgsAbstractGeometry> QgsGeos::fromGeos( const GEOSGeometry *geos
{
case GEOS_POINT: // a point
{
if ( GEOSisEmpty_r( geosinit()->ctxt, geos ) )
return qgis::make_unique< QgsPoint >();
const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq_r( geosinit()->ctxt, geos );
unsigned int nPoints = 0;
GEOSCoordSeq_getSize_r( geosinit()->ctxt, cs, &nPoints );

View File

@ -613,6 +613,12 @@ void TestQgsGeometry::geos()
QCOMPARE( GEOSGetNumGeometries_r( QgsGeos::getGEOSHandler(), asGeos.get() ), 2 );
res = QgsGeometry( QgsGeos::fromGeos( asGeos.get() ) );
QCOMPARE( res.asWkt(), QStringLiteral( "MultiPolygon (((0 0, 0 1, 1 1, 0 0)),((10 0, 10 1, 11 1, 10 0)))" ) );
// Empty geometry
QgsPoint point;
asGeos = QgsGeos::asGeos( &point );
res = QgsGeometry( QgsGeos::fromGeos( asGeos.get() ) );
QCOMPARE( res.asWkt(), QgsPoint().asWkt( ) );
}
void TestQgsGeometry::point()