wip
This commit is contained in:
parent
1c9f59c644
commit
372b0df773
@ -4,15 +4,17 @@ import csv
|
|||||||
import sys
|
import sys
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
def get_osm_gps_traces(min_lon, min_lat, max_lon, max_lat):
|
def get_osm_gps_traces(bboxes):
|
||||||
url = 'https://api.openstreetmap.org/api/0.6/trackpoints'
|
url = 'https://api.openstreetmap.org/api/0.6/trackpoints'
|
||||||
traces = []
|
traces = []
|
||||||
|
|
||||||
lon_step = 0.25
|
lon_step = 0.25
|
||||||
lat_step = 0.25
|
lat_step = 0.25
|
||||||
|
|
||||||
current_min_lon = min_lon
|
for bbox in bboxes:
|
||||||
|
min_lon, min_lat, max_lon, max_lat = map(float, bbox.split(','))
|
||||||
|
|
||||||
|
current_min_lon = min_lon
|
||||||
while current_min_lon < max_lon:
|
while current_min_lon < max_lon:
|
||||||
current_max_lon = min(current_min_lon + lon_step, max_lon)
|
current_max_lon = min(current_min_lon + lon_step, max_lon)
|
||||||
|
|
||||||
@ -20,11 +22,11 @@ def get_osm_gps_traces(min_lon, min_lat, max_lon, max_lat):
|
|||||||
while current_min_lat < max_lat:
|
while current_min_lat < max_lat:
|
||||||
current_max_lat = min(current_min_lat + lat_step, max_lat)
|
current_max_lat = min(current_min_lat + lat_step, max_lat)
|
||||||
|
|
||||||
bbox = f'{current_min_lon},{current_min_lat},{current_max_lon},{current_max_lat}'
|
bbox_str = f'{current_min_lon},{current_min_lat},{current_max_lon},{current_max_lat}'
|
||||||
print(f"Requesting bbox: {bbox}", file=sys.stderr)
|
print(f"Requesting bbox: {bbox_str}", file=sys.stderr)
|
||||||
|
|
||||||
params = {
|
params = {
|
||||||
'bbox': bbox,
|
'bbox': bbox_str,
|
||||||
'page': 0
|
'page': 0
|
||||||
}
|
}
|
||||||
headers = {
|
headers = {
|
||||||
@ -35,7 +37,7 @@ def get_osm_gps_traces(min_lon, min_lat, max_lon, max_lat):
|
|||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
traces.append(response.content)
|
traces.append(response.content)
|
||||||
else:
|
else:
|
||||||
print(f"Error fetching data for bbox {bbox}: {response.status_code} {response.text}", file=sys.stderr)
|
print(f"Error fetching data for bbox {bbox_str}: {response.status_code} {response.text}", file=sys.stderr)
|
||||||
|
|
||||||
current_min_lat += lat_step
|
current_min_lat += lat_step
|
||||||
current_min_lon += lon_step
|
current_min_lon += lon_step
|
||||||
@ -68,15 +70,12 @@ def save_to_csv(data, file):
|
|||||||
writer.writerows(data)
|
writer.writerows(data)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
parser = argparse.ArgumentParser(description='Fetch and output OSM GPS traces for a given bounding box.')
|
parser = argparse.ArgumentParser(description='Fetch and output OSM GPS traces for given bounding boxes.')
|
||||||
parser.add_argument('min_lon', type=float, help='Minimum longitude of the bounding box')
|
parser.add_argument('bboxes', nargs='+', help='Bounding boxes in the format min_lon,min_lat,max_lon,max_lat')
|
||||||
parser.add_argument('min_lat', type=float, help='Minimum latitude of the bounding box')
|
|
||||||
parser.add_argument('max_lon', type=float, help='Maximum longitude of the bounding box')
|
|
||||||
parser.add_argument('max_lat', type=float, help='Maximum latitude of the bounding box')
|
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
gpx_data_traces = get_osm_gps_traces(args.min_lon, args.min_lat, args.max_lon, args.max_lat)
|
gpx_data_traces = get_osm_gps_traces(args.bboxes)
|
||||||
print(f"Collected {len(gpx_data_traces)} trace segments", file=sys.stderr)
|
print(f"Collected {len(gpx_data_traces)} trace segments", file=sys.stderr)
|
||||||
|
|
||||||
all_data = []
|
all_data = []
|
||||||
|
Loading…
Reference in New Issue
Block a user