1

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

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

1 回答 1

1

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

# 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)
于 2015-02-02T11:51:19.967 回答