簡體   English   中英

從 OSM 檢索 gpx 路線周圍特定半徑內的露營地

[英]Retrieve campsites within a specific radius around a gpx route from OSM

即將到來 spring 我將從阿姆斯特丹步行到羅馬。 我已經計划好了路線。 現在我想在路線周圍找到露營地,並找到我永遠不必在路線周圍的露營地之間步行超過 35 公里的最佳方式。 有沒有人有什么建議?

我讓它與以下代碼一起工作:

import gpxpy
import shapely.geometry as geometry
from shapely.geometry import LineString
import pyproj 
import osmnx as ox
import geopandas as gpd
import shapely
from pyproj import Transformer

#parse the GPX file
with open('path/file.gpx', 'r') as gpx_file:
    gpx = gpxpy.parse(gpx_file)

track_points = [(point.latitude, point.longitude) for point in gpx.tracks[0].segments[0].points]

# check if the GPX file's coordinates are in degrees
if -180 <= track_points[0][0] <= 180 and -180 <= track_points[0][1] <= 180:
    print("The coordinates were in degrees")
    transformer = Transformer.from_crs("EPSG:4326", "EPSG:3857", always_xy=True)
    track_points = [transformer.transform(point[1], point[0]) for point in track_points]
else :
    print("The coordinates are in metres")

track_linestring = LineString(track_points)

# Create the buffer
buffer_distance = 3000 # this is a radius of 1.5 km
buffer_polygon = track_linestring.buffer(buffer_distance)

# Define the original and desired projections
inProj = pyproj.Proj(init='epsg:3857') # Web Mercator
outProj = pyproj.Proj(init='epsg:4326') # WGS 84

# Convert the coordinates of the Polygon object
buffer_polygon_4326 = shapely.ops.transform(lambda x, y: pyproj.transform(inProj, outProj, x, y), buffer_polygon)

# extract all the tourism places within the buffer zone
tourism_places = ox.geometries.geometries_from_polygon(buffer_polygon_4326, tags={'tourism': 'True'})

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM