[英]SqlGeography get polygons from multipolygon
I have table Town
with column TownBoundary
that contains polygon of relevant town ( geography
datatype). 我有包含相关镇(
geography
数据类型)的多边形的列TownBoundary
表Town
。
For each town I get polygon data that I need to generate KML(XML) files like: 对于每个城镇,我获得了生成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
}
Values of town.TownBoundary.WellKnownValue.WellKnownText
begins with POLYGON(..
town.TownBoundary.WellKnownValue.WellKnownText
值以POLYGON(..
开头POLYGON(..
But recently I have realised that some towns contains more polygons and WellKnownText
begins with MULTIPOLYGON(..
and function STPolyFromText
ends up in error. 但最近我已经意识到,一些城镇中含有较多的多边形和
WellKnownText
开始MULTIPOLYGON(..
和功能STPolyFromText
错误结束。
I have placed this in try{}
block, but in catch{}
- if value is multipolygon - is it possible to somehow get individual polygons? 我把它放在
try{}
块中,但是在catch{}
- 如果value是multipolygon - 是否有可能以某种方式获得单个多边形? I know there is method STMPolyFromText
, but I can't acccess individual polygons there, only points as in method STPolyFromText
. 我知道有方法
STMPolyFromText
,但我无法在那里处理单个多边形,只有方法STPolyFromText
点。
My goal is to split multipolygon to polygons and than foreach polygon do the same method as above. 我的目标是将多边形分割为多边形,而foreach多边形则采用与上述相同的方法。
Solved it, in method STMPolyFromText
I can get array of polygons using STNumGeometries
. 解决了它,在方法
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
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.