def downloadImage(lattitude, longitude, heading, pitch, outputfile, api_key='AIzaSyBZnvqy9HEpG-LAQwm_AxDOegMciI9jgP4'): url = 'http://maps.googleapis.com/maps/api/streetview?size=800x800&location=' + str( lattitude) + ',' + str(longitude) + '&fov=120&heading=' + str( heading) + '&pitch=' + str(pitch) + '&sensor=false' url = utils.createSecureURL(url) response = requests.get(utils.createSecureURL(url)) localfile = open(str(outputfile), 'w') localfile.write(response.content) localfile.close()
def process_values(city): basePath = '/Users/pranavramkrishnan/Desktop/Research/maps/static/data/' + str( city) + '/' greenery = json.load(open(basePath + 'green/greenery2.geojson', 'r')) csv = open(basePath + 'green/locations.csv', 'a+') radii = [] count = 0 misses = [(42.3923164451, -71.1461732451), (42.3541092657, -71.1024612476), (42.3714731065, -71.1132207351), (42.3997190373, -71.1304608654), (42.3816325179, -71.1207984099), (42.388917823, -71.1183665027), (42.388852855, -71.125067115), (42.3830568375, -71.1349497196), (42.3687665577, -71.1169101016), (42.3652459742, -71.0923812041), (42.362539202, -71.0937018092), (42.3742730326, -71.1363473293), (42.3701696631, -71.1133346053), (42.377515, -71.131606), (42.3985686, -71.1362478)] while (count < len(misses)): #point = greenery['features'][count] lat = misses[count][0] lng = misses[count][1] url = 'https://maps.googleapis.com/maps/api/geocode/xml?latlng=' url += str(lat) url += ',' url += str(lng) url += '&sensor=false' secureURL = utils.createSecureURL(url) response = requests.get(secureURL) parse = et.XML(response.content) if parse.find('status').text == 'OK': address = parse.find('result').find('formatted_address').text address_components = parse.find('result').findall( 'address_component') short_street = '' long_street = '' for addr in address_components: if addr.find('type') != None and addr.find( 'type').text == 'route': short_street = addr.find('short_name').text long_street = addr.find('long_name').text print short_street, long_street address = address.encode('utf8') csv.write( str(lat) + ';' + str(lng) + ';' + str(long_street) + ';' + str(address) + '\n') print secureURL print "done with ......" + str(count) + ' out of ' + str( len(greenery['features'])) count += 1 time.sleep(0.5)
def makeDistanceMatrixRequest(coords, ids, mode, city): #convert coords to string coordString = '' for crd in coords: crdString = str(crd[0]) + ',' + str(crd[1]) coordString += crdString + '|' coordString = coordString[:-1] url = 'http://maps.googleapis.com/maps/api/distancematrix/xml?origins=' + coordString + '&destinations=' + coordString + '&mode=' + str( mode) + '&sensor=false' url2 = utils.createSecureURL(url) print url2 #xml = requests.get(url2) response = urllib2.urlopen(url2) xml = response.read() parseDistanceMatrix(xml, ids, mode, city)
def directionsService(origin, dest, mode, city): departure_time= str(int(time.mktime(time.gmtime()))) url = 'http://maps.googleapis.com/maps/api/directions/xml?origin='+str(origin[0])+','+ str(origin[1])+'&destination='+str(dest[0])+','+ str(dest[1])+'&mode='+str(mode)+'&sensor=false' url2 = utils.createSecureURL(url) print url2 xml = requests.get(url2) #print xml.status_code #print xml.content parse = et.XML(xml.content) if (parse.find('status').text == 'OK'): steps = parse.find('route').find('leg').findall('step') final_segments = [] path = [] generation = 0 for step in steps: point_str = step.find('polyline').find('points').text points = decode(point_str) segments = pointsToSegments(points) instr = step.find('html_instructions').text instr = instr.split() containsName = ' '.join(instr[2:]) name = between('<b>', '</b>',containsName) for segment in segments: [start_lat, start_lng] = segment[0] [end_lat, end_lng] = segment[1] #if isPathSegmentUnique(start_lat, start_lng, end_lat, end_lng, name): final_segments.append([start_lat, start_lng, end_lat, end_lng, name, generation]) generation+=1 path_str = parse.find('route').find('overview_polyline').find('points').text path = decode(path_str) return [final_segments, path] else: #savePathDict() print "RequestError: " + parse.find('status').text if parse.find('status').text =='ZERO_RESULTS': return [0,0] return [None, None]
def geocode_segments(): intersections = open( '/Users/pranavramkrishnan/Desktop/Research/maps/static/data/Brooklyn/intersections.txt', 'r').readlines() segmentpoints = open( '/Users/pranavramkrishnan/Desktop/Research/maps/static/data/Brooklyn/segment_points.txt', 'a+') segments = open( '/Users/pranavramkrishnan/Desktop/Research/maps/static/data/Brooklyn/segments.txt', 'a+') errors = open( '/Users/pranavramkrishnan/Desktop/Research/maps/static/data/Brooklyn/segment-errors.txt', 'a+') count = 3594 while (count < len(intersections)): intersection = intersections[count] url = 'https://maps.googleapis.com/maps/api/geocode/xml?address=' [street1, street2] = intersection.split('and') url += str(''.join(street1.split())) url += 'and' url += str(''.join(street2[:len(street2) - 1].split())) url += '+Brooklyn,+NY&sensor=false' #'&key=AIzaSyBZnvqy9HEpG-LAQwm_AxDOegMciI9jgP4' secureURL = utils.createSecureURL(url) #print secureURL xml = requests.get(url) [lat, lng] = getLatLng(xml.content) if lat != None and lng != None: print lat, lng print "done with " + str(count) + " out of " + str( len(intersections)) segmentpoints.write(str(lat) + ',' + str(lng) + '\n') segments.write(intersection[:len(intersection) - 1] + ',' + str(lat) + ',' + str(lng) + '\n') else: errors.write(intersection) count += 1 time.sleep(0.7)
def getImages(point, bearing, api_key='AIzaSyBZnvqy9HEpG-LAQwm_AxDOegMciI9jgP4'): query_url = 'http://maps.googleapis.com/maps/api/streetview?' latitude = point[0] longitude = point[1] location = str(latitude) + ' ' + str(longitude) #print(location) headings = [(bearing + 90 + 10) % 360, (bearing - 90 - 10) % 360] orientation = ['left', 'right'] values = [] for i in range(len(headings)): current_heading = headings[i] current_pitch = 0 url2 = 'http://maps.googleapis.com/maps/api/streetview?size=50x50&location=' + str( latitude) + ',' + str(longitude) + '&fov=110&heading=' + str( current_heading) + '&pitch=' + str( current_pitch) + '&sensor=false' secureURL = utils.createSecureURL(url2) #print ("heading = "+ str(current_heading)+ " pitch = "+ str(current_pitch)) #print "URL = " + str(url2) response = requests.get(secureURL) #parse = et.XML(response.content) #print str(parse) [greenVal, [R, G, B]] = processImage(response.content) values.append([greenVal, [R, G, B]]) # localfile = open('images/cambridge/'+str(name)+'_'+str(orientation[i]) + '_'+str(lattitude)+'_'+str(longitude)+ '_'+ '.jpeg', 'w') # localfile.write(response.content) # localfile.close() #outputFile.write(str(lattitude) + ',' + str(longitude) + ',' + str(values) + '\n') print secureURL return values
def directionsService(origin, dest, mode): departure_time = str(int(time.mktime(time.gmtime()))) #url = 'http://maps.googleapis.com/maps/api/directions/xml?origin='+str(origin[0])+','+ str(origin[1])+'&destination='+str(dest[0])+','+ str(dest[1])+'&mode='+str(mode)+'&departure_time=' + str(departure_time) + '&sensor=false' url = 'http://maps.googleapis.com/maps/api/directions/xml?origin=' + str( origin[0]) + ',' + str(origin[1]) + '&destination=' + str( dest[0]) + ',' + str( dest[1]) + '&mode=' + str(mode) + '&sensor=false' url2 = utils.createSecureURL(url) print url2 xml = requests.get(url2) parse = et.XML(xml.content) if (parse.find('status').text == 'OK'): duration = float( parse.find('route').find('leg').find('duration').find( 'value').text) distance = float( parse.find('route').find('leg').find('distance').find( 'value').text) return [duration, distance] else: return [None, None]