我有一个表,其中包含一个SqlGeometry数据字段,我想将该表导出到asp.net应用程序上的shapefile。有没有办法将表格直接转换成shapefile?
如果没有,有没有免费的SDK或工具来写形状文件?
请注意,该表包含字符串、整型和布尔型字段。
发布于 2014-09-05 05:13:34
你可以尝试一下NetTopologySuite,他们有一个ShapeFileWriter类,只需要很少的努力就可以完成这项工作。
编辑:以下是一些示例代码。我用NetTopologySuite源文件写的。但是也有NuGet包。
namespace ConsoleApplication1
{
using GeoAPI.Geometries;
using NetTopologySuite.Features;
using NetTopologySuite.Geometries;
using NetTopologySuite.IO;
class Program
{
static void Main(string[] args)
{
FeatureCollection features = new FeatureCollection();
// Polygon 1
List<Coordinate> coords = new List<Coordinate>();
coords.Add(new Coordinate(0,0));
coords.Add(new Coordinate(0,10));
coords.Add(new Coordinate(10,10));
coords.Add(new Coordinate(10,0));
coords.Add(new Coordinate(0,0));
LinearRing ring = new LinearRing(coords.ToArray());
Polygon poly = new Polygon(ring);
// Polygon1 attributes
AttributesTable attr = new AttributesTable();
attr.AddAttribute("Column1", "HELLO");
attr.AddAttribute("Column2", "WORLD !");
Feature featureForPolygon = new Feature(poly, attr);
features.Add(featureForPolygon);
ShapefileDataWriter writer = new ShapefileDataWriter(@"%userprofile%\documents\outFile");
writer.Header = new DbaseFileHeader();
writer.Header.AddColumn("Column1", 'C', 10, 0);
writer.Header.AddColumn("Column2", 'C', 10, 0);
writer.Write(features.Features);
}
}
}这并不简单,因为您必须手动转换每个SqlGeometry。(也许NTS MsSqlSpatial会有所帮助...)
试一试,让我知道。
https://stackoverflow.com/questions/20727107
复制相似问题