c# – SqlGeography从多边形获取多边形
作者:互联网
我有包含相关镇(地理数据类型)的多边形的列TownBoundary的表镇.
对于每个城镇,我获得了生成KML(XML)文件所需的多边形数据,如:
sqlg = SqlGeography.STPolyFromText(new SqlChars(
town.TownBoundary.WellKnownValue.WellKnownText),
town.TownBoundary.CoordinateSystemId);
for (int i = 1; i <= sqlg.STNumPoints(); i++)
{
SqlGeography point = sqlg.STPointN(i);
var pLong = (point.Long).ToString().Replace(",", ".");
var pLat = (point.Lat).ToString().Replace(",", ".");
double dLong = double.Parse(pLong, CultureInfo.InvariantCulture);
double dLat = double.Parse(pLat, CultureInfo.InvariantCulture);
kmlCoordinates.Add(new Vector(dLat, dLong)); //one point od polygon
}
town.TownBoundary.WellKnownValue.WellKnownText的值以POLYGON开头(..
但最近我意识到一些城镇包含更多的多边形而WellKnownText以MULTIPOLYGON开头(..和函数STPolyFromText最终出错.
我把它放在try {}块中,但是在catch {}中 – 如果value是multipolygon – 是否有可能以某种方式获得单个多边形?我知道有方法STMPolyFromText,但我无法在那里处理单个多边形,只有方法STPolyFromText中的点.
我的目标是将多边形分割为多边形,而foreach多边形则采用与上述相同的方法.
解决方法:
解决了它,在方法STMPolyFromText中,我可以使用STNumGeometries获得多边形数组.
sqlg = SqlGeography.STMPolyFromText(
new SqlChars(town.TownBoundary.WellKnownValue.WellKnownText),
town.TownBoundary.CoordinateSystemId);
for (int i = 1; i <= sqlg.STNumGeometries(); i++)
{
SqlGeography poly = sqlg.STGeometryN(i);
//foreach poly
}
标签:c,polygon,geography,sqlgeography 来源: https://codeday.me/bug/20190528/1173111.html