我正在做一个django项目,用户以字符串的形式输入他们的开始和结束位置。你知道吗
我的应用程序必须连接到googledirectionserviceapi,获取字符串并将其转换为coords。然后从坐标创建一条多段线,并添加1公里的缓冲区。将作为多边形保存在postgis数据库中。你知道吗
from django.db import models
from django.contrib.gis.db import models
from django.forms import ModelForm
from django_google_maps import fields as map_fields
import shapely.geometry
import googlemaps
from googlemaps import Client
# Create your models here.
class Route(models.Model):
startPoint_address = PointField()
startPoint_geolocation = Pointfield()
endPoint_address = PointField()
endPoint_geolocation = Pointfield()
# endPoint = models.PointField()
# deviationDistance = models.IntegerField(default=20)
# routeName = models.CharField(max_length=50)
# https://github.com/geodav-tech/decode-google-maps-polyline
def decode_polyline(polyline_str):
'''Pass a Google Maps encoded polyline string; returns list of
lat/lon pairs'''
index, lat, lng = 0, 0, 0
coordinates = []
changes = {'latitude': 0, 'longitude': 0}
# Coordinates have variable length when encoded, so just keep
# track of whether we've hit the end of the string. In each
# while loop iteration, a single coordinate is decoded.
while index < len(polyline_str):
# Gather lat/lon changes, store them in a dictionary to apply them later
for unit in ['latitude', 'longitude']:
shift, result = 0, 0
while True:
byte = ord(polyline_str[index]) - 63
index+=1
result |= (byte & 0x1f) << shift
shift += 5
if not byte >= 0x20:
break
if (result & 1):
changes[unit] = ~(result >> 1)
else:
changes[unit] = (result >> 1)
lat += changes['latitude']
lng += changes['longitude']
coordinates.append((lat / 100000.0, lng / 100000.0))
return coordinates
gmaps = googlemaps.Client(key='AIzaSyCetShZ10WQVBVPaIu9pdPEktRVQq78TF4')
google_directions = gmaps.directions("Stellenbosch", "Cape Town")
encoded_polyline = google_directions[0]['overview_polyline']['points']
decoded_polyline = decode_polyline(encoded_polyline)
shapely_line = shapely.geometry.LineString(decoded_polyline)
buffered_line = shapely_line.buffer(0.00001)
当前错误: 断言失败:(0),函数查询,文件抽象树.cpp,第287行。 中止陷阱:6
如有任何可能,我们将不胜感激。你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐