samcragg / sharpkml

SharpKML is an implementation of the Open Geospatial Consortium (OGC) KML 2.2 standard developed in C#, able to read/write both KML files and KMZ files.
MIT License
158 stars 51 forks source link

Google Earth InnerBoundary Nesting #4

Closed DSchougaard closed 6 years ago

DSchougaard commented 6 years ago

It would appears as if Google Earth consequently "breaks" the written standard for a Polygon with multiple InnerBoundaries.

Instead of having:

They serialize it as:

When parsing such a file with SharpKML, only the last InnerBoundary is attached to the Polygon.

Suggestion: Add the feature of parsing such a Google Earth file, but convert it to valid KML 2.2 notation, with multiple InnerBoundaries instead.

samcragg commented 6 years ago

Checking the schema (in both 2.2 and 2.3) and there should only be one LinearRing, so it's odd it's choosing to serialize it like that.

My initial thoughts are to make Element.AddChild virtual so that InnerBoundary can override it and if it already has a LinearRing set it could add a new InnerBoundary to the Parent.

I'll see if I have time over the weekend to look at it.

DSchougaard commented 6 years ago

It is a weird way to serialize it. I tried forcing the KML to contain multiple InnerBoundaries instead, loading it into Google Earth, and finally re-saving it. It consistently goes against the specs.

I was looking at using the set'er for the LinearRing, but I ran into the problem that the InnerBoundary did not know its parent at the given time.

DSchougaard commented 6 years ago

Wouldn't it rather be Polygonwhich would need to override AddChild? Overriding AddChildin InnerBoundary, still results in its parent being null.

samcragg commented 6 years ago

That should be fixed now in version 3.0.2.

You were right about the parent not being set - I divided element creation and population into two separate steps now so that the change was easier to implement.

I added a unit test that hopefully shows the original problem, but if you have any issues let me know and I'll take another look at it.