Ошибка подтверждения на извлечении полилинии и буфера карт Google. - PullRequest
0 голосов
/ 28 мая 2018

Я работаю над проектом django, где пользователь вводит свое начальное и конечное местоположение в виде строки.

Мое приложение должно подключиться к API службы направления Google, взять строку и преобразовать ее в координаты.Затем из координат создайте ломаную линию и добавьте 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), запрос функции, файл AbstractSTRtree.cpp, строка 287. Прерывание прерывания: 6

Любая возможная помощь будет принята с благодарностью.

...