如何使用dotspatial从ASP.NET中的shapefile获取内环(孔)?

时间:2019-01-02 02:16:10

标签: asp.net dotspatial

我正在搜索一个脚本,以使用dotspatial从shapefile中的多边形获取内环。下面是我的脚本,用于从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 个答案:

答案 0 :(得分:0)

我找到了答案,这是我的代码,如何从多边形中获取内环

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++;
    }
}