0

I'm searching a script to get inner ring from a polygon in the shapefile using dotspatial. Below is my script to get all coordinate(ignoring outer/inner ring) from a shapefile.

string shapeFilePath = @"\example.shp";
shapeFilePath = location + shapeFilePath;
Shapefile indexMapFile = Shapefile.OpenFile(shapeFilePath);
indexMapFile.Reproject(KnownCoordinateSystems.Geographic.Australia.GeocentricDatumofAustralia1994);

for (int i = 0; i < indexMapFile.DataTable.Rows.Count; i++)
{

    IFeature feature = indexMapFile.Features.ElementAt(i);

    var arr = feature.Coordinates.ToArray();

    foreach (var det in arr)
    {
        DotSpatial.Topology.Coordinate det_cor = det;
        string X = det_cor.X.ToString();
        string Y = det_cor.Y.ToString();
    }
}

1 Answers1

0

i found the answer, this is my code, how to get inner ring from polygon

string shapeFilePath = @"\example.shp";
shapeFilePath = location + shapeFilePath;
Shapefile indexMapFile = Shapefile.OpenFile(shapeFilePath);
indexMapFile.Reproject(KnownCoordinateSystems.Geographic.Australia.GeocentricDatumofAustralia1994);

for (int i = 0; i < indexMapFile.DataTable.Rows.Count; i++)
{

    IFeature feature = indexMapFile.Features.ElementAt(i);
    IPolygon bp = feature.GetBasicGeometryN(0) as IPolygon;
    var all_polygon = bp.GetGeometryN(0);//include outer and inner ring, see this link -> https://stackoverflow.com/questions/8139739/wkt-how-do-you-define-polygons-with-3-rings-2-holes
    var outer_ring = bp.Shell.GetGeometryN(0);
    int idx_hole = 0;
    foreach (var hole in bp.Holes)
    {
        //get inner ring/hole from polygon
        Response.Write(bp.GetInteriorRingN(idx_hole));
        idx_hole++;
    }
}