2015-01-12 54 views
1

我从谷歌地图方向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 
# ??? 

回答

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)