5

I have a MultiPolygon that was created by reading from a GeoJSON string.

string geoJson = getGeoJson();
var rdr = new GeoJsonReader();
var multiPolygon = rdr.Read<MultiPolygon>(geoJson);

My problem - GeoJSON recommends but does not require that the outer ring be counter-clockwise and the inner rings be clockwise.

It looks to me as if GeoJsonReader, when handed a polygon with a clockwise outside ring constructs a MultiPolygon with a clockwise outer ring.

How can I detect, in Net Topology Suite, that a ring is clockwise or counter clockwise?

1 Answer 1

8

In NTS, every object that inherits ILinarRing interface has the IsCCW property to test if it is counter clockwise.

In case of a MultiPolygon object, you have to test the shell of every internal polygon. Like this:

IMultiPolygon multiPol = rdr.Read<MultiPolygon>(geoJson);
foreach (IGeometry geom in multiPol.Geometries)
{
    IPolygon pol = (IPolygon)geom;
    if (pol.Shell.IsCCW)
    {
        // Shell is counter clockwise
    }
    else
    {
        // Shell is clockwise
        IGeometry ccwShell = pol.Shell.Reverse();
    }
}

PD: Old question, maybe usefull for someone...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.