1
0
Fork 0

WS30: Improved gencoastlines

Use Overpass API more effectively in 1x1 degree blocks,
using same technique as genroads.py
This commit is contained in:
Stuart Buchanan 2022-05-28 20:42:43 +01:00
parent 5b12f55c3f
commit 382747c2d1
2 changed files with 19 additions and 10 deletions

View file

@ -4,5 +4,5 @@ runtime.
These scripts are very simplistic and don't attempt to be particularly efficient
in their use of the API. The should be improved before use on the entire world,
as they will (and do) result in being blocked from the overpass API if used on
as they can (and do) result in being blocked from the overpass API if used on
and unreasonably large area.

View file

@ -31,8 +31,8 @@ import calc_tile
import overpy
nodes = {}
road_count = 0
river_count = 0
curr_coast_count = 0
coast_count = 0
if (len(sys.argv) != 6):
print("Simple generation of COASTLINE_LIST files")
@ -88,7 +88,7 @@ def write_feature(lon, lat, coast):
def parse_way(way) :
global road_count, river_count, lat1, lon1, lat2, lon2
global curr_coast_count, lat1, lon1, lat2, lon2
pts = []
width = 6.0
road = 0
@ -103,6 +103,7 @@ def parse_way(way) :
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
curr_coast_count = curr_coast_count + 1
write_feature(lon, lat, way.nodes)
tileids.add(idx)
@ -112,11 +113,19 @@ def writeOSM(result):
# Get River data
osm_bbox = ",".join([lat1, lon1, lat2, lon2])
api = overpy.Overpass(url="https://lz4.overpass-api.de/api/interpreter")
coast_query = "way[\"natural\"=\"coastline\"](" + osm_bbox + ");(._;>;);out;"
result = api.query(coast_query)
writeOSM(result)
for lat in range(int(lat1), int(lat2)):
for lon in range(int(lon1), int(lon2)):
osm_bbox = ",".join([str(lat), str(lon), str(lat+1), str(lon+1)])
#api = overpy.Overpass(url="https://lz4.overpass-api.de/api/interpreter")
api = overpy.Overpass(url="https://overpass.kumi.systems/api/interpreter")
coast_query = "way[\"natural\"=\"coastline\"](" + osm_bbox + ");(._;>;);out;"
curr_coast_count = 0
result = api.query(coast_query)
writeOSM(result)
print(str(lat) + "," + str(lon) + ": " + str(curr_coast_count) + " pieces of coastline")
coast_count = coast_count + curr_coast_count
print(str(lat1) + "," + str(lon1) + " " + str(lat2) + "," + str(lon2))
print("Wrote total of " + str(coast_count) + " pieces of coastline")