Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help needed with fastkml
#1
Hi,

I would like to parse an existing kml file and change some attributes, for instance the color of a polygon.

This is the code I used:
with open(KMLFILE, 'rt', encoding="utf-8") as myfile:
    DOC=myfile.read()
INPUT = kml.KML()
OUTPUT = kml.KML()
INPUT.from_string(DOC)
FEATURES = list(INPUT.features())
f2 = list(FEATURES[0].features())
So far so good.
print(f2[0].name) -> gives me the name of the first placemark.
print(f2[0].geometry) -> gives me the coordinates of the polygon of the first placemark.

I don't seem to find a lot of information on fastkml and how the attributes are read.
I would like to add some styles like color to the polygons, but I don't have any clue how to do this.
Can anyone point me to some more information? Ideally some more examples of fastkml would be nice!

Rgds,
Johan.
Reply
#2
Hello there!

I agree; there is not a lot of info about fastKML, but its a really good library - I worked with it on a project last 3 months. Needless to say, I understood lots of it using it.

Looking at your code, I see you found this much through experimentation. However, your code still needs refining. It would take me a long while writing down everything here.

Here's a resource I wrote for Fastkml : https://medium.com/@wwaryan/the-definite...b8e19b8454
This will guide you on how to read KML Files, extract geometries and styles and so on.

As for your question, to use styles to colour polygons; I did it in my project. This will also give you a clear view of how fastkml example. Here's the link of the code : https://bitbucket.org/wxmetvis/mss/src/d...kwidget.py

Here's a link to my project video : You can see what I did. https://www.youtube.com/watch?v=G4aPIRLBz9U

Feel free to hit me up if you have any doubts :))

Hope this helps. Cheers!
Reply
#3
here's the google base page for several KML documents: https://developers.google.com/kml/documentation
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020