From 382747c2d1465c0437b3294b581e0d002c5a8e46 Mon Sep 17 00:00:00 2001 From: Stuart Buchanan Date: Sat, 28 May 2022 20:42:43 +0100 Subject: [PATCH] WS30: Improved gencoastlines Use Overpass API more effectively in 1x1 degree blocks, using same technique as genroads.py --- ws30/README.TXT | 2 +- ws30/gencoastline.py | 27 ++++++++++++++++++--------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/ws30/README.TXT b/ws30/README.TXT index ab6bac2..6e827bf 100644 --- a/ws30/README.TXT +++ b/ws30/README.TXT @@ -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. diff --git a/ws30/gencoastline.py b/ws30/gencoastline.py index 2f40740..2757e82 100755 --- a/ws30/gencoastline.py +++ b/ws30/gencoastline.py @@ -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") +