0

I've inherited some code that converts ArcGIS Engine IPolygon4 objects to GeoPackage-compatible objects. The format is very specific in terms of what's permitted with exterior and interior rings.

I need to port this code to ArcGIS Runtime for use on Android. The API for the Runtime polygon class Polygon is really sparse, and contains no properties or methods related to the polygon's rings. The only property I have is an IReadOnlyList<ReadOnlyPart> holding the polygon's parts.

I don't know if this collection is ordered, or if I can order it in some way to determine which ring is the exterior one.

Is there any way that I can identify the interior/exterior rings of a Polygon in ArcGISRuntime SDK for .NET?

Here is the code I am working with. WkbMultiPolygon is the custom polygon object I am trying to convert to.

using ESRI.ArcGIS.Geometry;
using System.Linq;

public static WkbMultiPolygon CreateMultiPolygon(IPolygon4 esriPolygon) {

    var exteriorRingGeometryCollection = (IGeometryCollection)esriPolygon.ExteriorRingBag;

    var exteriorRingCount = exteriorRingGeometryCollection.GeometryCount;

    // create my list of custom polygons
    var wkbPolygons = new List<WkbPolygon>(exteriorRingCount);

    for(var exteriorRingIndex = 0; exteriorRingIndex < exteriorRingCount; ++exteriorRingIndex) {
        var exteriorRingGeometry = exteriorRingGeometryCollection.Geometry[exteriorRingIndex];

        var interiorRingCollection = (IGeometryCollection)esriPolygon.InteriorRingBag[exteriorRingGeometry as IRing];

        // create my custom polygon object and add to list.
        wkbPolygons.Add(new WkbPolygon(ToLinearRing(exteriorRingGeometry as IPointCollection),
                                       Enumerable.Range(0, interiorRingCollection.GeometryCount)
                                                 .Select(index => interiorRingCollection.Geometry[index] as IPointCollection)
                                                 .Select(ToLinearRing)
                                                 .ToList()));
    }

    return new WkbMultiPolygon(wkbPolygons);
}
  • 1
    Can you provide a code snippet that illustrates where you are stuck, please? – PolyGeo Nov 8 '17 at 21:32
  • Possibly the only thing I can think of is that Exterior rings are clockwise and Interior rings (holes) are counter-clockwise, if you can get to the points from the ring then you could be able to determine direction of travel to decide if a ring is exterior or interior. – Michael Stimson Nov 8 '17 at 22:31
1

You can use the approach I used here:

https://github.com/dotMorten/GeometryConversions/blob/master/src/GeometryConversions.Shared/Utilities.cs#L12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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