-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
61 lines (47 loc) · 1.77 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import requests
from pyproj import Proj, transform
from xml.dom import minidom
from geopy import distance
from shapely.wkt import loads
def transform_back(x,y):
outProj = Proj('epsg:3857')
inProj = Proj('epsg:4326')
x,y = transform(inProj,outProj,x,y)
return x,y
def transform_projection(x,y):
inProj = Proj('epsg:3857')
outProj = Proj('epsg:4326')
x,y = transform(inProj,outProj,x,y)
return x,y
def coorOrganizer__(input=str):
# Coordinates in [1.2, 5.7, 6.8, 9.1] style is converted to LineString(1.2 5.7, 6.8 9.1) style by this function.
coorPair = [input[i:i + 2] for i in range(0, len(input), 2)]
usefulPoly = []
for i in coorPair:
usefulPoly.append(" ".join(map(str, i)))
wkt = 'LineString(%s)' % (','.join(usefulPoly))
return wkt
def wktMaker__(response=str):
responseData = minidom.parseString(response)
coors = responseData.getElementsByTagName('coordinates')[0].firstChild.nodeValue.strip()
commaCoors = coors.replace('\n', ',')
usefulCoorList = []
for i in commaCoors.split(','):
usefulCoorList.append(float(i))
return coorOrganizer__(usefulCoorList)
x1 = 7952815.486011353
y1 = 6654045.979371076
x2 = 7951729.234373041
y2 = 6650724.0702911215
x1,y1 = transform_projection(x1,y1)
x2,y2 = transform_projection(x2,y2)
yourNavigationBaseURL__ = 'http://www.yournavigation.org/api/dev/route.php?flat=%s&distance=gc&flon=%s&tlat=%s&tlon=%s&v=motorcar&fast=0&layer=mapnik&instructions=0'
url = yourNavigationBaseURL__ % (x1,y1,x2,y2)
r = requests.get(url)
wkt = wktMaker__(r.text)
# distance.VincentyDistance.ELLIPSOID = 'WGS-84'
# d = distance.distance
# line = loads(wkt)
# # convert the coordinates to xy array elements, compute the distance
# # dist = d(line.xy[0], line.xy[1])
print (r.text)