2016-05-11 39 views
1

設置shape文件的coordinatesystem我有下面的代碼讀取shape文件集(.DBF,.PRJ,.SHP,.SHX)與NetTopologySuite.IO.ShapefileDataReader如何確定與ShapefileDataReader

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

投影不在.shp文件可用,但在.prj文件,並且可以分別裝載:

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