Create MultiPolygon SqlGeography from Polygon SqlGeographys

本文关键字:Polygon SqlGeographys from SqlGeography MultiPolygon Create | 更新日期: 2023-09-27 18:11:47

我有一个多边形的sqlgeography列表。我想把它们合并成一个类型为multipolygon的SqlGeography。

List<SqlGeography> areaPolygons = GetAreaPolygons()
SqlGeography multiPoly = null;
foreach (SqlGeography geog in areaPolygons)
{
    /// Combine them somehow?
}

Create MultiPolygon SqlGeography from Polygon SqlGeographys

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