How to save GraphicsLayer elements as KML file?

1424
7
Jump to solution
01-24-2018 06:25 AM
AhmetEmre
New Contributor III

Hi,

I have a graphicslayer and some elements in it such as points, polygons and lines. Is there a simple/quick function/method for saving contents of GraphicsLayer elements as KML file?

Thanks.

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
ShellyGill1
Esri Contributor

Hi Ahmet - if you are using classes called GraphicsLayer and KmlLayer, then it looks like you are using the older 10.2.x version of the Runtime SDK - GraphicsLayer | ArcGIS Android 10.2.9 API  - is that correct? This version will not be updated, so will not gain any more functionality. As Eric says above, the current release of the SDK - 100.2 - ArcGIS Runtime SDK for Android | ArcGIS for Developers does not have Kml read or write, but is in active development so more and more functionality will be added over time - I'd recommend you take a look at this latest version.

There is no functionality in the SDK to specifically support writing out KML (and as far as I know, it is not planned functionality), so nothing 'simple and quick', no. However you could write your own xml serializing code to write out whatever files you need from a GraphicsOverlay (similar functionality to GraphicsLayer used in 100.2). For very simple KML, I've never done this, but I imagine this would be pretty feasible. KML can get quite complex though, and the model does not map directly to Graphics, so there would definitely be challenges here depending on what you need.

Shelly

View solution in original post

7 Replies
EricBader
Occasional Contributor III

Hi Ahmet.

KML read/write is not available in the API yet.

0 Kudos
AhmetEmre
New Contributor III

Hello Eric,

I could find only KmlLayer for reading .kml files and put the graphics objects in .kml file into KmlLayer on the map. However couldn't find anything that relates KmlLayer with GraphicsLayer. It would be nice if there was such a feature

0 Kudos
ShellyGill1
Esri Contributor

Hi Ahmet - if you are using classes called GraphicsLayer and KmlLayer, then it looks like you are using the older 10.2.x version of the Runtime SDK - GraphicsLayer | ArcGIS Android 10.2.9 API  - is that correct? This version will not be updated, so will not gain any more functionality. As Eric says above, the current release of the SDK - 100.2 - ArcGIS Runtime SDK for Android | ArcGIS for Developers does not have Kml read or write, but is in active development so more and more functionality will be added over time - I'd recommend you take a look at this latest version.

There is no functionality in the SDK to specifically support writing out KML (and as far as I know, it is not planned functionality), so nothing 'simple and quick', no. However you could write your own xml serializing code to write out whatever files you need from a GraphicsOverlay (similar functionality to GraphicsLayer used in 100.2). For very simple KML, I've never done this, but I imagine this would be pretty feasible. KML can get quite complex though, and the model does not map directly to Graphics, so there would definitely be challenges here depending on what you need.

Shelly

AhmetEmre
New Contributor III

Hello Shelly,

Thanks for the clear answer. Yes 10.2.X version you are right. I have understood the KML issue thank you.

Then want to ask you if the following solution is possible or not:

I understand there's no direct serialization of a complete graphics layer. But I can loop all geometries in a simple graphics layer one by one (points, polygons, lines etc) then serialize them and then save it. And later I can re-read these and construct my graphics layer?

Is this possible?

0 Kudos
ShellyGill1
Esri Contributor

Hi Ahmet,

Yes, that sounds feasible to me to loop through all the Graphics in a GraphicsOverlay and save out each one.  I'm not a KML expert, but I think you'd look at creating a KML Placemark for each Graphic, and create a single KML Geometry onto each Placemark based on the Geometry of the Runtime Graphic. A Point geometry will be relatively straightforward, but a Polygon or Polyline would be more complex, and the KML spec for Geometries (KML Reference  |  Keyhole Markup Language  |  Google Developers ) is not exactly the same as the Runtime geometries, so you'd have to do more work for those. My guess is you'd put the Attributes of the Runtime Graphic into the ExtendedData of the Placemark (although again, the models are different). 

I think one key point is that if you are in control of writing out exactly the KML that you read back in, you're probably OK. But if you want to be able to read in any KML from any source and try and translate that into Runtime graphics, that would be much less feasible, because of what the KML spec contains. Let us know how you get on with this if you try it!

Regards

Shelly

AhmetEmre
New Contributor III

Thanks Shelly for reply but in this case (since as you said there is not direct conversion between KML and graphics layer) saving lines, points etc. objects not as KML file but serialized geometry objects is more feasible. Since geometry objects have serialization support, looping all objects of a graphics layer and put them in a serialized file. Does this sound right ?

0 Kudos
ShellyGill1
Esri Contributor

Yes, if you're not bothered about the KML aspect at all, then I agree it makes more senses to serialize more directly. You'd have to serialise attributes separately, but that should be fairly straightforward.