[mapguide-users] Mapguide WKT standards?
Firenter
cedric.corthout.external at arcelormittal.com
Fri Jan 20 01:25:51 PST 2017
Allright it seems I've found a workaround by reading out the coordinates of
these CurvePolygons and then converting those into normal Polygons.
If I ever run into other CurveThings I'll just add them to it then :P
Thanks for setting me on this path, didn't know how to convert geometries
that came in bytes to MgGeometries and now I do! Which is what led me to
finding out that you can just get the coordinates of anything.
Here's the C# code I used:
private string GetGeometryFromBytes(MgByteReader geometry)
{
MgAgfReaderWriter agfReadWrite = new MgAgfReaderWriter();
MgGeometry geom = agfReadWrite.Read(geometry);
int geometryType = geom.GetGeometryType();
MgGeometryFactory gf = new MgGeometryFactory();
//CurvePolygons don't generate standard WKT convert them to
regular polygons
if (geometryType == MgGeometryType.CurvePolygon)
{
MgCurvePolygon cp = (MgCurvePolygon)geom;
geom = CreatePolygonFromCurvePolygon(cp, gf);
}else if(geometryType == MgGeometryType.MultiCurvePolygon)
{
MgMultiCurvePolygon mcp = (MgMultiCurvePolygon)geom;
geom = CreateMultiPolygonFromMultiCurvePolygon(mcp, gf);
}
//TODO: Other CurveThings
MgWktReaderWriter wktReadWrite = new MgWktReaderWriter();
string wktGeom = wktReadWrite.Write(geom);
return wktGeom;
}
private MgPolygon CreatePolygonFromCurvePolygon(MgCurvePolygon cp,
MgGeometryFactory gf)
{
MgCoordinateIterator cpCoords = cp.Coordinates;
MgCoordinateCollection coordCollection = new
MgCoordinateCollection();
while (cpCoords.MoveNext())
{
coordCollection.Add(cpCoords.GetCurrent());
}
MgLinearRing ring = gf.CreateLinearRing(coordCollection);
return gf.CreatePolygon(ring, null);
}
private MgMultiPolygon
CreateMultiPolygonFromMultiCurvePolygon(MgMultiCurvePolygon mcp,
MgGeometryFactory gf)
{
MgPolygonCollection pc = new MgPolygonCollection();
int polygonCount = mcp.GetCount();
for (int i = 0; i < polygonCount; i++)
{
MgCurvePolygon cp = mcp.GetCurvePolygon(i);
pc.Add(CreatePolygonFromCurvePolygon(cp, gf));
}
return gf.CreateMultiPolygon(pc);
}
--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Mapguide-WKT-standards-tp5303869p5304137.html
Sent from the MapGuide Users mailing list archive at Nabble.com.
More information about the mapguide-users
mailing list