计算包含地理坐标的字符串的边界框

2024-04-25 10:23:10 发布

您现在位置:Python中文网/ 问答频道 /正文

我从googlemapsdirectionsapi计算了linestring。 我把线串转换成GeoGeometry对象。我需要另一个区域,覆盖距离linestring对象“d”的所有点。 距离以m,km为单位。 GEOS API提供geosometry.buffer(width,quadsegs=8)这样做在二维投影中效果很好。在

但对于球形模型,该怎么做呢?是否与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
# ???

Tags: 对象djangofromimport距离bufferoverviewcontrib
1条回答
网友
1楼 · 发布于 2024-04-25 10:23:10

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

# 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)

相关问题 更多 >

    热门问题