Include more railway features, don't add tunnels

From mespieler.

8333805787116b9d5cbc91b67f2a6b9bac4922b1
This commit is contained in:
Stuart Buchanan 2022-09-25 18:32:25 +01:00
parent 8966dcd737
commit 50fd23d72c

View File

@ -105,67 +105,69 @@ def parse_way(way) :
railway = way.tags.get("railway")
feature_type = "None"
if (highway=="motorway_junction") or (highway=="motorway") or (highway=="motorway_link"):
width = 15.0
feature_type = "ws30Freeway"
curr_road_count = curr_road_count + 1
if way.tags.get("tunnel") == None or way.tags.get("tunnel") != "yes":
if (highway=="primary") or (highway=="trunk") or (highway=="trunk_link") or (highway=="primary_link") :
width = 12.0
feature_type = "ws30Freeway"
curr_road_count = curr_road_count + 1
if (highway=="motorway_junction") or (highway=="motorway") or (highway=="motorway_link"):
width = 15.0
feature_type = "ws30Freeway"
curr_road_count = curr_road_count + 1
if (highway=="secondary") or (highway=="secondary_link") :
width = 12.0
feature_type = "ws30Road"
curr_road_count = curr_road_count + 1
if (highway=="primary") or (highway=="trunk") or (highway=="trunk_link") or (highway=="primary_link") :
width = 12.0
feature_type = "ws30Freeway"
curr_road_count = curr_road_count + 1
if (highway=="unclassified") or (highway=="tertiary") or (highway=="tertiary_link") or (highway=="service") or (highway=="residential"):
width = 6.0
feature_type = "ws30Road"
curr_road_count = curr_road_count + 1
if (waterway=="river") or (waterway=="canal") :
width = 10.0
feature_type = "ws30River"
curr_river_count = curr_river_count + 1
if (highway=="secondary") or (highway=="secondary_link") :
width = 12.0
feature_type = "ws30Road"
curr_road_count = curr_road_count + 1
if (railway=="rail") or (railway=="preserved") or (railway=="disused") :
width = 4.2 # Standard guage ~ 1.4m, with twice the space either side
feature_type = "ws30Railway"
if (highway=="unclassified") or (highway=="tertiary") or (highway=="tertiary_link") or (highway=="service") or (highway=="residential"):
width = 6.0
feature_type = "ws30Road"
curr_road_count = curr_road_count + 1
if (waterway=="river") or (waterway=="canal") :
width = 10.0
feature_type = "ws30River"
curr_river_count = curr_river_count + 1
# Use the width if defined and parseable
if (way.tags.get("width") != None) :
width_str = way.tags.get("width")
try:
if (' m' in width_str) :
width = float(width_str[0:width_str.find(" m")])
if (' ft' in width_str) :
width = 0.3 * float(width_str[0:width_str.find(" ft")])
except ValueError :
print("Unable to parse width " + width_str)
if (railway=="rail") or (railway=="preserved") or (railway=="disused") :
width = 4.2 # Standard guage ~ 1.4m, with twice the space either side
feature_type = "ws30Railway"
# Use the lit tag if defined and parseable
if (way.tags.get("lit") != None) :
lit_str = way.tags.get("lit")
if ((lit_str == "no") or (lit == "disused")) :
# Specific tags for unlit ways
lit = 0
else :
# Everything else indicates some form of lighting
lit = 1
# Use the width if defined and parseable
if (way.tags.get("width") != None) :
width_str = way.tags.get("width")
try:
if (' m' in width_str) :
width = float(width_str[0:width_str.find(" m")])
if (' ft' in width_str) :
width = 0.3 * float(width_str[0:width_str.find(" ft")])
except ValueError :
print("Unable to parse width " + width_str)
if (feature_type != "None") :
# It's a road or river. Add it to appropriate tile entries.
tileids = set()
# Use the lit tag if defined and parseable
if (way.tags.get("lit") != None) :
lit_str = way.tags.get("lit")
if ((lit_str == "no") or (lit == "disused")) :
# Specific tags for unlit ways
lit = 0
else :
# Everything else indicates some form of lighting
lit = 1
for pt in way.nodes:
lon = float(pt.lon)
lat = float(pt.lat)
idx = calc_tile.calc_tile_index([lon, lat])
if ((float(lon1) <= lon <= float(lon2)) and (float(lat1) <= lat <= float(lat2)) and (idx not in tileids)) :
# Write the feature to a bucket provided it's within the lat/lon bounds and if we've not already written it there
write_feature(lon, lat, way.nodes, feature_type, width, lit)
tileids.add(idx)
if (feature_type != "None") :
# It's a road or river. Add it to appropriate tile entries.
tileids = set()
for pt in way.nodes:
lon = float(pt.lon)
lat = float(pt.lat)
idx = calc_tile.calc_tile_index([lon, lat])
if ((float(lon1) <= lon <= float(lon2)) and (float(lat1) <= lat <= float(lat2)) and (idx not in tileids)) :
# Write the feature to a bucket provided it's within the lat/lon bounds and if we've not already written it there
write_feature(lon, lat, way.nodes, feature_type, width, lit)
tileids.add(idx)
def writeOSM(result):
for child in result.ways:
@ -185,7 +187,7 @@ for lat in range(int(lat1), int(lat2)):
writeOSM(result)
railway_query = "("
railway_types = ["rail", "preserved", "disused"]
railway_types = ["rail", "preserved", "disused", "subway", "narrow_gauge"]
for r in railway_types :
railway_query = railway_query + "way[\"railway\"=\"" + r + "\"](" + osm_bbox + ");"