API call for transforming polygon to line?

Dave Wilson dave.wilson at autodesk.com
Wed Mar 15 17:06:09 EST 2006


Hey Jason,
 
I don't think there is a direct API call to do this. If I'm wrong
hopefully someone will pipe up.
 
Programmatically there are a couple of ways you can do this.
 
A quick and dirty way would be to get the WKT string of the Polygon
using the MgWktReaderWriter which would yield something like:
 
POLYGON ((1 1, 1 -1, -1 -1, -1 1, 1 1))
 
You could parse the resulting string to remove the POLYGON (  and
trailing ) leaving (1 1, 1 -1, -1 -1, -1 1, 1 1).
 
Then concatenate LINESTRING to it and you can use the ReaderWriter to
create the geometry object for you from the string.
 
Of course if your polygon has inner rings you will have to check the
count of the inner rings using GetInteriorRingCount as these won't
convert to simple linestrings. You may be able to convert them to
MULTILINESTRING instead by just changing the leading concatenation.
 
If your polygon contains curvestrings in it I'm not sure if you can
again just change the leading concatenation to CURVESTRING as I haven't
worked with these. The quick and dirty is nice because it requires
minimal processing and if all your polygons don't have inner rings or
curves it's a piece of cake.
 
An alternative and more rigorous approach would be to determine the
types of polygon involved and walk the geometry, getting each of the
coordinate values and using an MgGeometryFactory create the MgLinestring
or MgMultLinestring or other type as needed but this will be more
complex code I think because you need to use collection objects and
looping to walk the objects.
 
Regards,
Dave

  _____  

From: Jason Birch [mailto:Jason.Birch at nanaimo.ca] 
Sent: Wednesday, March 15, 2006 1:21 PM
To: users at mapguide.osgeo.org
Subject: API call for transforming polygon to line?


Is there a method that would allow me to type case a polygon to a line?
I can do the same going to a point with the GetCentroid command (I
think) but can't figure out poly->line.
 
Thanks,
Jason
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/mapguide-users/attachments/20060315/b7d45d85/attachment.html


More information about the Mapguide-users mailing list