Made sure that the XML parser gets valid XML as otherwise the check lead to crashes in the code that generates the orthos
This commit is contained in:
parent
8774e3b6ac
commit
7b7aff4acf
35
osmxml.py
35
osmxml.py
@ -13,16 +13,23 @@
|
|||||||
|
|
||||||
|
|
||||||
import xml.dom.minidom
|
import xml.dom.minidom
|
||||||
|
from pyexpat import ExpatError
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
import os
|
import os
|
||||||
from defines import *
|
from defines import *
|
||||||
from log import *
|
from log import *
|
||||||
|
import time
|
||||||
|
|
||||||
class mstr_osmxml:
|
class mstr_osmxml:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
#self._xmlfn = mstr_datafolder + "_cache/tile_" + str(lat) + "-" + str(v) + "_" + str(lng) + "-" + str(h) + ".xml"
|
#self._xmlfn = mstr_datafolder + "_cache/tile_" + str(lat) + "-" + str(v) + "_" + str(lng) + "-" + str(h) + ".xml"
|
||||||
self._xmldata = None
|
self._xmldata = None
|
||||||
self._xmlcontent = ""
|
self._xmlcontent = ""
|
||||||
|
self._lat = 0
|
||||||
|
self._lng = 0
|
||||||
|
self._curB_lat = 0
|
||||||
|
self._curB_lng = 0
|
||||||
|
|
||||||
|
|
||||||
# Adjust bbox for when this class should persost, but acquire data for a different bbox
|
# Adjust bbox for when this class should persost, but acquire data for a different bbox
|
||||||
@ -58,7 +65,8 @@ class mstr_osmxml:
|
|||||||
mstr_msg("osmxml", "Acquiring OSM data for " + str(self._lat)+","+str(self._lng)+" - "+str(self._curB_lat)+","+str(self._curB_lng))
|
mstr_msg("osmxml", "Acquiring OSM data for " + str(self._lat)+","+str(self._lng)+" - "+str(self._curB_lat)+","+str(self._curB_lng))
|
||||||
|
|
||||||
# We will use our self-hosted API for this.
|
# We will use our self-hosted API for this.
|
||||||
while self._xmlcontent == "":
|
parse = False
|
||||||
|
while parse == False:
|
||||||
data = {
|
data = {
|
||||||
"bbox": {
|
"bbox": {
|
||||||
"lat": str(self._lat),
|
"lat": str(self._lat),
|
||||||
@ -73,21 +81,24 @@ class mstr_osmxml:
|
|||||||
}
|
}
|
||||||
r = requests.post(mstr_osm_endpoint, json=data)
|
r = requests.post(mstr_osm_endpoint, json=data)
|
||||||
|
|
||||||
self._xmlcontent = r.content
|
try:
|
||||||
|
# Attempt to parse the XML string
|
||||||
#if os.path.isfile(self._xmlfn):
|
dom = xml.dom.minidom.parseString(r.content)
|
||||||
# os.remove(self._xmlfn)
|
|
||||||
#with open(self._xmlfn, 'wb') as textfile:
|
|
||||||
# textfile.write(r.content)
|
|
||||||
|
|
||||||
# 1 second delay in case the request fails
|
|
||||||
if self._xmlcontent == "":
|
|
||||||
#if os.path.isfile(self._xmlfn) == False:
|
|
||||||
sleep(1)
|
|
||||||
|
|
||||||
|
# Check if the DOM object has a document element
|
||||||
|
if dom.documentElement:
|
||||||
# Store the content in memory
|
# Store the content in memory
|
||||||
|
self._xmlcontent = r.content
|
||||||
self._xmldata = xml.dom.minidom.parseString(self._xmlcontent)
|
self._xmldata = xml.dom.minidom.parseString(self._xmlcontent)
|
||||||
self._xmlcontent = "" # Clear
|
self._xmlcontent = "" # Clear
|
||||||
|
parse = True
|
||||||
|
|
||||||
|
except ExpatError as e:
|
||||||
|
parse = False
|
||||||
|
time.sleep(1)
|
||||||
|
except Exception as e:
|
||||||
|
parse = False
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
|
||||||
# Get all nodes from the specified OSM file
|
# Get all nodes from the specified OSM file
|
||||||
|
Loading…
x
Reference in New Issue
Block a user