Beispiel #1
0
def get_mid_point():
    sp = shortest_path.ShortestPath(STATION_FILE,
                                    LINE_FILE,
                                    JOIN_FILE)
    point1 = geocoding.request('中野島駅')
    point2 = geocoding.request('武蔵小山駅')
    point3 = geocoding.request('鴨宮駅')
    middle_cord = get_middle_point([point1.data[0]['geometry']['location'], point2.data[0]['geometry']['location'], point3.data[0]['geometry']['location']])
    stations = placesearch.get_nearest_station(middle_cord, key='XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
    shortest_path_index = get_shortest_path_index(sp, stations, point1, point2, point3)
    print stations.data[shortest_path_index]['name']
Beispiel #2
0
def get_middle_point(coordinates):
    x = 0
    y = 0
    z = 0
    for point in coordinates:
        x = x + cos(point["lat"] * pi / 180) * cos(point["lng"] * pi / 180)
        y = y + cos(point["lat"] * pi / 180) * sin(point["lng"] * pi / 180)
        z = z + sin(point["lat"] * pi / 180)
    x = x / len(coordinates)
    y = y / len(coordinates)
    z = z / len(coordinates)
    return {"lng": atan2(y, x) * 180 / pi, "lat": atan2(z, sqrt(x * x + y * y)) * 180 / pi}


point1 = geocoding.request("Tokyo")
point2 = geocoding.request("Osaka")
point3 = geocoding.request("Nagoya")
middle_cord = get_middle_point(
    [
        point1.data[0]["geometry"]["location"],
        point2.data[0]["geometry"]["location"],
        point3.data[0]["geometry"]["location"],
    ]
)
middle_point = geocoding.request(str(middle_cord["lat"]) + "," + str(middle_cord["lng"]))

results = directions.request(
    origin="Tokyo",
    destination=str(middle_point.data[0]["geometry"]["location"]["lat"])
    + ","
Beispiel #3
0
#coding: UTF-8
#Geographic midpoint
#http://www.geomidpoint.com/meet/
#http://www.geomidpoint.com/calculation.html
from math import (pi, sin, cos, atan2, sqrt)
from get_mid_point import (pygmapslib, directions, geocoding, placesearch)

def get_middle_point(coordinates):
    x = 0
    y = 0
    z = 0
    for point in coordinates:
        x = x + cos(point['lat'] * pi / 180) * cos(point['lng'] * pi /180)
        y = y + cos(point['lat'] * pi / 180) * sin(point['lng'] * pi /180)
        z = z + sin(point['lat'] * pi / 180)
    x = x / len(coordinates)
    y = y / len(coordinates)
    z = z / len(coordinates)
    return {'lng' : atan2(y,x) * 180 / pi, 'lat' : atan2(z, sqrt(x*x + y*y)) * 180 /pi}

point1 = geocoding.request('Tokyo station')
point2 = geocoding.request('Ikebukuro station')
point3 = geocoding.request('Shibuya station')
middle_cord = get_middle_point([point1.data[0]['geometry']['location'], point2.data[0]['geometry']['location'], point3.data[0]['geometry']['location']])
stations = placesearch.get_nearest_station(middle_cord, key='XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')

print stations