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

Using KML files from other sources may cause problems

Jun 1, 2011 at 6:37 PM

I posted a query earlier about having difficulty reading already existing files. Please see the discussion on SharpKML - Terrific. In this discussion I posted a file which did not want to load. However I found if I altered the line:-

<kml xmlns="http://earth.google.com/kml/2.2">

to

<kml xmlns="http://www.opengis.net/kml/2.2">

then it did load in.

 

 

Jun 1, 2011 at 10:27 PM
Edited Jun 1, 2011 at 10:29 PM

This is a known issue when working with legacy files which do not follow the OGC standard.

I've updated the documentation and added a Legacy Files section which should (hopefully) help in this case.

Jun 2, 2011 at 9:10 AM

Sam, thanks for outlining the problem with legacy KML files. I have written a small subset of reading and writing KML files as well as drawing them on PC and Mobile devices over the years and was keen to adopt your scheme that obeyed the more rigorous OGC standard. Here is a sample (overlaid on Google Earth) of some parcels collected by some locals in Laos on a windows mobile device using my old scheme. The sample KML is included. If I exchange your Sample.kml for the laos.kml one and then try this in your ‘examples’ app and do the ‘SortParcels’ option only 4 of the 45 parcels are identified and listed. Unfortunately all Placemarks are called ‘Parcel’ as that is the name of the GIS item (see picture below). Is this also a legacy issue where objects are not embedded or grouped together in the proper manner and thus are not identified as ‘Placemark’ ?

I do apologise for sending the query in this form as I did not know how to present it otherwise to illustrate my problem. I also apologise for asking too many questions about this issue but you’ve written some good stuff and so few people know about it.

Best wishes

Gordon Pagan

Jun 2, 2011 at 2:57 PM
Edited Jun 2, 2011 at 2:58 PM

Hi Gordon,

No need to apologise for asking any questions - if you're stuck using the library then this is the way to get help!

I've not had much chance to work with older kml but if it's something you could send across I'd be happy to take a look. Unfortunately you can't add attachments to your postings on CodePlex but you can either use pastebin.com (or a similar site) and post the link here or send me your email address using the contact option on my profile page and I'll send you an email so you can send me the file and I'll try to help out.

Sam

Jun 4, 2011 at 10:27 AM
samcragg wrote:

This is a known issue when working with legacy files which do not follow the OGC standard.

I've updated the documentation and added a Legacy Files section which should (hopefully) help in this case.


Sam you are definitely a programmer of the highest calibre. As a coder myself (trying to improve over the last 40 years or so), I must take my hat off to you. By gum, the solution you proposed did the trick! For any one reading this memo, Sam suggested loading in legacy files (or any existing Google Earth file) by means of the following routine:-

    private static KmlFile ParseLegacyFile(string path)
    {
        // Manually parse the Xml
        string xml = File.ReadAllText(path);

        Parser parser = new Parser();
        parser.ParseString(xml, false); // Ignore the namespaces

        // The element will be stored in parser.Root - wrap it inside a KmlFile.
        return KmlFile.Create(parser.Root, true);
    }

Great one Sam. I keep saying it but it's true - You did a great piece of work creating this library.

Thanks again

Gordon Pagan