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/
requestsand then I would import it to Postgres usingogr2ogrwhich can be called from Python. Check this answer for an example of usingogr2ogrto import a KML into a Postgres database. – Marcelo Villa Jul 29 '19 at 19:51simplekmllibrary to get the geometries into WKT and use some regex or whatever to pull needed attributes from the description snippet. – auslander Jul 29 '19 at 21:10data = str(response.content)gets you in your case the kml file as a string. from there on you could usepykmlto access the data – zwnk Jul 30 '19 at 18:14