Navigation Menu

Skip to content

Commit

Permalink
Fix fromGeos returning 0 for x/y on empty point
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso authored and nyalldawson committed Feb 8, 2021
1 parent bdccd78 commit a89d564
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/core/geometry/qgsgeos.cpp
Expand Up @@ -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 );
Expand Down
6 changes: 6 additions & 0 deletions tests/src/core/testqgsgeometry.cpp
Expand Up @@ -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()
Expand Down

0 comments on commit a89d564

Please sign in to comment.