我有以下代码来使用
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;
}
这是可行的,但是几何对象没有属性来告诉坐标位于哪个参考系中。
如何找出形状文件或单个形状所在的坐标系/参考系?
投影在 .shp 文件中不可用,但在 .prj 文件中可用,并且可以单独加载:
var projectionFile = Path.Combine(Path.GetDirectoryName(localShapeFile), Path.GetFileNameWithoutExtension(localShapeFile) + ".prj");
var projectionInfo = ProjectionInfo.Open(projectionFile);
var projectionFile = Path.Combine(Path.GetDirectoryName(localShapeFile), Path.GetFileNameWithoutExtension(localShapeFile) + ".prj");
var coordSystem = CoordinateSystemWktReader.Parse(File.ReadAllText(projectionFile)) as CoordinateSystem;