Skip to content

Commit

Permalink
Don't use geos to calculate QgsGeometry::length
Browse files Browse the repository at this point in the history
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 e10a48b
Showing 1 changed file with 1 addition and 9 deletions.
10 changes: 1 addition & 9 deletions src/core/geometry/qgsgeometry.cpp
Expand Up @@ -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
Expand Down

0 comments on commit e10a48b

Please sign in to comment.