Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 是否有方法直接将dbgeometry或sqlgeometry转换为形状文件?_C#_Gis_Shapefile_Sqlgeometry - Fatal编程技术网

C# 是否有方法直接将dbgeometry或sqlgeometry转换为形状文件?

C# 是否有方法直接将dbgeometry或sqlgeometry转换为形状文件?,c#,gis,shapefile,sqlgeometry,C#,Gis,Shapefile,Sqlgeometry,我有一个包含SqlGeometry数据字段的表,我想将该表导出到asp.net应用程序上的shapefile。有没有办法将表格直接转换为shapefile 如果没有,是否有用于编写形状文件的免费SDK或工具 请注意,该表包含字符串、int和Boolean字段。您可以尝试一下NetTopologySuite,它们有一个ShapeFileWriter类,只需稍加努力即可完成这项工作 编辑:下面是一些示例代码。我使用NetTopologySuite源文件编写了它。但也有NuGet软件包 namespa

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

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


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

您可以尝试一下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);
    }
}
}
命名空间控制台应用程序1
{
使用GeoAPI。几何;
使用NetTopologySuite.Features;
使用NetTopologySuite.几何学;
使用NetTopologySuite.IO;
班级计划
{
静态void Main(字符串[]参数)
{
FeatureCollection features=新FeatureCollection();
//多边形1
列表坐标=新列表();
坐标添加(新坐标(0,0));
坐标添加(新坐标(0,10));
添加(新坐标(10,10));
添加(新坐标(10,0));
坐标添加(新坐标(0,0));
线性齿圈=新的线性齿圈(coords.ToArray());
多边形多边形=新多边形(环);
//Polygon1属性
AttributesTable attr=新的AttributesTable();
attr.AddAttribute(“Column1”、“HELLO”);
attr.AddAttribute(“Column2”,“WORLD!”);
特征featureForPolygon=新特征(多边形、属性);
添加(featureForPolygon);
ShapefileDataWriter=新的ShapefileDataWriter(@“%userprofile%\documents\outFile”);
writer.Header=新的DbaseFileHeader();
writer.Header.AddColumn(“Column1”,C',10,0);
writer.Header.AddColumn(“Column2”,“C',10,0”);
作家。写作(特征。特征);
}
}
}
这并不简单,因为您必须手动转换每个SqlGeometry。(也许MSSQLSpace会有帮助…)

试试看,让我知道