mirror of
https://github.com/DerTyp7/local-analyzer-python.git
synced 2025-10-29 04:22:10 +01:00
merged shops and amenities to places
This commit is contained in:
136
osm.py
136
osm.py
@@ -1,4 +1,5 @@
|
||||
from objects import Node, NodeTag, Way, WayTag, Shop
|
||||
from objects.baseObjects import Node, NodeTag, Way, WayTag, Place
|
||||
from objects.metaObjects import Address, Contact
|
||||
|
||||
class OSM:
|
||||
# TODO Average value of "last updated" to see how up to date the data is.
|
||||
@@ -8,7 +9,8 @@ class OSM:
|
||||
self.nodeTagList = []
|
||||
self.wayList = []
|
||||
self.wayTagList = []
|
||||
self.shopList = []
|
||||
self.placeList = []
|
||||
|
||||
self.parseOsmContent()
|
||||
|
||||
def parseOsmContent(self):
|
||||
@@ -45,29 +47,129 @@ class OSM:
|
||||
elif len(wayLines) > 0:
|
||||
wayLines.append(line)
|
||||
|
||||
def createShop(self, lines):
|
||||
# TODO Make sure shops are not duplicates.
|
||||
# TODO e.g. REWE(shop) is big enough to have some "Ways" of it's own and multiple nodes, which can cause duplicates.
|
||||
|
||||
nodeIds = []
|
||||
type = ""
|
||||
name = ""
|
||||
def createContact(self, lines):
|
||||
c = Contact()
|
||||
|
||||
for line in lines:
|
||||
if '<tag ' in line:
|
||||
key = str(line.split('k="')[1].split('"')[0])
|
||||
value = str(line.split('v="')[1].split('"')[0])
|
||||
|
||||
if key == "shop":
|
||||
if key == "contact:website" or key == "website":
|
||||
c.website = value
|
||||
elif key == "contact:phone" or key == "phone":
|
||||
c.phone = value
|
||||
elif key == "contact:mobile" or key == "mobile":
|
||||
c.mobile = value
|
||||
elif key == "contact:fax" or key == "fax":
|
||||
c.fax = value
|
||||
elif key == "contact:email" or key == "email":
|
||||
c.email = value
|
||||
elif key == "contact:facebook":
|
||||
c.facebook = value
|
||||
elif key == "contact:vk":
|
||||
c.vk = value
|
||||
elif key == "contact:instagram":
|
||||
c.instagram = value
|
||||
elif key == "contact:twitter":
|
||||
c.twitter = value
|
||||
elif key == "contact:youtube":
|
||||
c.youtube = value
|
||||
elif key == "contact:ok":
|
||||
c.ok = value
|
||||
elif key == "contact:webcam":
|
||||
c.webcam = value
|
||||
elif key == "contact:telegram":
|
||||
c.telegram = value
|
||||
elif key == "contact:whatsapp":
|
||||
c.whatsapp = value
|
||||
elif key == "contact:linkedin":
|
||||
c.linkedin = value
|
||||
elif key == "contact:pinterest":
|
||||
c.pinterest = value
|
||||
elif key == "contact:viper":
|
||||
c.viper = value
|
||||
elif key == "contact:foursquare":
|
||||
c.foursquare = value
|
||||
elif key == "contact:skype":
|
||||
c.skype = value
|
||||
elif key == "contact:xing":
|
||||
c.xing = value
|
||||
elif key == "contact:vhf":
|
||||
c.vhf = value
|
||||
elif key == "contact:flickr":
|
||||
c.flickr = value
|
||||
elif key == "contact:mastodon":
|
||||
c.mastodon = value
|
||||
elif key == "contact:sip":
|
||||
c.sip = value
|
||||
elif key == "contact:diaspora":
|
||||
c.diaspora = value
|
||||
elif key == "contact:gnusocial":
|
||||
c.gnusocial = value
|
||||
return c
|
||||
|
||||
def createAddress(self, lines):
|
||||
a = Address()
|
||||
|
||||
for line in lines:
|
||||
if '<tag ' in line:
|
||||
key = str(line.split('k="')[1].split('"')[0])
|
||||
value = str(line.split('v="')[1].split('"')[0])
|
||||
|
||||
if key == "addr:housenumber":
|
||||
a.housenumber = value
|
||||
elif key == "addr:street":
|
||||
a.street = value
|
||||
elif key == "addr:place":
|
||||
a.place = value
|
||||
elif key == "addr:city":
|
||||
a.city = value
|
||||
elif key == "addr:postcode":
|
||||
a.postcode = value
|
||||
elif key == "addr:country":
|
||||
a.country = value
|
||||
elif key == "addr:suburb":
|
||||
a.suburb = value
|
||||
elif key == "addr:state":
|
||||
a.state = value
|
||||
elif key == "addr:province":
|
||||
a.province = value
|
||||
return a
|
||||
|
||||
def createPlace(self, lines, isShop):
|
||||
# TODO Make sure shops are not duplicates.
|
||||
# TODO e.g. REWE(shop) is big enough to have some "Ways" of it's own and multiple nodes, which can cause duplicates.
|
||||
|
||||
nodeIds = []
|
||||
type = ""
|
||||
name = ""
|
||||
openingHours = ""
|
||||
|
||||
address = self.createAddress(lines)
|
||||
contact = self.createContact(lines)
|
||||
|
||||
for line in lines:
|
||||
if '<tag ' in line:
|
||||
key = str(line.split('k="')[1].split('"')[0])
|
||||
value = str(line.split('v="')[1].split('"')[0])
|
||||
|
||||
if key == "amenity" and not isShop:
|
||||
type = value
|
||||
elif key == "shop" and isShop:
|
||||
type = value
|
||||
elif key == "name":
|
||||
name = value
|
||||
elif key == "opening_hours":
|
||||
openingHours = value
|
||||
|
||||
elif '<nd ' in line:
|
||||
nodeIds.append(line.split('ref="')[1].split('"')[0])
|
||||
|
||||
s = Shop(nodeIds, name, type)
|
||||
self.shopList.append(s)
|
||||
elif "<node" in line:
|
||||
nodeIds.append(str(line.split('id="')[1].split('"')[0]))
|
||||
|
||||
p = Place(nodeIds, type, name, address, contact, openingHours)
|
||||
self.placeList.append(p)
|
||||
|
||||
def createWay(self, lines):
|
||||
wayId = ""
|
||||
@@ -91,7 +193,9 @@ class OSM:
|
||||
self.wayTagList.append(wt)
|
||||
|
||||
if key == "shop":
|
||||
self.createShop(lines)
|
||||
self.createPlace(lines, True)
|
||||
elif key == "amenity":
|
||||
self.createPlace(lines, False)
|
||||
|
||||
def createNode(self, lines):
|
||||
nodeId = ""
|
||||
@@ -117,4 +221,6 @@ class OSM:
|
||||
self.nodeTagList.append(nt)
|
||||
|
||||
if key == "shop":
|
||||
self.createShop(lines)
|
||||
self.createPlace(lines, True)
|
||||
elif key == "amenity":
|
||||
self.createPlace(lines, False)
|
||||
Reference in New Issue
Block a user