SqlGeography - getting polygons from polygons

I have a table Town

with a column TownBoundary

that contains the polygon of the corresponding city ( geography

datatype).

For each city, I get the polygonal data that I need to generate KML (XML) files like:

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 town.TownBoundary.WellKnownValue.WellKnownText

start withPOLYGON(..

But recently I realized that some cities contain more polygons, and WellKnownText

starts with MULTIPOLYGON(..

, and the function STPolyFromText

ends with an error.

I have placed this in a block try{}

, but in catch{}

- if the value is multipolygon - is it possible to somehow get the individual polygons? I know there is a method STMPolyFromText

, but I cannot use individual polygons there, only points as in the method STPolyFromText

.

My goal is to split the polygon into polygons rather than polygon by doing the same method as above.

+3


source to share


1 answer


Solved it, in the method STMPolyFromText

I can get the polygon array using 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
} 

      

+5


source







All Articles