我有以下代码用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;
}
这样可行,但几何对象没有一个属性来告诉坐标所在的参考系统。
如何找出形状文件或各个形状所在的坐标系/参考系?
答案 0 :(得分:0)
投影在.shp文件中不可用,但在.prj文件中,可以单独加载:
var projectionFile = Path.Combine(Path.GetDirectoryName(localShapeFile), Path.GetFileNameWithoutExtension(localShapeFile) + ".prj");
var projectionInfo = ProjectionInfo.Open(projectionFile);