This project has moved. For the latest updates, please go here.

Icon, LatLonBox and Saving

Feb 22, 2012 at 9:31 AM

First I'd like to congratulate you for developing this great tool. Nevertheless I've got three problems with it:

1. Why is there a difference between IconStyle.IconLink myIcon and Icon myIcon (from groundoverlay)?

2. Extracting the values from a LatLonBox (example) I get only values without seperator. For this Example 485297877485518, 4393540532972251 and so on.

<LatLonBox>
	<north>48.5297877485518</north>
	<south>43.93540532972251</south>
	<east>16.8605967559783</east>
	<west>4.741519968498992</west>
	<rotation>4.301879389290288</rotation>
</LatLonBox>

3. Saving a kml file, I've got only ANSI-Files where specific local language characters will be lost. Adding an default encoding solve this problem for me.

        public void Save(Stream stream)
        {
            Serializer serializer = new Serializer();
            serializer.Serialize(this.Root);

            using (var writer = new StreamWriter(stream, System.Text.Encoding.Default))
            {
                writer.Write(serializer.Xml);
            }
        }

Thanks in advance
Rainer

Coordinator
Feb 22, 2012 at 10:26 AM

Hi Rainer,

Thanks for using the library! While there doesn't appear to be a difference between IconLink and Icon, the specification mandates two separate objects; §12.9 lists Icon as a special child of IconStyle and §13.1 lists Icon as effectively an alias for Link.

Regarding your second point, the following code works for me:

using System;
using SharpKml.Base;
using SharpKml.Dom;

public static class Program
{
    public static void Main(string[] args)
    {
        const string kml =
@"<LatLonBox>
<north>48.5297877485518</north>
<south>43.93540532972251</south>
<east>16.8605967559783</east>
<west>4.741519968498992</west>
<rotation>4.301879389290288</rotation>
</LatLonBox>";

        var parser = new Parser();
        parser.ParseString(kml, false);
        LatLonBox box = (LatLonBox)parser.Root;
        Console.WriteLine("North: {0}\nSouth: {1}\nEast:  {2}\nWest:  {3}",
            box.North,
            box.South,
            box.East,
            box.West);
    }
}

However, looking through the source code and it appears as though the parsing might be sensitive to the current culture (i.e. if the above doesn't work for you try adding System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture; before the call to parser.ParseStrin and see if that works). If changing the culture works can you let me know what your system language is so I can create a test case and fix the bug.

The last issue you mention isn't a problem with the serializer as it uses InvariantCulture - I think it's more an issue with storing the returned string.

Thanks again and if you can let me know about you language settings I'll get the code updated (I'm currently working on SilverLight support so it would be nice to update everything at the same time.)

Sam

Feb 22, 2012 at 11:15 AM

Hello Sam,

I'm excited about this quick response!

Your example didn't work for me either. After adding the CurrentCulture setting it worked. By the way, reading coordinates results the right values, this problem occurs only with the LatLonBox.

At last, I'm from Germany got a lot of ÄÖÜ...

Thank you very much!

Rainer

Coordinator
Feb 22, 2012 at 11:46 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.