Skip to content

Commit

Permalink
[geometry] optimize point distance to point
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Jun 4, 2018
1 parent 84806b9 commit 783b6b8
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/core/geometry/qgsgeometry.cpp
Expand Up @@ -1595,6 +1595,12 @@ double QgsGeometry::distance( const QgsGeometry &geom ) const
return -1.0;
}

// avoid calling geos for trivial point-to-point distance calculations
if ( QgsWkbTypes::flatType( d->geometry->wkbType() ) == QgsWkbTypes::Point && QgsWkbTypes::flatType( geom.wkbType() ) == QgsWkbTypes::Point )
{
return qgsgeometry_cast< const QgsPoint * >( d->geometry.get() )->distance( *qgsgeometry_cast< const QgsPoint * >( geom.constGet() ) );
}

QgsGeos g( d->geometry.get() );
mLastError.clear();
return g.distance( geom.d->geometry.get(), &mLastError );
Expand Down

0 comments on commit 783b6b8

Please sign in to comment.