 # Geometry :

Subject: Re: [geometry] Negative distance?
From: Barend Gehrels (barend_at_[hidden])
Date: 2012-03-08 13:15:15

Hi Volker,

On 8-3-2012 8:47, Volker Schöch wrote:
> Hi,
>
> I am seeing negative results from the distance algorithm with boost::geometry::distance(MultiPolygon, Point). I wonder if this is a problem in my code, or a bug in GGL, or by design -- and in the latter case, what's the meaning of negative distances?
>
> The boost::geometry documentation says:
>
>> The function distance implements function Distance from the OGC Simple Feature Specification.
> The OGC Simple Feature Specification says:
>
>> Distance (anotherGeometry: Geometry):Double - Returns the shortest distance between any two Points in the two geometric objects as calculated in the spatial reference system of this geometric object. Because the geometries are closed, it is possible to find a point on each geometric object involved, such that the distance between these 2 points is the returned distance between their geometric objects.
> I don't find my question explicitly answered there, but since in mathematical geometry distances are usually non-negative and there is no mentioning or explanation of why and how OGC would define negative distances, I assume it may be a bug?
>
> I am using boost 1.48.0, my polygon type is oriented counter-clockwise and not closed, my point type is based on int.
>

It will be an already-solved bug, I think. Version 1.48 contained an
uninitialized variable in the case of an empty multi-polygon (empty
vector) compared to a point. Might that have been the case? It is solved
in the meantime, so for 1.49. We now throw an "empty input exception".
This might change in future versions where we will either return a
boost-optional, or an error code, or an exception, probably on request.

What has been discussed is that there are wishes to measure the
"internal distance" too, so for a point inside a polygon the distance to
the border. I believe it has been suggested to make that distance
negative (makes sense) but it has not been implemented like that. It is
probably better to make that a separate function, or it is also possible
to implement that as a strategy property. To be decided.

In any case, negative distances should currently not occur but can
unfortunately occur in 1.48.

Regards, Barend

Geometry list run by mateusz at loskot.net