Mat*_*int 5 c# geospatial shapefile wkt
我有一个包含几千个多边形的Shapefile.
我需要在C#中读取此文件并输出WKT格式的字符串列表.
我看了DotSpatial和"CatFood"ESRI Shapefile Reader.我可以得到正好加载shapefile,但我无法弄清楚如何导出为WKT.
在DotSpatial中,我能找到的唯一例子是使用WktWritera Geometry.我无法弄清楚如何获得Geometry一个Shape.
有没有更合适的图书馆?
更新
感谢mdm20的回答,我能够写下以下内容:
using (var fs = FeatureSet.Open(path))
{
var writer = new WktWriter();
var numRows = fs.NumRows();
for (int i = 0; i < numRows; i++)
{
var shape = fs.GetShape(i, true);
var geometry = shape.ToGeometry();
var wkt = writer.Write((Geometry) geometry);
Debug.WriteLine(wkt);
}
}
Run Code Online (Sandbox Code Playgroud)
我最初错过它的原因是因为我正在关注这个样本,而fs.ShapeIndices不是使用fs.GetShape().这不是a Shape,而是a ShapeRange,我无法转换为几何.
新问题
fs.IndexMode = true吗?为什么或者为什么不?它似乎没有任何性能或结果影响.fs.GetShape()采用一个叫做的布尔值getAttributes.我确实对我的形状有属性,并且它们似乎是通过设置是真还是假来实现的.同样,无论如何都没有明显的性能影响.这是预期的吗?非常感谢!
在DotSpatial中,Shape类有一个ToGeometry方法。
/// <summary>
/// Converts this shape into a Geometry using the default factory.
/// </summary>
/// <returns>The geometry version of this shape.</returns>
public IGeometry ToGeometry()
{
return ToGeometry(Geometry.DefaultFactory);
}
Run Code Online (Sandbox Code Playgroud)
编辑
我只使用了点空间的东西来进行投影,所以我不能真正帮助你太多。
1-2:不确定。如果你想看看他们做了什么,代码是开源的
3:WKT 是人类可读的几何文本表示形式。我认为它与文件的值相同,但我不知道。再次..查看点空间源代码
4:prj 文件告诉您几何体所在的投影。根据您想要用它做什么,您可能需要重新投影它。例如,必应地图和谷歌地球等都使用墨卡托投影。点空间投影库很好,可以轻松地将几何图形从一种投影转换为另一种投影。
我已经用 shapefile 做了很多工作......如果您有更多问题,请告诉我。