0

我有一个包含 SqlGeometry 数据字段的表,我想将该表导出到 asp.net 应用程序上的 shapefile。有没有办法将表格直接转换为 shapefile?

如果没有,是否有用于编写形状文件的免费 SDK 或工具?

请注意,该表包含字符串、int 和布尔字段。

4

1 回答 1

2

你可以试试 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 会有所帮助......)

试一试,让我知道。

于 2014-09-04T21:13:33.820 回答