import .kml Function?

Topics: Feature Requests
Jan 10, 2012 at 1:07 PM

Hello Gmap Community,

is there any interest to implement a .kml import? All geofeatures(point, line, polygon) are realized by radioman.

Are there allready some codesnippets?

bye EDE

Jan 20, 2012 at 9:25 PM

KMZ would be better (okay, I know it's just a zip wrapper, but better to support it properly).

 

I think this would be a very useful thing. I'm surprised there has been no other comment!

Feb 11, 2012 at 11:04 PM

Same here... Is kind of a surprise not finding discussions about this theme... Any help on how to import Kml would be appreciated. 

Feb 21, 2012 at 1:14 PM

You can use SharpKml for that. It's very easy to use with GMap.net, so it takes not a lot of time to write a wrapper.

For example loading Polygons onto the map (quick'n'dirty-solution just to illustrate the idea):

using SharpKml;
using SharpKml.Base;
using SharpKml.Dom;
using SharpKml.Engine;

/* ... */
                        // Load KML-Data into program
                        KmlFile kmlData = KmlFile.Load(file);

                        GMapOverlay overlay = new GMapOverlay(file);
                        mapController.Overlays.Add(overlay);
                        foreach (var poly in kmlData.Root.Flatten().OfType<Polygon>())
                        {
                            // Fetch path from KML-Data
                            List<PointLatLng> path = new List<PointLatLng>();
                            foreach (Vector i in poly.OuterBoundary.LinearRing.Coordinates)
                                path.Add(new PointLatLng(i.Latitude, i.Longitude));

                            // Add Polygon to Map-Overlay
                            GMapPolygon pol = new GMapPolygon(path, System.IO.Path.GetFileNameWithoutExtension(file));
                            overlay.Polygons.Add(pol);
                        }

Feb 21, 2012 at 8:16 PM

Thanks, wanne try it tomorrow.

EDE

Mar 17, 2012 at 8:30 PM
Edited Mar 17, 2012 at 8:31 PM

Thank you neurotroph, it works. Had to change from VS2008 to VS2010 because sharpKML only works with .Net Framework 4. But it was worth it ;)

Linq is needed to, otherwise it doesn't recognize "OfType".


Aug 22, 2013 at 11:25 PM
neurotroph,

THANK YOU!!! This thread really helped me a ton in getting my app to load KML files... Thanks!