예제 #1
0
def getRoute(orig_coord = (-73.990602, 40.731779), dest_coord =  (-73.976709, 40.751687)):

    global googleApiKey

    st_code = 0

    sys.stdout.flush()

    while st_code is not 200:
        #Returns the list of routes Distance in metres and duration in sec (driving?!)
        gd = GoogleDirections(googleApiKey)
        try:
            res = gd.query(str((orig_coord[1], orig_coord[0])), str((dest_coord[1], dest_coord[0])))
        except TypeError:
            return None
        st_code = res.result['Status']['code']

    sys.stdout.flush()
    routes = res.result['Directions']["Routes"][0]['Steps']

    df = pd.DataFrame(routes, columns=['Distance', 'Duration', 'Point', 'polylineIndex'])

    df['Distance'] = df['Distance'].apply(lambda x: x['meters'])
    df['Duration'] = df['Duration'].apply(lambda x: x['seconds'])
    df['Point'] = df['Point'].apply(lambda x: x['coordinates'][:2])

    return df
예제 #2
0
def get_directions(self, source, destination):
    steps = []
    res = False
    #    try:
    gd = GoogleDirections("ABQIAAAAUbF6J26EmcC_0QgBXb9xvhRoz3DfI4MsQy-vo3oSCnT9jW1JqxQfs5OWnaBY9or_pyEGfvnnRcWEhA")
    res = gd.query(source, destination)
    #    except:
    #        raise osv.except_osv('Warning!','Please install Google direction package from http://pypi.python.org/pypi/google.directions/0.3 ')
    if res:
        if res.status != 200:
            print "Address not found. Status was: %d" % res.status
            return
        if "Directions" in res.result:
            endPoint = res.result["Directions"]["Routes"][0]["End"]["coordinates"]
            result = res.result["Directions"]["Routes"][0]["Steps"]
            for i in result:
                steps.append(i["Point"]["coordinates"])
            steps.append(endPoint)
            return steps
    def getDirections( self, startPoint, endPoint ):

        startX = startPoint.x
        startY = startPoint.y
        endX   = endPoint.x
        endY   = endPoint.y
         
        gd = GoogleDirections('AIzaSyCUyKgIqRsJcdjrmOHDKJSBgyaBwDvfkbw')
        response = gd.query( "{1},{0}".format(startX,startY), "{1},{0}".format(endX,endY) )

        status = response.status

        if status == 620:
            raise Exception('status 604: Google thinks you\'re geocoding too fast')
        elif status != 200:
            raise Exception( "received status {status}; unable to geocode from:{sY},{sX} to:{eY},{eX}".format(status=status,
                sY=startY,sX=startX,
                eY=endY,eX=endX) 
            )

        return response.result
    def getDirections(self, startPoint, endPoint):

        startX = startPoint.x
        startY = startPoint.y
        endX = endPoint.x
        endY = endPoint.y

        gd = GoogleDirections('AIzaSyCUyKgIqRsJcdjrmOHDKJSBgyaBwDvfkbw')
        response = gd.query("{1},{0}".format(startX, startY),
                            "{1},{0}".format(endX, endY))

        status = response.status

        if status == 620:
            raise Exception(
                'status 604: Google thinks you\'re geocoding too fast')
        elif status != 200:
            raise Exception(
                "received status {status}; unable to geocode from:{sY},{sX} to:{eY},{eX}"
                .format(status=status, sY=startY, sX=startX, eY=endY, eX=endX))

        return response.result
예제 #5
0
def get_directions(self, source, destination):
    steps = []
    res = False
    #    try:
    gd = GoogleDirections(
        'ABQIAAAAUbF6J26EmcC_0QgBXb9xvhRoz3DfI4MsQy-vo3oSCnT9jW1JqxQfs5OWnaBY9or_pyEGfvnnRcWEhA'
    )
    res = gd.query(source, destination)
    #    except:
    #        raise osv.except_osv('Warning!','Please install Google direction package from http://pypi.python.org/pypi/google.directions/0.3 ')
    if res:
        if res.status != 200:
            print "Address not found. Status was: %d" % res.status
            return
        if 'Directions' in res.result:
            endPoint = res.result['Directions']['Routes'][0]['End'][
                'coordinates']
            result = res.result['Directions']['Routes'][0]['Steps']
            for i in result:
                steps.append(i['Point']['coordinates'])
            steps.append(endPoint)
            return steps
from google.directions import GoogleDirections
import pandas as pd
from pandas import DataFrame

gd = GoogleDirections('AIzaSyBGrDxPZz6WuOkZXgJSATpvAkjHhhwd_UU')

Villes = ['caen', 'paris', 'marseille', 'lyon', 'lille']


Dist = pd.DataFrame([[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0],[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]] ,
index = Villes,
columns = Villes)


for ville1 in Villes:
    for ville2 in Villes:
        if ville1 != ville2:
            res = gd.query(ville1,ville2)
            Dist.at[ville1, ville2] = res.distance
        else:
            Dist.at[ville1, ville2] = 0

print Dist



예제 #7
0
# -*- coding: utf-8 -*-
"""
Created on Tue Oct 28 08:42:29 2014

@author: christian
"""

import numpy as np

villes = ['caen', 'paris', 'marseille', 'lyon', 'lille']

Matrix = [[]]

from google.directions import GoogleDirections
gd = GoogleDirections('AIzaSyD8De9F85qtHsOl9vP27KHWbmZnnMW6CJ4')
res = gd.query('berlin', 'paris')

i = 0

for ville1 in villes:
    for ville2 in villes:
        Matrix.append([])
        if ville1 != ville2:
            res = gd.query(ville1, ville2)
            Matrix[i].append(res.distance)
            print "Distance ", ville1, ville2, "= ", res.distance
    i += 1

print Matrix
예제 #8
0
파일: villes.py 프로젝트: jludac/MS-BGD
"""
Created on Tue Oct 28 08:42:29 2014

@author: christian
"""

import numpy as np


villes = ["caen", "paris", "marseille", "lyon", "lille"]

Matrix = [[]]

from google.directions import GoogleDirections

gd = GoogleDirections("AIzaSyD8De9F85qtHsOl9vP27KHWbmZnnMW6CJ4")
res = gd.query("berlin", "paris")

i = 0

for ville1 in villes:
    for ville2 in villes:
        Matrix.append([])
        if ville1 != ville2:
            res = gd.query(ville1, ville2)
            Matrix[i].append(res.distance)
            print "Distance ", ville1, ville2, "= ", res.distance
    i += 1

print Matrix
예제 #9
0
"""Using the Google directions API"""
# -*- coding: iso-8859-15 -*-
from google.directions import GoogleDirections
gd = GoogleDirections('AIzaSyC7d9cBib4H734ta4lHc0JEQ7LMIdm3njQ')
villes = ['Caen', 'Paris', 'Marseille', 'Lyon', 'Lille']
for v1 in villes:
    for v2 in villes:
        if v2 not in [v1]:
    		res = gd.query(v1, v2)
    		print v1+' to '+v2 + '=' +str(res.distance)
예제 #10
0
from google.directions import GoogleDirections
import pandas as pd
from pandas import DataFrame

gd = GoogleDirections('AIzaSyBGrDxPZz6WuOkZXgJSATpvAkjHhhwd_UU')

Villes = ['caen', 'paris', 'marseille', 'lyon', 'lille']

Dist = pd.DataFrame([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0],
                     [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]],
                    index=Villes,
                    columns=Villes)

for ville1 in Villes:
    for ville2 in Villes:
        if ville1 != ville2:
            res = gd.query(ville1, ville2)
            Dist.at[ville1, ville2] = res.distance
        else:
            Dist.at[ville1, ville2] = 0

print Dist
예제 #11
0
"""Using the Google directions API"""
# -*- coding: iso-8859-15 -*-
from google.directions import GoogleDirections
gd = GoogleDirections('AIzaSyC7d9cBib4H734ta4lHc0JEQ7LMIdm3njQ')
villes = ['Caen', 'Paris', 'Marseille', 'Lyon', 'Lille']
for v1 in villes:
    for v2 in villes:
        if v2 not in [v1]:
            res = gd.query(v1, v2)
            print v1 + ' to ' + v2 + '=' + str(res.distance)

# res.distance

#[x for x in my_list if not x.startswith('#')]
#[for a in villes if not a in ['Paris']: print a]

# for a in villes:
#     if a not in ['paris']:
#     	print a