Fix drawing outside borders
This commit is contained in:
parent
1167747fae
commit
931b30cbce
1 changed files with 14 additions and 20 deletions
34
map.py
34
map.py
|
|
@ -111,7 +111,6 @@ def main():
|
||||||
del arguments
|
del arguments
|
||||||
|
|
||||||
bounds, nodes, ways, relations = parse_xml(osm_path)
|
bounds, nodes, ways, relations = parse_xml(osm_path)
|
||||||
print(f'{bounds} {len(nodes)=} {len(ways)=} {len(relations)=}')
|
|
||||||
|
|
||||||
if convert_data:
|
if convert_data:
|
||||||
with (osm_path.parent / f'{osm_path.stem}.json').open(mode='w', encoding='utf-8') as json_file:
|
with (osm_path.parent / f'{osm_path.stem}.json').open(mode='w', encoding='utf-8') as json_file:
|
||||||
|
|
@ -169,9 +168,7 @@ def main():
|
||||||
coords = []
|
coords = []
|
||||||
for node_id in way.nodes:
|
for node_id in way.nodes:
|
||||||
node = nodes[node_id]
|
node = nodes[node_id]
|
||||||
new_coord = (
|
new_coord = ((node.lon - bounds.minlon) * lon_scale, map_height - ((node.lat - bounds.minlat) * lat_scale))
|
||||||
min(max((node.lon - bounds.minlon) * lon_scale, 0), map_width),
|
|
||||||
min(max(map_height - ((node.lat - bounds.minlat) * lat_scale), 0), map_height))
|
|
||||||
if not coords or new_coord != coords[-1]:
|
if not coords or new_coord != coords[-1]:
|
||||||
coords.append(new_coord)
|
coords.append(new_coord)
|
||||||
draw.polygon(coords, fill=color, outline=outline, width=width)
|
draw.polygon(coords, fill=color, outline=outline, width=width)
|
||||||
|
|
@ -181,9 +178,7 @@ def main():
|
||||||
coords = []
|
coords = []
|
||||||
for node_id in way.nodes:
|
for node_id in way.nodes:
|
||||||
node = nodes[node_id]
|
node = nodes[node_id]
|
||||||
new_coord = (
|
new_coord = ((node.lon - bounds.minlon) * lon_scale, map_height - ((node.lat - bounds.minlat) * lat_scale))
|
||||||
min(max((node.lon - bounds.minlon) * lon_scale, 0), map_width),
|
|
||||||
min(max(map_height - ((node.lat - bounds.minlat) * lat_scale), 0), map_height))
|
|
||||||
if not coords or new_coord != coords[-1]:
|
if not coords or new_coord != coords[-1]:
|
||||||
coords.append(new_coord)
|
coords.append(new_coord)
|
||||||
draw.line(coords, width=width, fill=color, joint=joint)
|
draw.line(coords, width=width, fill=color, joint=joint)
|
||||||
|
|
@ -221,29 +216,28 @@ def main():
|
||||||
if 'highway' in way.tags:
|
if 'highway' in way.tags:
|
||||||
match way.tags['highway']:
|
match way.tags['highway']:
|
||||||
case 'motorway' | 'motorway_link':
|
case 'motorway' | 'motorway_link':
|
||||||
draw_way_line(way, 15, (220, 160, 160), joint='curve')
|
draw_way_line(way, 25, (220, 160, 160), joint='curve')
|
||||||
case 'trunk' | 'trunk_link':
|
case 'trunk' | 'trunk_link':
|
||||||
draw_way_line(way, 13, bridge_outline if 'bridge' in way.tags else (230, 180, 130), joint='curve')
|
draw_way_line(way, 21, bridge_outline if 'bridge' in way.tags else (230, 180, 130), joint='curve')
|
||||||
draw_way_line(way, 11, (240, 200, 170), joint='curve')
|
draw_way_line(way, 19, (240, 200, 170), joint='curve')
|
||||||
case 'primary' | 'primary_link':
|
case 'primary' | 'primary_link':
|
||||||
draw_way_line(way, 11, bridge_outline if 'bridge' in way.tags else (230, 200, 110), joint='curve')
|
draw_way_line(way, 19, bridge_outline if 'bridge' in way.tags else (230, 200, 110), joint='curve')
|
||||||
draw_way_line(way, 9, (245, 225, 150), joint='curve')
|
draw_way_line(way, 17, (245, 225, 150), joint='curve')
|
||||||
case 'secondary' | 'secondary_link':
|
case 'secondary' | 'secondary_link':
|
||||||
draw_way_line(way, 11, bridge_outline if 'bridge' in way.tags else (200, 200, 140), joint='curve')
|
draw_way_line(way, 17, bridge_outline if 'bridge' in way.tags else (200, 200, 140), joint='curve')
|
||||||
draw_way_line(way, 9, (220, 220, 180), joint='curve')
|
draw_way_line(way, 15, (220, 220, 180), joint='curve')
|
||||||
case 'tertiary' | 'tertiraty_link':
|
case 'tertiary' | 'tertiraty_link':
|
||||||
draw_way_line(way, 9, bridge_outline if 'bridge' in way.tags else (160, 160, 160), joint='curve')
|
draw_way_line(way, 15, bridge_outline if 'bridge' in way.tags else (160, 160, 160), joint='curve')
|
||||||
draw_way_line(way, 7, (245, 245, 245), joint='curve')
|
draw_way_line(way, 13, (245, 245, 245), joint='curve')
|
||||||
case 'residential' | 'unclassified' | 'road':
|
case 'residential' | 'unclassified' | 'road':
|
||||||
draw_way_line(way, 7, bridge_outline if 'bridge' in way.tags else (160, 160, 160), joint='curve')
|
draw_way_line(way, 13, bridge_outline if 'bridge' in way.tags else (160, 160, 160), joint='curve')
|
||||||
draw_way_line(way, 5, (250, 250, 250), joint='curve')
|
draw_way_line(way, 11, (250, 250, 250), joint='curve')
|
||||||
elif 'waterway' in way.tags and way.tags['waterway'] in {'river', 'steam', 'tidal_channel', 'flowline'}:
|
elif 'waterway' in way.tags and way.tags['waterway'] in {'river', 'steam', 'tidal_channel', 'flowline'}:
|
||||||
draw_way_line(way, 11, (180, 200, 240), joint='curve')
|
draw_way_line(way, 21, (180, 200, 240), joint='curve')
|
||||||
elif 'building' in way.tags:
|
elif 'building' in way.tags:
|
||||||
draw_way_polygon(way, (190, 180, 160), outline=(120, 120, 120))
|
draw_way_polygon(way, (190, 180, 160), outline=(120, 120, 120))
|
||||||
|
|
||||||
image = cv2.cvtColor(np.asarray(image), cv2.COLOR_BGR2RGB)
|
image = cv2.cvtColor(np.asarray(image), cv2.COLOR_BGR2RGB)
|
||||||
print(f'{image.shape=}')
|
|
||||||
cv2.namedWindow('map', cv2.WINDOW_KEEPRATIO)
|
cv2.namedWindow('map', cv2.WINDOW_KEEPRATIO)
|
||||||
while cv2.waitKey(50) & 0xff != ord('q'):
|
while cv2.waitKey(50) & 0xff != ord('q'):
|
||||||
cv2.imshow('map', image)
|
cv2.imshow('map', image)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue