def downloadSurroundingStreetView(point, directory, picNum, ptrNum, intersectionPointInfo): """ Call Google street view image api to get the four surrounding images at the given point. :param point: (float, float) longitude and latitude :param directory: the directory for saving the images """ result = [] for heading in CONFIG["gmap"]["headings"]: filename = "%s/%010d_%s_%s_%s.jpg" % (directory, picNum, str( point[1]), str(point[0]), heading[0]) paramDict = GoogleStreetView.makeParameterDict(point[1], point[0], heading[1]) metadata = GoogleStreetView.getMetadata(paramDict) result.append([ picNum, ptrNum, str(point[1]) + "," + str(point[0]), heading[0], metadata["date"], filename.split("/")[-1], ",".join(intersectionPointInfo[(point[0], point[1])]) ]) param = GoogleStreetView.makeParameter(point[1], point[0], heading[1]) GoogleStreetView.downloadStreetView(param, filename) picNum += 1 return result
def isValidPoint(point): """ Call Google Street Image View metadata API to check the existance of the street view image for the given point. :return: """ headings = CONFIG["gmap"]["headings"] params = GoogleStreetView.makeParameterDict(point[1], point[0], headings[0][1]) return GoogleStreetView.isValidPoint(params)
def findValidIntersections(intersections): Logger.printAndWrite("Checking valid intersections") start = 260000 delta = 10000 msg = "Starting record = %d" % start Logger.printAndWrite(msg) headingZero = CONFIG["gmap"]["headings"][0] validIntersections = {} i = 0 for point in intersections.keys()[start:start + delta]: param = GoogleStreetView.makeParameterDict(point[1], point[0], headingZero) if GoogleStreetView.isValidPoint(param): validIntersections[point] = intersections[point] i += 1 if i % 10 == 0: sys.stdout.write("\r%d" % i) return validIntersections
def getSurroundingStreetViewLinks(point, picNum, ptrNum, intersectionPointInfo): """ Call Google street view image api to get the links for the four surrounding images at the given point. :param point: (float, float) longitude and latitude :param directory: the directory for saving the images """ result = [] for heading in CONFIG["gmap"]["headings"]: try: filename = "%010d_%s_%s_%s.jpg" % (picNum, str(point[1]), str(point[0]), heading[0]) paramDict = GoogleStreetView.makeParameterDict(point[1], point[0], heading[1]) metadata = GoogleStreetView.getMetadata(paramDict) param = GoogleStreetView.makeParameter(point[1], point[0], heading[1]) imageLink = GoogleStreetView.getStreetViewLink(param) if "date" in metadata: date = metadata["date"] else: date = "Unknown" print filename + " has now date" result.append([ picNum, ptrNum, str(point[1]) + "," + str(point[0]), heading[0], date, filename, ",".join(intersectionPointInfo[(point[0], point[1])]), imageLink ]) picNum += 1 except: print metadata break return result
def getPointInfoToFile(points, filename): lines = [] lineFormat = "%s==Actual Location:%s,%s|date:%s" counter = {} counter["no date"] = 0 headingsZero = CONFIG["gmap"]["headings"][0] prog = 0 for point in points: lngLat = [float(p) for p in point.split(",")] param = GoogleStreetView.makeParameterDict(lngLat[1], lngLat[0], headingsZero) info = GoogleStreetView.getMetadata(param) if info["status"] == GoogleStreetView.OK: if 'date' in info: data = lineFormat % (point, info['location']['lng'], info['location']['lat'], info['date']) else: counter['no date'] += 1 data = lineFormat % (point, info['location']['lng'], info['location']['lat'], "0000-00") lines.append(data) else: print "Point err:", point prog += 1 if prog % 10 == 0: sys.stdout.write("\r%d" % prog) print "\nnumber of points that have no date: %d" % counter['no date'] lines = "\n".join(lines) lines += "\n" output = open(filename, 'a') output.writelines(lines) output.close()