首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >有没有办法直接将dbgeometry shape文件转换成图形文件?

问有没有办法直接将dbgeometry shape文件转换成图形文件?
EN

Stack Overflow用户
提问于 2013-12-22 15:09:05
回答 1查看 1.3K关注 0票数 0

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

如果没有,有没有免费的SDK或工具来写形状文件?

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

EN

回答 1

Stack Overflow用户

发布于 2014-09-05 05:13:34

你可以尝试一下NetTopologySuite,他们有一个ShapeFileWriter类,只需要很少的努力就可以完成这项工作。

编辑:以下是一些示例代码。我用NetTopologySuite源文件写的。但是也有NuGet包。

代码语言:javascript
复制
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会有所帮助...)

试一试,让我知道。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20727107

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档