mirror of
https://github.com/DerTyp7/local-analyzer-python.git
synced 2025-10-29 04:22:10 +01:00
get shops
This commit is contained in:
37
osm.py
37
osm.py
@@ -1,16 +1,19 @@
|
||||
from objects import Node, NodeTag
|
||||
from objects import Node, NodeTag, Way, WayTag
|
||||
|
||||
class OSM:
|
||||
def __init__(self, _osmContent):
|
||||
self.osmContent = str(_osmContent)
|
||||
self.nodeList = []
|
||||
self.nodeTagList = []
|
||||
self.wayList = []
|
||||
self.wayTagList = []
|
||||
self.parseOsmContent()
|
||||
|
||||
def parseOsmContent(self):
|
||||
lines = self.osmContent.split("\n")
|
||||
|
||||
nodeLines = []
|
||||
wayLines = []
|
||||
|
||||
for line in lines:
|
||||
if "<node" in line:
|
||||
@@ -29,7 +32,39 @@ class OSM:
|
||||
nodeLines = []
|
||||
elif len(nodeLines) > 0:
|
||||
nodeLines.append(line)
|
||||
elif "<way" in line:
|
||||
wayLines.append(line)
|
||||
elif "</way>" in line:
|
||||
try:
|
||||
self.createWay(wayLines)
|
||||
except:
|
||||
print("Way could not be inserted")
|
||||
wayLines = []
|
||||
elif len(wayLines) > 0:
|
||||
wayLines.append(line)
|
||||
|
||||
|
||||
def createWay(self, lines):
|
||||
wayId = ""
|
||||
|
||||
for line in lines:
|
||||
if "<way" in line:
|
||||
wayId = str(line.split('id="')[1].split('"')[0])
|
||||
wayVersion = str(line.split('version="')[1].split('"')[0])
|
||||
wayTimestamp = str(line.split('timestamp="')[1].split('"')[0])
|
||||
wayChangeset = str(line.split('changeset="')[1].split('"')[0])
|
||||
wayUid = str(line.split('uid="')[1].split('"')[0])
|
||||
wayUser = str(line.split('user="')[1].split('"')[0])
|
||||
|
||||
w = Way(wayId, wayVersion, wayTimestamp, wayChangeset, wayUid, wayUser)
|
||||
self.wayList.append(w)
|
||||
|
||||
elif '<tag ' in line:
|
||||
key = str(line.split('k="')[1].split('"')[0])
|
||||
value = str(line.split('v="')[1].split('"')[0])
|
||||
wt = WayTag(len(self.wayTagList), wayId, key, value)
|
||||
self.wayTagList.append(wt)
|
||||
|
||||
def createNode(self, lines):
|
||||
nodeId = ""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user