繁体   English   中英

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

[英]Calculate bounding box for linestring containing geographic coordinates

我根据Google Maps Directions api计算了线串。 我将线串转换为GEOSGeometry对象。 我需要另一个区域,该区域覆盖距线串对象“ d”的所有点。 距离以米,公里为单位。 GEOS API提供了GEOSGeometry.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
# ???

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM