如何将纬度和经度距离转换为米?
How to turn latitude and longitude distance into meters?
我能够得到一个点和 LINESTRING 之间的最短距离。我假设的“epsg=4326”中的点和线串是纬度和经度。如何确定距离是米还是公里。
我能得到下面的距离
import geopandas as gpd
import shapely.wkt
import shapely.geometry
line_string = ["LINESTRING (-1.15.12 9.9, -1.15.13 9.93)", "LINESTRING (-2.15.12 8.9, -2.15.13 8.93)"]
# fix invalid wkt string...
line_string = ["LINESTRING (-1.15 9.9, -1.15 9.93)", "LINESTRING (-2.15 8.9, -2.15 8.93)"]
point = "POINT (5.41 3.9)"
gdf_p = gpd.GeoDataFrame(geometry=[shapely.wkt.loads(point)])
gdf_l = gpd.GeoDataFrame(geometry=pd.Series(line_string).apply(shapely.wkt.loads))
df_n = gpd.sjoin_nearest(gdf_p, gdf_l).merge(gdf_l, left_on="index_right", right_index=True)
df_n["distance"] = df_n.apply(lambda r: r["geometry_x"].distance(r["geometry_y"]), axis=1)
df_n
您需要将您的几何图形从 EPSG:4326
(十进制度)重新投影到公制坐标系,例如EPSG:3857
或一些局部坐标系以获得更高的精度。
您只需要修改这些行:
gdf_p = gpd.GeoDataFrame(geometry=[shapely.wkt.loads(point)]).set_crs('EPSG:4326').to_crs('EPSG:3857')
gdf_l = gpd.GeoDataFrame(geometry=pd.Series(line_string).apply(shapely.wkt.loads)).set_crs('EPSG:4326').to_crs('EPSG:3857')
我能够得到一个点和 LINESTRING 之间的最短距离。我假设的“epsg=4326”中的点和线串是纬度和经度。如何确定距离是米还是公里。
我能得到下面的距离
import geopandas as gpd
import shapely.wkt
import shapely.geometry
line_string = ["LINESTRING (-1.15.12 9.9, -1.15.13 9.93)", "LINESTRING (-2.15.12 8.9, -2.15.13 8.93)"]
# fix invalid wkt string...
line_string = ["LINESTRING (-1.15 9.9, -1.15 9.93)", "LINESTRING (-2.15 8.9, -2.15 8.93)"]
point = "POINT (5.41 3.9)"
gdf_p = gpd.GeoDataFrame(geometry=[shapely.wkt.loads(point)])
gdf_l = gpd.GeoDataFrame(geometry=pd.Series(line_string).apply(shapely.wkt.loads))
df_n = gpd.sjoin_nearest(gdf_p, gdf_l).merge(gdf_l, left_on="index_right", right_index=True)
df_n["distance"] = df_n.apply(lambda r: r["geometry_x"].distance(r["geometry_y"]), axis=1)
df_n
您需要将您的几何图形从 EPSG:4326
(十进制度)重新投影到公制坐标系,例如EPSG:3857
或一些局部坐标系以获得更高的精度。
您只需要修改这些行:
gdf_p = gpd.GeoDataFrame(geometry=[shapely.wkt.loads(point)]).set_crs('EPSG:4326').to_crs('EPSG:3857')
gdf_l = gpd.GeoDataFrame(geometry=pd.Series(line_string).apply(shapely.wkt.loads)).set_crs('EPSG:4326').to_crs('EPSG:3857')