我有一个 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/