This project has moved and is read-only. For the latest updates, please go here.

adding multiplegepmetry to a placemark

Apr 9, 2013 at 1:41 PM
Edited Apr 9, 2013 at 1:42 PM
i have a problem with the "MultipleGeometry" class.
I want to add to a placemark 2 geometry elements (for example 2 polygon), so i wrote...
MultipleGeometry mGeometry = new MultipleGeometry();
placeMark.Geometry = mGeometry;

This piece of code doesn't work :/
I try this too and it works:
MultipleGeometry mGeometry = new MultipleGeometry();
i get this in my kml file


instead with the first piece of code i get no multipleGeometry entry in the kml file.

Do i write something wrong?

Thanks a lot
Apr 10, 2013 at 11:22 AM
Trying to solve the problem, i found this problem with the MultipleGeometry

I try to add only one polygon (mGeometry.AddGeometry(polygon1);) and then i serialize the file. The output kml was written fine, but when i tried to add a second polygon i got the following exception:

<ExceptionElement xmlns:xsi="" xmlns:xsd="" xmlns="">
<exceptionMessage>Cannot add child element to this instance because it belongs to another instance.</exceptionMessage>
at SharpKml.Dom.Element.AddChild[Geometry] (SharpKml.Dom.Geometry child) [0x00000] in <filename unknown>:0 at SharpKml.Dom.MultipleGeometry.AddGeometry (SharpKml.Dom.Geometry geometry) [0x00000] in <filename unknown>:0 at Connector.Catalogue.KMLAssembly.KMLGeometry (System.Xml.XmlNode node, System.Xml.XmlNamespaceManager xnsm) [0x002e5] in /Users/cdangelis1/Repository/live/sugar.portal.modules.ngeoconnector.library/NgEO/Connector/Catalogue/KMLAssembly.cs:707 at Connector.Catalogue.KMLAssembly.QueryAtomToKML (Portal.OpenSearchRequest request,OpenSearch.OpenSearchUrl url) [0x00e6f] in /Users/cdangelis1/Repository/live/sugar.portal.modules.ngeoconnector.library/NgEO/Connector/Catalogue/KMLAssembly.cs:525 at Portal.OpenSearchEngine.Query (Portal.OpenSearchRequest request) [0x00077] in /Users/cdangelis1/Repository/live/sugar.portal.core.library/Portal/Search.cs:125 at () [0x0009e] in /Users/cdangelis1/Repository/live/ngeo.webserver.library/NgEO/WebServer/CatalogueSearch/ProductSearchService.cs:92 at WebServer.CatalogueSearch.ProductSearchService.Execute (WebServer.CatalogueSearch.ProductSearch productSearch) [0x00000] in /Users/cdangelis1/Repository/live/ngeo.webserver.library/NgEO/WebServer/CatalogueSearch/ProductSearchService.cs:116
Apr 11, 2013 at 7:26 AM
I'm not sure why it's not working to be honest. The exception you are getting is probably because you are adding the same polygon instance to the MulipleGeometry - you can use the Clone extension method from the SharpKml.Engine namespace to help you create a copy.

Can you show me any code that reproduces the original problem of the MultipleGeometry not serializing properly so I can try and diagnose it further?

Apr 11, 2013 at 9:02 AM
Thanks a lot samcragg
I get the error because i use the same polygon object to test my procedure. I didn't think to add a different polygon to the multiplegeometry, i believed i could add the same object twice or more. Now, trying with a second different polygon from the first one, i get the right kml output. So the original problem came from my coding (i tried to add the same polygon object so i got an error, but i put this part of code inside a try cacth statement, so the multiplegeometry node was not added to the kml).
Thanks a lot :)