gpt4 book ai didi

python - 计算包含地理坐标的线串的边界框

转载 作者:太空宇宙 更新时间:2023-11-03 17:59:44 24 4
gpt4 key购买 nike

我从谷歌地图方向 API 计算了线串。我将线串转换为 GEOSGeometry 对象。我需要另一个区域,该区域覆盖距线串对象距离为“d”的所有点。距离单位为米、公里。GEOS API 提供了 GEOSGeometry.buffer(width,quadsegs=8) 来执行此操作,这在 2D 投影中效果很好。

但是对于球形模型如何做到这一点?是否与SRID有关。

from django.contrib.gis.geos import LineString
from django.contrib.gis.geos import GEOSGeometry

directions = maps_client.directions(source, destination)
overview_polyline = decode_polyline(directions[0]['overview_polyline'])

linestring_obj = LineString(overview_polyline)

# FOR 2-D projection
bounding_box = linestring_obj.buffer(width=100)

# For spherical model
# ???

最佳答案

为了使以米为单位的地理距离有意义,您始终必须经过投影坐标系,因此我建议您将数据转换为投影坐标系,创建缓冲区并将其投影回来。例如:

# Specify the original srid of your data
orig_srid = 4326

# Create the linestring with the correct srid
linestring_obj = LineString(overview_polyline, srid=orig_srid)

# Transform (project) the linestring into a projected coorinate system
linestring_obj.transform(3857)

# Compute bbox in in that system
bounding_box = linestring_obj.buffer(width=100)

# Transform bounding box into the original coorinate system of your data
bounding_box.transform(orig_srid)

关于python - 计算包含地理坐标的线串的边界框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27901923/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com