NearestCoordinate throws NotImplementedException

469
1
10-13-2019 03:58 PM
MatthiasPorges
New Contributor

GeometryEngine.NearestCoordinate(envelope, mapPoint) throws a NotImplementedException.

This is definitely a bug, as the documentation doesn't mention it: GeometryEngine.NearestCoordinate Method 

The fix is to convert the Envelope to a Polygon:

private static Polygon EnvelopeToPolygon(Envelope envelope)
{
    return new Polygon(new MapPoint[]
    {
        new MapPoint(envelope.XMin, envelope.YMin, envelope.SpatialReference),
        new MapPoint(envelope.XMax, envelope.YMin, envelope.SpatialReference),
        new MapPoint(envelope.XMax, envelope.YMax, envelope.SpatialReference),
        new MapPoint(envelope.XMin, envelope.YMax, envelope.SpatialReference)
    });
}

It really should be implemented, as it's just a few lines of code.

0 Kudos
1 Reply
PreetiMaske
Esri Contributor

GeometryEngine.NearestCoordinate is not implemented for Envelope. It is as expected because Envelope is not a feature geometry. You are on the right track to get around this limitation by converting envelope to a polygon.

But yes, this should definitely be documented. I have raised an issue to update the documentation to include this information.

0 Kudos