Skip to content

Commit

Permalink
Don't use GEOS to calculate length of points/linestrings
Browse files Browse the repository at this point in the history
These calculations are so trivial that the expense of conversion
to a geos representation is unwanted overhead
  • Loading branch information
nyalldawson committed Feb 24, 2021
1 parent 4f29af5 commit ff17205
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/core/geometry/qgsgeometry.cpp
Expand Up @@ -1786,6 +1786,13 @@ 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 );
Expand Down

0 comments on commit ff17205

Please sign in to comment.