如何确定使用 ShapefileDataReader 设置的 shapefile 的坐标系

问题描述 投票:0回答:2

我有以下代码来使用

NetTopologySuite.IO.ShapefileDataReader
:

读取 shapefile 集(.dbf、.prj、.shp、.shx)
public FeatureCollection ReadShapeFile(string localShapeFile)
{
    var collection = new FeatureCollection();
    var factory = new GeometryFactory();
    using (var reader = new ShapefileDataReader(localShapeFile, factory))
    {
        var header = reader.DbaseHeader;
        while (reader.Read())
        {
            var f = new Feature {Geometry = reader.Geometry};

            var attrs = new AttributesTable();
            for (var i = 0; i < header.NumFields; i++)
            {
                attrs.AddAttribute(header.Fields[i].Name, reader.GetValue(i));
            }

            f.Attributes = attrs;

            collection.Add(f);
        }
    }
    return collection;
}

这是可行的,但是几何对象没有属性来告诉坐标位于哪个参考系中。

如何找出形状文件或单个形状所在的坐标系/参考系?

c# .net geospatial shapefile nettopologysuite
2个回答
0
投票

投影在 .shp 文件中不可用,但在 .prj 文件中可用,并且可以单独加载:

var projectionFile = Path.Combine(Path.GetDirectoryName(localShapeFile), Path.GetFileNameWithoutExtension(localShapeFile) + ".prj");
var projectionInfo = ProjectionInfo.Open(projectionFile);

0
投票

来自:如何读取Shapefile的prj文件?

var projectionFile = Path.Combine(Path.GetDirectoryName(localShapeFile), Path.GetFileNameWithoutExtension(localShapeFile) + ".prj");
var coordSystem = CoordinateSystemWktReader.Parse(File.ReadAllText(projectionFile)) as CoordinateSystem;
© www.soinside.com 2019 - 2024. All rights reserved.