【问题标题】:Create MultiPolygon SqlGeography from Polygon SqlGeographys从 Polygon SqlGeographys 创建 MultiPolygon SqlGeography
【发布时间】:2014-07-07 07:32:50
【问题描述】:

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

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

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

【问题讨论】:

    标签: c# sqlgeography


    【解决方案1】:

    我找到了一种使用 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;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-06
      相关资源
      最近更新 更多