c# - 从 Polygon SqlGeographics 创建 MultiPolygon SqlGeography

标签 c# sqlgeography

我有一个 SqlGeographics 列表,它们是多边形。我想将它们组合成一个类型为 multipolygon 的 SqlGeography。

List<SqlGeography> areaPolygons = GetAreaPolygons()
SqlGeography multiPoly = null;

foreach (SqlGeography geog in areaPolygons)
{
    /// Combine them somehow?
}

最佳答案

我找到了一种使用 SqlGeographyBuilder 的方法,可能有更有效的方法,但这个方法有效:

List<SqlGeography> areaPolygons = GetAreaPolygons()
SqlGeography multiPoly = null;

SqlGeographyBuilder sqlbuilder = new SqlGeographyBuilder();
sqlbuilder.SetSrid(4326);
sqlbuilder.BeginGeography(OpenGisGeographyType.MultiPolygon);

foreach (SqlGeography geog in areaPolygons)
{
    sqlbuilder.BeginGeography(OpenGisGeographyType.Polygon);

    for (int i = 1; i <= geog.STNumPoints(); i++)
        {
            if (i == 1)
                sqlbuilder.BeginFigure((double)geog.STPointN(i).Lat, (double)geog.STPointN(i).Long);
            else
                sqlbuilder.AddLine((double)geog.STPointN(i).Lat, (double)geog.STPointN(i).Long);
        }

        sqlbuilder.EndFigure();
        sqlbuilder.EndGeography();
}

sqlbuilder.EndGeography();
multiPoly = sqlbuilder.ConstructedGeography;

关于c# - 从 Polygon SqlGeographics 创建 MultiPolygon SqlGeography,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24605196/

相关文章:

c# - C# 的 WebP 库

c# - 我是否需要对字体、画笔等使用使用模式

c# - 访问 Win32_OperatingSystem 的属性

sql-server - 在矩形(多边形)内查找sql​​地理点

c# - 通过 ado.net 插入 DBGeography 类型的正确方法是什么

c# - MVVM light application - 如何正确清理 ViewModels

c# - 使用继承自 List<T> 的类进行 JSON 序列化

sql-server - 由于此查询中定义的提示,查询处理器无法生成查询计划。重新提交查询并且不使用 SET FORCEPLAN

sql - 如何将地理位置批量插入到新的SQL Server 2008表中

SQL 几何 VS 小数(8,6) 纬度、经度性能