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:
4
.vscode/settings.json
vendored
Normal file
4
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"python.linting.pylintEnabled": true,
|
||||||
|
"python.linting.enabled": true
|
||||||
|
}
|
||||||
Binary file not shown.
Binary file not shown.
BIN
__pycache__/places.cpython-310.pyc
Normal file
BIN
__pycache__/places.cpython-310.pyc
Normal file
Binary file not shown.
Binary file not shown.
16
main.py
16
main.py
@@ -1,9 +1,14 @@
|
|||||||
from osm import OSM
|
from osm import OSM
|
||||||
|
from places import Shops
|
||||||
from publicTransport import PublicTransportAccessibility
|
from publicTransport import PublicTransportAccessibility
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
# 52.9152386,,15.96z
|
||||||
# bhv 53.51500036203292, 8.603602165157444
|
# bhv 53.51500036203292, 8.603602165157444
|
||||||
lon = 8.603602165157444 # 8.6039883
|
|
||||||
lat = 53.51500036203292 # 52.51608
|
# TODO Get User input
|
||||||
|
lon = 8.8285578 # 8.6039883
|
||||||
|
lat = 52.9152386 # 52.51608
|
||||||
|
|
||||||
# TODO Get real value based on a metric radius
|
# TODO Get real value based on a metric radius
|
||||||
areaHeightRadius = 0.01 # 0.01
|
areaHeightRadius = 0.01 # 0.01
|
||||||
@@ -21,14 +26,13 @@ requestsUrlParams = f"?bbox={minLon},{minLat},{maxLon},{maxLat}"
|
|||||||
print(requestUrl + requestsUrlParams)
|
print(requestUrl + requestsUrlParams)
|
||||||
|
|
||||||
print("Downloading OSM-File...")
|
print("Downloading OSM-File...")
|
||||||
# TODO Check if banned from overpass-api
|
# TODO Check if banned from overpass-api MAYBE get alternative API then
|
||||||
r = requests.get(requestUrl + requestsUrlParams, headers={'Content-Type': 'application/xml'})
|
r = requests.get(requestUrl + requestsUrlParams, headers={'Content-Type': 'application/xml'})
|
||||||
print("Done: Downloading OSM-File")
|
print("Done: Downloading OSM-File")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
osm = OSM(r.text)
|
osm = OSM(r.text)
|
||||||
pta = PublicTransportAccessibility(osm)
|
pta = PublicTransportAccessibility(osm)
|
||||||
|
shops = Shops(osm)
|
||||||
|
|
||||||
print("Bus:" + str(pta.isBusAccessible()))
|
print("Bus:" + str(pta.isBusAccessible()))
|
||||||
print("Tram:" + str(pta.isTramAccessible()))
|
print("Tram:" + str(pta.isTramAccessible()))
|
||||||
@@ -36,3 +40,5 @@ print("Light Rail:" + str(pta.isLightRailAccessible()))
|
|||||||
print("Subway:" + str(pta.isSubwayAccessible()))
|
print("Subway:" + str(pta.isSubwayAccessible()))
|
||||||
print("Train:" + str(pta.isTrainAccessible()))
|
print("Train:" + str(pta.isTrainAccessible()))
|
||||||
print("Monorail:" + str(pta.isMonorailAccessible()))
|
print("Monorail:" + str(pta.isMonorailAccessible()))
|
||||||
|
|
||||||
|
print(shops.countOfShops())
|
||||||
|
|||||||
19
objects.py
19
objects.py
@@ -12,7 +12,24 @@ class Node:
|
|||||||
|
|
||||||
class NodeTag:
|
class NodeTag:
|
||||||
def __init__(self, _id, _nodeId, _key, _value):
|
def __init__(self, _id, _nodeId, _key, _value):
|
||||||
self.id = _id
|
self.id = int(_id)
|
||||||
self.nodeId = int(_nodeId)
|
self.nodeId = int(_nodeId)
|
||||||
self.key = str(_key)
|
self.key = str(_key)
|
||||||
self.value = str(_value)
|
self.value = str(_value)
|
||||||
|
|
||||||
|
class Way:
|
||||||
|
def __init__(self, _id, _version, _timestamp, _changeset, _uid, _user):
|
||||||
|
self.id = int(_id)
|
||||||
|
self.version = str(_version)
|
||||||
|
self.timestamp = str(_timestamp)
|
||||||
|
self.changeset = int(_changeset)
|
||||||
|
self.uid = int(_uid)
|
||||||
|
self.user = str(_user)
|
||||||
|
|
||||||
|
|
||||||
|
class WayTag:
|
||||||
|
def __init__(self, _id, _wayId, _key, _value):
|
||||||
|
self.id = int(_id)
|
||||||
|
self.wayId = int(_wayId)
|
||||||
|
self.key = str(_key)
|
||||||
|
self.value = str(_value)
|
||||||
|
|||||||
37
osm.py
37
osm.py
@@ -1,16 +1,19 @@
|
|||||||
from objects import Node, NodeTag
|
from objects import Node, NodeTag, Way, WayTag
|
||||||
|
|
||||||
class OSM:
|
class OSM:
|
||||||
def __init__(self, _osmContent):
|
def __init__(self, _osmContent):
|
||||||
self.osmContent = str(_osmContent)
|
self.osmContent = str(_osmContent)
|
||||||
self.nodeList = []
|
self.nodeList = []
|
||||||
self.nodeTagList = []
|
self.nodeTagList = []
|
||||||
|
self.wayList = []
|
||||||
|
self.wayTagList = []
|
||||||
self.parseOsmContent()
|
self.parseOsmContent()
|
||||||
|
|
||||||
def parseOsmContent(self):
|
def parseOsmContent(self):
|
||||||
lines = self.osmContent.split("\n")
|
lines = self.osmContent.split("\n")
|
||||||
|
|
||||||
nodeLines = []
|
nodeLines = []
|
||||||
|
wayLines = []
|
||||||
|
|
||||||
for line in lines:
|
for line in lines:
|
||||||
if "<node" in line:
|
if "<node" in line:
|
||||||
@@ -29,6 +32,38 @@ class OSM:
|
|||||||
nodeLines = []
|
nodeLines = []
|
||||||
elif len(nodeLines) > 0:
|
elif len(nodeLines) > 0:
|
||||||
nodeLines.append(line)
|
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):
|
def createNode(self, lines):
|
||||||
nodeId = ""
|
nodeId = ""
|
||||||
|
|||||||
35
places.py
Normal file
35
places.py
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
from operator import itemgetter
|
||||||
|
|
||||||
|
class Shops:
|
||||||
|
def __init__(self, _osm):
|
||||||
|
self.osm = _osm
|
||||||
|
|
||||||
|
def getAllShops(self):
|
||||||
|
shopList = []
|
||||||
|
|
||||||
|
for tag in self.osm.nodeTagList:
|
||||||
|
if tag.key == "shop":
|
||||||
|
shopList.append(tag.value)
|
||||||
|
|
||||||
|
for tag in self.osm.wayTagList:
|
||||||
|
if tag.key == "shop":
|
||||||
|
shopList.append(tag.value)
|
||||||
|
return shopList
|
||||||
|
|
||||||
|
def countOfShops(self):
|
||||||
|
shopList = self.getAllShops()
|
||||||
|
countDict = []
|
||||||
|
|
||||||
|
if shopList:
|
||||||
|
def isInDict(name):
|
||||||
|
for a in countDict:
|
||||||
|
if a['name'] == name:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
for shop in shopList:
|
||||||
|
print(shop)
|
||||||
|
if not isInDict(shop):
|
||||||
|
print("add" + str(shopList.count(shop)))
|
||||||
|
countDict.append({'name': shop, 'count': shopList.count(shop)})
|
||||||
|
return sorted(countDict, key=itemgetter('count'), reverse=True)
|
||||||
Reference in New Issue
Block a user