[英]Calculate bounding box for linestring containing geographic coordinates
I calculated linestring from google maps directions api. 我根据Google Maps Directions api计算了线串。 I converted the linestring to GEOSGeometry object.
我将线串转换为GEOSGeometry对象。 I need to another region which covers all the points at a distance of 'd' from the linestring object.
我需要另一个区域,该区域覆盖距线串对象“ d”的所有点。 The distance is in m, km.
距离以米,公里为单位。 GEOS API provides GEOSGeometry.buffer(width, quadsegs=8) to do so which works well in 2-D projection.
GEOS API提供了GEOSGeometry.buffer(width,quadsegs = 8)来实现,这在二维投影中效果很好。
But how to do so for spherical model ? 但是对于球形模型该怎么做呢? Is it related to SRID.
它与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
# ???
For geographical distance in meters to make sense, you will always have to go through a projected coordinate system, so I would suggest that you transform your data to a projected coordinate system, create the buffer and project it back. 为了使以米为单位的地理距离有意义,您将始终必须经过投影坐标系,因此我建议您将数据转换为投影坐标系,创建缓冲区并将其投影回去。 For instance:
例如:
# 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.