Skip to content
Permalink
Browse files
Don't use geos to calculate QgsGeometry::length
Instead use the QgsAbstractGeometry method, so that consistent
results are obtained across the API and an exact length is used
for curved geometries (instead of the length of the segmentized
curves)

Refsi https://lists.osgeo.org/pipermail/qgis-developer/2021-October/064159.html.
  • Loading branch information
nyalldawson committed Nov 2, 2021
1 parent 9f19d4f commit e10a48b3eea6c494bdd5a079b3a7b7752c43b287
Showing with 1 addition and 9 deletions.
  1. +1 −9 src/core/geometry/qgsgeometry.cpp
@@ -1913,15 +1913,7 @@ double QgsGeometry::length() const
return -1.0;
}

// avoid calling geos for trivial geometry calculations
if ( QgsWkbTypes::geometryType( d->geometry->wkbType() ) == QgsWkbTypes::PointGeometry || QgsWkbTypes::geometryType( d->geometry->wkbType() ) == QgsWkbTypes::LineGeometry )
{
return d->geometry->length();
}

QgsGeos g( d->geometry.get() );
mLastError.clear();
return g.length( &mLastError );
return d->geometry->length();
}

double QgsGeometry::distance( const QgsGeometry &geom ) const

0 comments on commit e10a48b

Please sign in to comment.