0

I'm using fastkml in python to parse a large kml file where Google Earth has made a new style for every placemark.

I'm trying to parse subfolders which contain a point placemark and/or a polygon placemark, whereby each placemark is assigned one of 5 icon styles or one of 5 polygon styles (respectively), then apply that style accordingly.

Eg.

root/fldr1/num1/pm1 
if pm1 is Point:
    pm1.styleUrl = "#point_class2"
elif pm1 is Polygon:
    pm1.styleUrl = "#poly_class2"
else:
    raise Exception ("Nope")
  1. Should/(can) I merge the styleUrls?
  2. Is there a better way I should go about tidying 50000 lines of superfluous Google Earth-created styles?

NB. I asked a similar more specific question here

1

Yes, you can absolutely merge and consolidate Styles in a KML file. It's often the first thing I do when customizing a KML generated by Google Earth (which often has duplicates or other unnecessary styles).

All you have to do is put your new simplified, shared styles in the top level Document, and then ensure that the styleUrl in each Feature (Placemark, Overlay, etc.) points at the correct shared style. I often do it by hand-editing one of the existing styles to be the way I want it, deleting all the other existing styles, and then doing a regex find/replace to update all the styleUrl tag contents with the pointer to my new style. Since it sounds like you want to apply a handful of new styles in the same KML file, you'll need something more sophisticated to parse each feature and apply the desired styleUrls.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.