I have a REST KML service that I am trying to import into a PostgreSQL table using Python 3. I haven't ever dealt directly with a KML service before, only JSON, and I'm having some trouble finding a way to consume this format. With JSON I use the response library similar to this:
import requests
import responses
response = requests.get('http://url_or_ip')
data = response.json()
I can then iterate through the data variable and get what I need, but I haven't found anything similar for KML. Is there a similar method to iterate through KML?
For reference, the service I'm trying to consume is located here: http://206.74.144.42/eitms/roadconditions/
requests
and then I would import it to Postgres usingogr2ogr
which can be called from Python. Check this answer for an example of usingogr2ogr
to import a KML into a Postgres database.simplekml
library to get the geometries into WKT and use some regex or whatever to pull needed attributes from the description snippet.data = str(response.content)
gets you in your case the kml file as a string. from there on you could usepykml
to access the data