2015-01-12 53 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)