[mapguide-users] RE: API call for transforming polygon to line?

Jason Birch Jason.Birch at nanaimo.ca
Wed Mar 15 18:37:08 EST 2006


Thanks Dave.  
 
I think I'll go with the less rigorous approach, as it would lend itself well to a simple regular expression substitution, and because it would take considerably less processing time.  Google Earth seems to be picky about getting data back in a timely manner, and I'd rather support a larger number of features returned than better code.  Sometimes the best approach isn't the best solution :)
 
Jason

________________________________

From: Dave Wilson [mailto:dave.wilson at autodesk.com]
Sent: Wed 2006-03-15 2:06 PM
To: users at mapguide.osgeo.org
Subject: [mapguide-users] RE: API call for transforming polygon to line?


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 --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/ms-tnef
Size: 7184 bytes
Desc: not available
Url : http://lists.osgeo.org/pipermail/mapguide_users/attachments/20060315/504e55e2/attachment.bin


More information about the Mapguide_users mailing list