def plotErrMap(trips, title, outputFile): SMALL_ERR_COLOR = "#0000FF" # blue MED_ERR_COLOR = "#00FF00" # green LARGE_ERR_COLOR = "#FF0000" # red # set the center of this map center = trips[0][2] mymap = pygmaps.maps(center[1], center[0], 10) # Add every points in framePoint to this map. for dist, errDist, point in trips: if errDist < dist * 0.1: color = SMALL_ERR_COLOR elif errDist < dist * 0.5: color = MED_ERR_COLOR else: color = LARGE_ERR_COLOR mymap.addpoint(point[1], point[0], color) # Create this map. mapFilename = outputFile mymap.draw('./' + mapFilename) # Create the local link to this map file. url = "file://" + os.getcwd() + "/" + mapFilename # Open this map on a browser webbrowser.open_new(url)
def show_map(location): ''' show_map(dict) -> str (HTML with map) Use pygmaps (as a class modified in this project) to draw map and overlay icon on location (latitude, longitude) and a circle with the accuracy Overlay the weather stations near location Generates an HTML file that is returned ''' zoom = 15 mymap = pygmaps.maps(float(location['latitude']),float(location['longitude']),zoom) mymap.addpoint(float(location['latitude']),float(location['longitude']),'house') mymap.addcircle(float(location['latitude']),float(location['longitude']),float(location['accuracy']),"#0000FF") # add nearest weather stations stations = find_weather_stations_near(location) for number in range(len(stations)): station = stations[number] if station: mymap.addpoint(float(station['latitude']), float(station['longitude']), 'station') else: print "[show_map] No weather station to display" mymap.draw('./templates/mymap.html') f = open('./templates/mymap.html','r') fmap = Markup(f.read()) return fmap
def display(): mymap = pygmaps.maps(40.437822, -79.933101, 15) #mymap.setgrids(37.42, 37.43, 0.001, -122.15, -122.14, 0.001) #mymap.addradpoint(37.429, -122.145, 95, "#FF0000") stations = [(40.444632, -79.942993), (40.443897, -79.938852), (40.437822, -79.933101), (40.438051, -79.927844), (40.438051, -79.919368), (40.438002, -79.913145)] stationCnt = len(stations) mymap.addpath(stations, "#00FF00") url = '/Volumes/HDD/Dropbox/CMU_course/18842_distributed_systems/Bus_Tracker/host/mymap.html' for i in range(stationCnt): mymap.addpoint(stations[i][0], stations[i][1], "#0000FF") pathes = [(40.444632, -79.942993), (40.444322, -79.941147), (40.443897, -79.938852), (40.442673, -79.937649), (40.440566, -79.935696), (40.437822, -79.933101), (40.437822, -79.930675), (40.438051, -79.927844), (40.438051, -79.919368), (40.438132, -79.916084), (40.438002, -79.913145)] for i in range(len(pathes)): if i > 0: mymap.delpoint() mymap.addpoint(pathes[i][0], pathes[i][1], "#FF0000") mymap.draw('./mymap.html') browser = webbrowser.get("safari") browser.open(url) time.sleep(2)
def locate(self, target): self.target = target self.rawdata = pygeoip.GeoIP('GeoLiteCity.dat') try: self.data = self.rawdata.record_by_addr(self.target) except: self.data = self.rawdata.record_by_name(self.target) self.country = self.data['country_name'] self.longi = self.data['longitude'] self.lat = self.data['latitude'] self.mymap = pygmaps.maps(self.lat, self.longi, 12) self.mymap.addpoint(self.lat, self.longi, "Target is near this area") self.mymap.draw('./target_location.html') print yellow("[!] Target: ") + red(str(self.target)) print yellow("[x] Target's country: ") + red(str(self.country)) print yellow("[x] Longitude: ") + red(str(self.longi)) print yellow("[x] Latitude: ") + red(str(self.lat)) print yellow('[x] Map of the location >') + red( '"target_location.html"') while True: self.o_map = raw_input( "Try to open target_location.html map in browser(y/ n):\n>" ).lower() if self.o_map.startswith('y'): try: self.new = 2 webbrowser.open("target_location.html", new=self.new) break except: print '[!]Could not open map in web browser. Open "geo_trace.html" -file manually' break elif self.o_map.startswith('n'): break
def draw_trips(directory, outputpath, number): filelist = traverseFolder(directory, '.mat', number) print(filelist) make_sure_path_exists(outputpath) color_list = [ 'Deep pink', 'Alizarin crimson', 'Amber', 'Amethyst', 'Android Green', 'Azure', 'Aqua', 'Magenta' ] color_dictionary = { 'Aqua': "#00ffff", 'Alizarin crimson': "#e32636", 'Amber': "#ffbf00", 'Amethyst': "#9966cc", 'Android Green': "#a4c639", 'Azure': "#007fff", 'Deep pink': "#ff1493", 'Magenta': "#f00ff" } start_color = "#0000FF" end_color = "#FF0000" index = 0 Trip_list = [] for file in filelist: Trip_data = load_mat_file(file) # load origin .mat data point_list = extract_points_location(Trip_data) trip = Trip() trip.name = file trip.start_point = point_list[0] trip.end_point = point_list[-1] trip.Trip_index = index trip.path_list = [] trip.path_color = color_list[index] for i in point_list: trip.path_list.append(tuple([i.latitude, i.longitude])) # draw start point, end point, route_path mymap = pygmaps.maps(trip.start_point.latitude, trip.start_point.longitude, 12) # start a map mymap.addpoint(trip.start_point.latitude, trip.start_point.longitude, start_color) mymap.addpoint(trip.end_point.latitude, trip.end_point.longitude, end_color) mymap.addpath(trip.path_list, color_dictionary[trip.path_color]) index = index + 1 map_path = outputpath + file.split( "/" )[-1][:-4] + '.map.draw.html' # delete the '.mat' and add '.map.draw.html' mymap.draw(map_path) url = map_path webbrowser.open_new_tab(url) Trip_list.append(trip)
def make_route_HTML(input_file_name, output_file_name="", input_path="./GPS_route_log", output_path="./htmls", data_separator=",", open_at_finish=False): track_file = open(input_path + "/" + input_file_name, 'r') GPS_data = [] for line in track_file: data = (line.split("\n")[0]).split(data_separator) GPS_data.append((float(data[0]), float(data[1]))) start = [(GPS_data[0])[0], (GPS_data[0])[1]] stop = [(GPS_data[len(GPS_data)-1])[0], (GPS_data[len(GPS_data)-1])[1]] mymap = pygmaps.maps(start[0], start[1], 16) mymap.addpoint(start[0], start[1]) #, "#0000FF") mymap.addpoint(stop[0], stop[1], "#FFFFFF") #, "#0000FF") mymap.addpath(GPS_data,"#0000FF") if output_file_name == "": output_file_name = input_file_name + ".html" if (not (os.path.isdir(output_path))): os.system('mkdir ' + output_path) mymap.draw(output_path + "/" + output_file_name) if open_at_finish: webbrowser.open(output_path + "/" + output_file_name,2)
def createDeliveryMap(orders, outputfile): zoomlevel = 13 # bigger is closer #print "Creating overview map of " + str(len(orders)) + " deliveries" import pygmaps # Church of the Epiphany - 38.906814,-77.40729 # centered at rough central order 38.927115,-77.384287 mymap = pygmaps.maps(38.927115, -77.384287, zoomlevel) for o in orders: if (o.lat[:7] == 'Address'): print o.street + " is being ignored due to bad address" continue # The default pygmaps won't work with this. The following change will rectify. See http://stackoverflow.com/questions/19142375/how-to-add-a-title-to-each-point-mapped-on-google-maps-using-python-pygmaps #This is an issue with pygmaps.py program I downloaded. In the supplied package there is no option to add a 4th column (title). # #Now I modified pygmaps.py program like below: # #from # #def addpoint(self, lat, lng, color = '#FF0000'): # self.points.append((lat,lng,color[1:])) #to: # #def addpoint(self, lat, lng, color = '#FF0000', title = None): # self.points.append((lat,lng,color[1:],title)) # label = o.street + " - Order " + o.order + " - " + o.bags + " bags" mymap.addpoint(float(o.lat), float(o.lon), o.color, label) mymap.draw(outputfile)
def main(): args = parse_cmd_args() my_map = pygmaps.maps(0, 0, 2) colors = [ "#ff0000", "#00ff00", "#0000ff", "#ffff00", "#00ffff", "#ff00ff", "#000000", "#ffffff", "#770000", "#007700", "#000077", "#777700", "#007777", "#770077" ] # Iterate over all files provided over the command line and plot its IP # addresses on a map in different colours. for file_name in args.file: color = colors.pop(0) locations = map_location(load_addresses(file_name), args.geoip_file) for address in locations.keys(): latitude, longitude = locations[address] my_map.addpoint(latitude, longitude, color=color, title=file_name) # Write the resulting map to disk. output_file = tempfile.mktemp(prefix="map_", suffix=".html") my_map.draw(output_file) print >> sys.stderr, "[*] Wrote output to: %s" % output_file return 0
def plot_user_locations(uid, df_results, range_coordinates, zoom_map, alg): """ Plot locations using pympas packages """ mymap = pygmaps.maps(np.mean(range_coordinates[:2]), np.mean(range_coordinates[2:]), zoom_map) #mymap.setgrids(39.7627, 40.028974, 0.03, 116.182325,116.5787, 0.03) # color: e.g. red "#FF0000", Blue "#0000FF", Green "#00FF00" if (alg == 'freq') | (alg == 'both'): for location in df_results[['lat', 'lon', 'type', 'alg']].values: if (location[2] == 'single') and (location[3] == 'freq'): mymap.addpoint(location[0], location[1], "#00FF00") if (location[2] == 'community') and (location[3] == 'freq'): mymap.addpoint(location[0], location[1], "#FF0000") if (alg == 'cluster') | (alg == 'both'): for location in df_results[['lat', 'lon', 'type', 'alg']].values: if (location[2] == 'single') and (location[3] == 'cluster'): mymap.addpoint(location[0], location[1], "#00F00") if (location[2] == 'community') and (location[3] == 'cluster'): mymap.addpoint(location[0], location[1], "#0000FF") mymap.draw('./locationMap/infering home location_%s.html' % (str(uid) + '_' + alg)) return True
def map_individuals(self): import pygmaps from matplotlib import colors as matcol colormap = plt.cm.get_cmap() import random r = random.sample(range(len(set(self.labels))), len(set(self.labels))) rand = [] for i in range(len(self.labels)): rand.append(r[self.labels[i]]/float(self.clusters)) for color in set(self.colors): first = True num_paths = 0 for i in range(len(self.colors)): if self.colors[i] == color: num_paths += 1 start_lat = self.data[i]['trip_start_location'][1] start_lon = self.data[i]['trip_start_location'][0] end_lat = self.data[i]['trip_end_location'][1] end_lon = self.data[i]['trip_end_location'][0] if first: mymap = pygmaps.maps(start_lat, start_lon, 10) first = False path = [(start_lat, start_lon), (end_lat, end_lon)] mymap.addpath(path, matcol.rgb2hex(colormap(rand[i]))) if num_paths > 1: mymap.draw('./mycluster' + str(color) + '.html') else: mymap.draw('./onemycluster' + str(color) + '.html') #clusters with only one trip
def func7(signal_data): #Declaring an empty list to hold the list of coordinates coordinates = [] #Declaring a smaller list to hold the current coordinates position = [] count = 0 for line in signal_data: if 'latitude' in line.values() and count is 0: position.append(float(line['value'])) count = count + 1 continue if 'latitude' in line.values() and count is 1: position.insert(0,float(line['value'])) coordinates.append(tuple(position)) #Reinitialize position to empty list when both coordinates are found position = [] count = 0 continue if 'longitude' in line.values() and count is 0: position.append(float(line['value'])) count = count + 1 continue if 'longitude' in line.values() and count is 1: position.append(float(line['value'])) coordinates.append(tuple(position)) #Reinitialize position to empty list when both coordinates are found position = [] count = 0 continue print('Map file created') mymap = pygmaps.maps(coordinates[0][0], coordinates[0][1],15) mymap.addpath(coordinates, "#FF0000") mymap.draw('./mymap.html')
def drawTopK_cmp(topKPath, cluster_centers): global colors mymap = pygmaps.maps(37.78713, -122.42392, 13) i = 0 colorNum = 6 for route, timeLen, score in topKPath: path = [] # mymap.addpoint(cluster_centers[sc.startLm][1], cluster_centers[sc.startLm][0], colors[8], title = str(sc.startLm)+'_clus ') # path.append((cluster_centers[sc.startLm][1], cluster_centers[sc.startLm][0])) for lmId in route: lon, lat = findLmLoc(lmId, cluster_centers) if len(path) == 0: mymap.addpoint(lat, lon, colors[8], title = str(lmId)+'_lm '+str(timeLen)+'hr s:'+str(score)) else: mymap.addpoint(lat, lon, colors[i%colorNum], title = str(lmId)+'_lm ') path.append((lat, lon)) mymap.addpoint(lat, lon, colors[7], title = str(lmId)+'_lm ') mymap.addpath(path, colors[i%colorNum]) i += 1 drawName = '_'.join(['topK_cmp', str(sc.popImp), str(sc.simImp), str(sc.ulmImp), 'StartLm'+str(sc.startLm) ]) + '.html' mymap.draw(drawName) url = drawName webbrowser.open_new_tab(url)
def showMap(points, outputDirectory): """ Show GPS path and extracted street view images' locations on Google map. Args: (list) path: a list of GPS data of a path. (list) framePoint: a list of GPS data of extracted video frames. (String) outputDirectory: the folder for storing this map file. """ # Set the center of this map. Using the starting point of the # path as the center of the map. mymap = pygmaps.maps(points[0][0], points[0][1], 10) # Add every points in framePoint to this map. for point in points: # Set the first point with color = "#00FF00". mymap.addpoint(point[0], point[1], "#1515f4") # Create this map. mapFilename = outputDirectory + "map.html" mymap.draw('./' + mapFilename) # Create the local link to this map file. url = "file://" + os.getcwd() + "/" + mapFilename # Open this map on a browser webbrowser.open_new(url)
def make_route_HTML(input_file_name, output_file_name="", input_path="./GPS_route_log", output_path="./htmls", data_separator=",", open_at_finish=False): track_file = open(input_path + "/" + input_file_name, 'r') GPS_data = [] for line in track_file: data = (line.split("\n")[0]).split(data_separator) GPS_data.append((float(data[0]), float(data[1]))) start = [(GPS_data[0])[0], (GPS_data[0])[1]] stop = [(GPS_data[len(GPS_data) - 1])[0], (GPS_data[len(GPS_data) - 1])[1]] mymap = pygmaps.maps(start[0], start[1], 16) mymap.addpoint(start[0], start[1]) #, "#0000FF") mymap.addpoint(stop[0], stop[1], "#FFFFFF") #, "#0000FF") mymap.addpath(GPS_data, "#0000FF") if output_file_name == "": output_file_name = input_file_name + ".html" if (not (os.path.isdir(output_path))): os.system('mkdir ' + output_path) mymap.draw(output_path + "/" + output_file_name) if open_at_finish: webbrowser.open(output_path + "/" + output_file_name, 2)
def compareTrips(section1, section2): startPoint = section1['section_start_point']['coordinates'] # coordinates are in GeoJSON format, ie lng, lat gmap = pygmaps.maps(startPoint[1], startPoint[0], 14) drawSection(section1, PATH, gmap, COLOR[1]) drawSection(section2, PATH, gmap, COLOR[4]) gmap.draw('gmap_display/compare.html')
def getMap(file, path, zoom): if (debug >= 1): print('Entering getMap:') if (debug >= 2): print('File passed in:' + str(file)) print('Path passed in:' + str(path)) print('Zoom Level passed in::' + str(zoom)) # with open(file, 'r') as f: # while (True): # lineIn = f = open(file, 'r') lineIn = skipHash(f) c1, c2 = latLong(lineIn) if (debug >= 2): print('\tCoordinates: ' + str(c1) + ' - ' + str(c2)) mymap = pygmaps.maps(c1, c2, zoom) lineIn = f.readline() counter = 1 while lineIn: c1, c2 = latLong(lineIn) if not (c1 == 0) and not (c2 == 0): mymap.addpoint(c1, c2, "#0000FF") counter += 1 lineIn = f.readline() mymap.draw(path + '\mymap.html') print(counter)
def predict(): features = [float(x) for x in request.form.values()] final_features = [np.array(features)] prediction = model.predict(final_features) mymap3 = pygmaps.maps(features[1], features[2], 15) if prediction[0] == 0: output = "FCW - Imminent collisions Ahead!" mymap3.addpoint(features[1], features[2], "#FF0000") #red elif prediction[0] == 1: output = "HB - Geographic Troubles in this area." mymap3.addpoint(features[1], features[2], "#925F4B") #brown elif prediction[0] == 2: output = "HMW - A lot of traffic here!" mymap3.addpoint(features[1], features[2], "#0000FF") #blue elif prediction[0] == 3: output = "PCW - Watch Out!Pedestrians are Ahead" mymap3.addpoint(features[1], features[2], "#09F434") #green elif prediction[0] == 4: output = "Stoppage - Looks like you're gonna stop." mymap3.addpoint(features[1], features[2], "#925F4B") mymap3.addradpoint(features[1], features[2], 150, "#000000") points1(features, mymap3, n) points2(features, mymap3, n) points3(features, mymap3, n) points4(features, mymap3, n) mymap3.draw(r'C:\Users\Sarvesh\Desktop\Intel\templates\map.htm') return render_template( 'result.htm', prediction_text='Predicted Value: {}'.format(output))
def drawTopK(topKPath, cluster_centers, cluster_centers2): global colors mymap = pygmaps.maps(37.78713, -122.42392, 13) i = 0 colorNum = 6 for score, route, timeLen in topKPath: path = [] if sc.haveStartClus: mymap.addpoint(cluster_centers[sc.startClus][1], cluster_centers[sc.startClus][0], colors[8], title = str(sc.startClus)+'_clus ') path.append((cluster_centers[sc.startClus][1], cluster_centers[sc.startClus][0])) for clus, hr, clusScore in route: lms = findClusLms(clus, hr) mymap.addpoint(cluster_centers[clus][1], cluster_centers[clus][0], colors[i%colorNum], title = str(clus)+'_clus '+str(hr)+'hr') path.append((cluster_centers[clus][1], cluster_centers[clus][0])) for lmId, lm_time, lm_score in lms: lon, lat = findLmLoc(lmId, cluster_centers2) if lmId != 186 and lmId!= 310: if len(path) == 0: mymap.addpoint(lat, lon, colors[8], title = str(lmId)+'_lm '+str(lm_time)+'hr') else: mymap.addpoint(lat, lon, colors[i%colorNum], title = str(lmId)+'_lm '+str(lm_time)+'hr') # path.append((lat, lon)) #draw lm paths mymap.addpoint(cluster_centers[clus][1], cluster_centers[clus][0], colors[7], title = str(clus)+'_clus '+str(hr)+'hr') # mymap.addpoint(lat, lon, colors[7], title = str(lmId)+'_lm '+str(lm_time)+'hr') mymap.addpath(path, colors[i%colorNum]) i += 1 if sc.haveStartClus: drawName = '_'.join(['topK', str(sc.popImp), str(sc.simImp), str(sc.ulmImp), 'StartClus'+str(sc.startClus), sc.seqtime]) + '.html' else: drawName = '_'.join(['topK', str(sc.popImp), str(sc.simImp), str(sc.ulmImp), 'NoStart', sc.seqtime]) + '.html' mymap.draw(drawName) url = drawName webbrowser.open_new_tab(url)
def func7(signal_data): #Declaring an empty list to hold the list of coordinates coordinates = [] #Declaring a smaller list to hold the current coordinates position = [] count = 0 for line in signal_data: if 'latitude' in line.values() and count is 0: position.append(float(line['value'])) count = count + 1 continue if 'latitude' in line.values() and count is 1: position.insert(0, float(line['value'])) coordinates.append(tuple(position)) #Reinitialize position to empty list when both coordinates are found position = [] count = 0 continue if 'longitude' in line.values() and count is 0: position.append(float(line['value'])) count = count + 1 continue if 'longitude' in line.values() and count is 1: position.append(float(line['value'])) coordinates.append(tuple(position)) #Reinitialize position to empty list when both coordinates are found position = [] count = 0 continue print('Map file created') mymap = pygmaps.maps(coordinates[0][0], coordinates[0][1], 15) mymap.addpath(coordinates, "#FF0000") mymap.draw('./mymap.html')
def plotMap(allPaths): print "Plot points..., total %d points" % len(allPaths) def printFunc(n): sys.stdout.write("\r%d" % n) prog = CustomedProgress() prog.setThreshold(1000) prog.setPrintFunc(printFunc) centerLng, centerLat = findCenterFromPaths(allPaths) myMap = pygmaps.maps(centerLat, centerLng, 10) colors = ["#ff3300", "#3333ff", "#0000", "#ff00ff", "#00e600", "#ff9900", "#66c2ff", "#ffff00"] colorIdx = 0 for path in allPaths: prog.printProgress() pathPoint = getPath(path) myMap.addpath(pathPoint, colors[colorIdx]) colorIdx = (colorIdx + 1) % len(colors) # create map file mapFilename = "allPath.html" myMap.draw('./' + mapFilename) # Open the map file on a web browser. url = "file://" + os.getcwd() + "/" + mapFilename webbrowser.open_new(url)
def draw_trips(directory, outputpath): filelist = traverseFolder(directory, '.mat') print(filelist) make_sure_path_exists(outputpath) color_list = ['Aqua', 'Alizarin crimson', 'Amber', 'Amethyst', 'Android Green', 'Azure', 'Deep pink', 'Magenta'] color_dictionary = {'Aqua': "#00ffff", 'Alizarin crimson': "#e32636", 'Amber': "#ffbf00", 'Amethyst': "#9966cc", 'Android Green': "#a4c639", 'Azure': "#007fff", 'Deep pink': "#ff1493", 'Magenta': "#f00ff" } start_color = "#0000FF" end_color = "#FF0000" index = 0 Trip_list = [] for file in filelist: Trip_data = load_mat_file(file) # load origin .mat data point_list = extract_points_location(Trip_data) trip = Trip() trip.name = file trip.start_point = point_list[0] trip.end_point = point_list[-1] trip.Trip_index = index trip.path_list = [] trip.path_color = color_list[index] for i in point_list: trip.path_list.append(tuple([i.latitude, i.longitude])) # draw start point, end point, route_path if 'mymap' not in locals(): mymap = pygmaps.maps(trip.start_point.latitude, trip.start_point.longitude, 12) # start a map mymap.addpoint(trip.start_point.latitude, trip.start_point.longitude, start_color) mymap.addpoint(trip.end_point.latitude, trip.end_point.longitude, end_color) mymap.addpath(trip.path_list, color_dictionary[trip.path_color]) index = (index + 1) % len(color_list) map_path = outputpath + 'SoSd.map.draw.html' # delete the '.mat' and add '.map.draw.html' mymap.draw(map_path) url = map_path webbrowser.open_new_tab(url) Trip_list.append(trip)
def createRoute(home, dest, altitude, airspeed, custom=[], environments=[], climb_dist=7, climb_speed=75, region="NORTHEAST"): messages = [] ll = getLatLon(home) origin = Point_Of_Interest(home, ll[0], ll[1], 0) destination = Point_Of_Interest(dest, getLatLon(dest)[0], getLatLon(dest)[1], -1) course = getDistHeading(origin, destination) elevation_data = getProperAlt(origin, destination, course) cruising_alt = elevation_data[0] elevation_map = elevation_data[1] final_alt = altitude if (float(cruising_alt) > float(altitude) or True): # TODO: should be if one is not even/odd etc. final_alt = cruising_alt messages.append("Changed cruising altitude") rType = "direct" if len(custom) == 0 else "custom" print 'Make route' route = Route(course, origin, destination, routeType=rType, custom=custom, cruising_alt=final_alt, cruise_speed=airspeed, \ climb_speed=climb_speed, climb_dist=climb_dist, doWeather=False, region=region) print 'Insert climb' noTOC = copy.copy(route) route.insertClimb() messages.append("Added Top of Climb (TOC) waypoint") # map creation num = getMid(len(route.courseSegs)) mapLL = (route.courseSegs[num].to_poi.lat, route.courseSegs[num].to_poi.lon) mymap = pygmaps.maps(float(mapLL[0]), float(mapLL[1]), 7) mymap.addpoint(float(ll[0]), float(ll[1])) path = [] path.append((float(ll[0]), float(ll[1]))) frequencies = getFrequencies(route.courseSegs) # route path line for item in route.courseSegs: path.append((float(item.to_poi.lat), float(item.to_poi.lon))) if item.to_poi.hasFuel: # this will not work if frequencies have not yet been set # some fuel/gas sign here - clipart type thing mymap.addpoint(float(item.to_poi.lat), float(item.to_poi.lon)) else: # no discrimination based on fuel currentlyforms mymap.addpoint(float(item.to_poi.lat), float(item.to_poi.lon)) # add point with fuel or not mymap.addpath(path, "#4169E1") return (getHtml(mymap, route.landmarks), noTOC, route, elevation_map, messages, frequencies, getZip(origin))
def index(request): mymap = pygmaps.maps(20.680329,-103.348732,17) mapa = mymap.script_drawmap() miubicacion = mymap.script_self_point() c = Context({'drawselfpoint':miubicacion,'drawmap':mapa}) t = get_template("mimapa.html") html = t.render(c) return HttpResponse(html)
def gmaps(): #Build map map = pygmaps.maps(latitude, longitude, 3) for p,k in latlong.items(): #Add in locations map.addpoint(float(p), float(k)) #Draw the map map.draw('./map.html')
def getGoogleMap(self): latidute = [y.data.x for y in self.gps_llh] longitude = [y.data.y for y in self.gps_llh] height = [y.data.z for y in self.gps_llh] mymap = pygmaps.maps(latidute[1],longitude[1],16) path = zip(latidute, longitude) mymap.addpath(path, "#0099FF") mymap.draw('./mymap.html')
def plot_common_routes_for_user(user_id, method='lcs'): Sections = get_section_db() idxs = get_common_routes_for_user(user_id, method) gmap = pygmaps.maps(37.8717, -122.2728, 14) for idx in idxs: section = Sections.find_one({'_id': idx}) drawSection(section, 'path', gmap) gmap.draw(str(user_id) + '_' + method + '.html')
def draw_coroutes(directory, outputpath, number): filelist = traverseFolder(directory, '.mat', number) print(filelist) make_sure_path_exists(outputpath) color_list = ['Deep pink', 'Alizarin crimson', 'Amber', 'Amethyst', 'Android Green', 'Azure', 'Aqua', 'Magenta'] color_dictionary = {'Aqua': "#00ffff", 'Alizarin crimson': "#e32636", 'Amber': "#ffbf00", 'Amethyst': "#9966cc", 'Android Green': "#a4c639", 'Azure': "#007fff", 'Deep pink': "#ff1493", 'Magenta': "#f00ff" } start_color = "#0000FF" end_color = "#FF0000" index = 0 coRoute_list = [] for file in filelist: coRoute_data = load_mat_file(file) point_list = extract_points_location(coRoute_data) route = coRoute() route.name = file route.start_point = point_list[0] route.end_point = point_list[-1] route.coRoute_index = index route.path_list = [] route.path_color = color_list[index] for i in point_list: route.path_list.append(tuple([i.latitude, i.longitude])) # draw start point, end point, route_path mymap = pygmaps.maps(route.start_point.latitude, route.start_point.longitude, 12) # start a map mymap.addpoint(route.start_point.latitude, route.start_point.longitude, start_color) mymap.addpoint(route.end_point.latitude, route.end_point.longitude, end_color) mymap.addpath(route.path_list, color_dictionary[route.path_color]) index = index + 1 map_path = outputpath + file.split("/")[-1][:-4] + '.map.draw.html' # delete the '.mat' and add '.map.draw.html' mymap.draw(map_path) url = map_path webbrowser.open_new_tab(url) coRoute_list.append(route)
def display_home(): mymap_home = pygmaps.maps(37.8556475757, -122.248774009, 14) for user in get_section_db().distinct('user_id'): print(user) user_home = detect_home(user) print(user_home) if user_home != 'N/A': mymap_home.addpoint(user_home[0], user_home[1], "#FF0000") mymap_home.draw('mymap_home.html')
def iphone_test(value): flag = 0 lats = [] longs = [] lines = value line = lines.split("\n") for each in line: if (each != ""): each1 = each.split() if (re.match("[0-9]+", each1[5])): lats.append(float(each1[5])) if (re.match("[0-9]+", each1[6])): longs.append(float(each1[6])) latitudes = RemoveOutliers(lats) longitudes = RemoveOutliers(longs) centerlong = mean(longitudes) centerlat = mean(latitudes) mymap = pygmaps.maps(centerlat, centerlong, 10) print "<table border='1'>" for each in line: if (each != ""): print "<tr>" each1 = each.split() if (re.match("[0-9]+", each1[5])): print "<td>" + each1[5] + "</td>" lat = float(each1[5]) flag = 0 else: flag = -1 print "<th>" + "Latitude " + "</th>" if (re.match("[0-9]+", each1[6])): print "<td>" + "<br>" + each1[6] + "</td>" longitude = float(each1[6]) flag = 0 else: print "<th>" + "Longitude" + "</th>" flag = -1 if flag == -1: print "<th>" + "Formatted Address" + "</th>" else: address = returnaddress(lat, longitude) utf_version = address.encode('utf-8') print "<td>" + "<br>" + utf_version + "</td>" if (flag == 0): mymap.addradpoint(lat, longitude, 30000, "#FF0000") mymap.addpoint(lat, longitude, "#FF0000") print "</tr>" print "</table>" mymap.draw('mymap.draw.html') url = 'mymap.draw.html' webbrowser.open_new(url)
def ihopethisshitwrosk(): Food.query(fat,rat) title = "ur here" mymap = pygmaps.maps(fat,rat,20) mymap.addpoint(fat, rat,"Sr") for k,v in Food.query(fat,rat).items(): mymap.addpoint(k,v,"#0000FF") mymap.draw("./mymap.html")
def makeCircleMapRating(coordinates): meanLat = np.mean(coordinates["latitude"]) meanLon = np.mean(coordinates["longitude"]) # circleMapRating = pygmaps.maps(meanLat, meanLon, 8) circleMapRating = pygmaps.maps(38.231761, -122.896364, 9) i = 0 k = 0 j = 0 l = 0 for business in range(len(coordinates)): if coordinates["rating"][business] == 0.5 or coordinates["rating"][ business] == 1: #yellow # if i < 100: circleMapRating.addradpoint(coordinates["latitude"][business], coordinates["longitude"][business], 200, '#F8E71C') # i += 1 for business in range(len(coordinates)): if coordinates["rating"][business] == 1.5 or coordinates["rating"][ business] == 2: #green # if k < 100: circleMapRating.addradpoint(coordinates["latitude"][business], coordinates["longitude"][business], 200, '#50E3C2') # k += 1 for business in range(len(coordinates)): if coordinates["rating"][business] == 2.5 or coordinates["rating"][ business] == 3: #red # if j < 100: circleMapRating.addradpoint(coordinates["latitude"][business], coordinates["longitude"][business], 200, '#FF0000') # j += 1 for business in range(len(coordinates)): if coordinates["rating"][business] == 3.5 or coordinates["rating"][ business] == 4: #blue # if l < 100: circleMapRating.addradpoint(coordinates["latitude"][business], coordinates["longitude"][business], 200, '#1015E0') # l += 1 for business in range(len(coordinates)): if coordinates["rating"][business] == 4.5 or coordinates["rating"][ business] == 5: #purple # if l < 100: circleMapRating.addradpoint(coordinates["latitude"][business], coordinates["longitude"][business], 200, '#BD10E0') # l += 1 return circleMapRating.draw( '/Users/selinerguncu/Desktop/PythonProjects/Fun Projects/Yelp/yelp/static/circleMapRating.html' )
def iphone_test(value): flag=0 lats=[] longs=[] lines=value line=lines.split("\n") for each in line: if (each!=""): each1=each.split() if (re.match("[0-9]+",each1[5])): lats.append(float(each1[5])) if (re.match("[0-9]+",each1[6])): longs.append(float(each1[6])) latitudes=RemoveOutliers(lats) longitudes=RemoveOutliers(longs) centerlong=mean(longitudes) centerlat=mean(latitudes) mymap = pygmaps.maps(centerlat,centerlong, 10) print "<table border='1'>" for each in line: if(each != ""): print "<tr>" each1=each.split() if(re.match("[0-9]+",each1[5])): print "<td>"+each1[5]+"</td>" lat=float(each1[5]) flag=0 else: flag=-1 print "<th>"+"Latitude "+"</th>" if(re.match("[0-9]+",each1[6])): print "<td>"+"<br>"+each1[6]+"</td>" longitude=float(each1[6]) flag=0 else: print "<th>"+"Longitude"+"</th>" flag=-1 if flag==-1: print "<th>"+"Formatted Address"+"</th>" else: address=returnaddress(lat,longitude) utf_version=address.encode('utf-8') print "<td>"+"<br>"+utf_version+"</td>" if(flag==0): mymap.addradpoint(lat, longitude, 30000, "#FF0000") mymap.addpoint(lat, longitude, "#FF0000") print "</tr>" print "</table>" mymap.draw('mymap.draw.html') url = 'mymap.draw.html' webbrowser.open_new(url)
def create_search_map(origin, coords, radius_enforced=True, radius=1): lat, lon = origin gmap = pygmaps.maps(lat, lon, 12) # 14 is the map's zoom level gmap.addradpoint(lat, lon, (radius * METERS_PER_MILE), "origin") for pair in coords: lat, lon = pair gmap.addpoint(lat, lon, "#0000FF") timestamp = strftime("%H:%M:%S", localtime()) gmap.draw("./search_map_({0}).html".format(timestamp))
def gmaps_mapit(self): print ("GO!") # f = open('Regions.text', 'r') # map_regions = [] # for line in f: # map_regions.append(line.rstrip('\n')) geo = Geocoder.geocode(self.sel_st) geo_st = (geo[0].coordinates) st_joint = ', '.join(map(str, geo_st)) split_st_joint = st_joint.split(',', 2) st_lat = split_st_joint[0] st_lon = split_st_joint[1] print st_joint print split_st_joint print st_lat print st_lon regions_map = pygmaps.maps(float(st_lat), float(st_lon),7) # Generate state map f = open('Regions.text', 'r') map_regions = [] for line in f: map_regions.append(line.rstrip('\n')) print "map_regions: " print map_regions def geo_region(): for item in map_regions: try: geo_reg = Geocoder.geocode(item) except: pass else: point = (geo_reg[0].coordinates) title = item joint = ', '.join(map(str, point)) split_point = joint.split(',', 2) lat = split_point[0] lon = split_point[1] if '(All Digital)' in item: regions_map.addpoint(float(lat), float(lon), "#0101DF", title=title) else: regions_map.addpoint(float(lat), float(lon), "#FF0000", title=title) # print "Point: " # print point # print "Joint: " # print joint # print "split_joint: " # print split_point sleep(0.1) geo_region() regions_map.draw('./mymap.html') print "Done"
def initMap(ofile, useBrowser): """Set up Google Maps""" # centre map on Greenwich twMap = pygmaps.maps(51.20, 0.0, 2.8) twMap.draw(os.getcwd() + "/" + ofile) if useBrowser: controller = webbrowser.get("safari") else: controller = None return (twMap, controller)
def mapping(item): gmaps = googlemaps.Client(key='AIzaSyC0Mmo-RKU6ZhYVuEbjOBnBBqkOjd9Ju_8') gmap = pygmaps.maps(34.213320, -118.457529, 12) geocode = gmaps.geocode(item)[0] latlong = geocode['geometry']['location'] gmap.addpoint( latlong['lat'], latlong['lng'], ) gmap.draw("map.html")
def initMap(ofile,useBrowser): """Set up Google Maps""" # centre map on Greenwich twMap = pygmaps.maps(51.20,0.0,2.8) twMap.draw(os.getcwd() + "/" + ofile) if useBrowser: controller = webbrowser.get("safari") else: controller = None return (twMap,controller)
def display_trip(file_name): with open(file_name, 'r') as f: data = f.readlines() sections = literal_eval(data[0]) gmap = pygmaps.maps(37.8717, -122.2728, 14) for section in sections: print(section.keys()) if section['type'] == 'move': drawSection(section, gmap) gmap.draw(file_name + '.html')
def plotOnMap(lonAxisStart, lonAxisStop, latAxisStart, latAxisStop, prob, allPoints, vmin, vmax): lat1 = latAxisStart + ((latAxisStop-latAxisStart)/2) lon1 = lonAxisStart + ((lonAxisStop-lonAxisStart)/2) mymap = pygmaps.maps(lat1, lon1, 12) addMapPoints(prob, allPoints, mymap, vmin, vmax) mymap.draw('mymap.draw.html') url = 'mymap.draw.html' webbrowser.open_new_tab(url)
def make_map(self, a, b, point_a, point_b, path): # Add to a map and write it out path_map = pygmaps.maps(point_a[0], point_a[1], 12) path_map.addpoint(point_a[0], point_a[1], "#0000FF") path_map.addpoint(point_b[0], point_b[1], "#0000FF") # Convert the list path_map.addpath(path, "#FF0000") path_map.draw('%s/%s-%s.html' % (self.output_dir, a.capitalize(), b.capitalize()));
def makeDataMap(coordinateList): #bigList = readBikeData.GatherData('rows.json') #DONT CHANGE FOLLOWING LINE mymap = pygmaps.maps(37.7749295, -122.4194155, 13) for i in range(len(coordinateList)): mymap.addpoint(coordinateList[i][0], coordinateList[i][1], "#FF0000") mymap.draw('mymap.draw.html') url = 'mymap.draw.html' webbrowser.open_new_tab(url)
def main(): """ Main rountine to parse drive log and create Google map """ # Read the file, splitting into lists of parsed gps messages and RSSI floats gps = [] rssi = [] for line in fileinput.input(): # Ignore lines that don't start with $ if line[0] == '$': pmsg = pynmea2.parse(line.split()[0]) # Strip out messages with no GPS fix (zero latitude or longitude) if (pmsg.latitude == 0.0) or (pmsg.longitude == 0.0): pass else: gps.append(pmsg) rssi.append(float(line.split()[1])) else: pass # Use the first gps coordinate to center the map mymap = pygmaps.maps(gps[0].latitude, gps[0].longitude, 16) # Create a color map from the min and max RSSI rssi_max = sorted(rssi, key=float)[-1] rssi_min = sorted(rssi, key=float)[0] cmap = plt.get_cmap('jet') cNorm = colors.Normalize(vmin=rssi_min, vmax=rssi_max) scalarMap = cmx.ScalarMappable(norm=cNorm, cmap=cmap) print 'RSSI_max = ' + str(rssi_max) + ' dBm' print 'RSSI_min = ' + str(rssi_min) + ' dBm' # Plot the points while len(gps) != 0: # Map a color to the RSSI value and convert to hex string color = scalarMap.to_rgba(rssi[0]) red = "{0:0{1}x}".format(int(color[0]*255),2) green = "{0:0{1}x}".format(int(color[1]*255),2) blue = "{0:0{1}x}".format(int(color[2]*255),2) color_string = "#" + red + green + blue # Parse the gps_msg and plot point_label = str(rssi[0]) + ' dBm, ' point_label += str(gps[0].altitude) + gps[0].altitude_units mymap.addpoint(gps[0].latitude, gps[0].longitude, color_string, point_label) gps.pop(0) rssi.pop(0) # Create the Google map *.html file input_file_name = fileinput.filename() output_file_name = input_file_name.split('.')[0] + ".html" mymap.draw(output_file_name)
def gmaps_mapit(): regions_map = pygmaps.maps(44.3148443, -85.60236429999999,7) # Generate state map f = open('Regions2.text', 'r') map_regions = [] for line in f: map_regions.append(line.rstrip('\n')) print map_regions region_coords = [] def geo_region(): for item in map_regions: try: geo = Geocoder.geocode(item) except: pass else: point = (geo[0].coordinates) joint = ', '.join(map(str, point)) split_point = joint.split(',', 2) lat = split_point[0] lon = split_point[1] print point # point represents the lat/long for each city # print split_joint # print lats # print lons regions_map.addpoint(float(lat), float(lon)) # region_coords.append(joint) # time.sleep(0.5) # print region_coords # for x in region_coords: # map_coords() # mymap = pygmaps.maps(45.0702432, -85.2653517, 14) # mymap.addpoint(45.0702432, -85.2653517, "#0000FF") # mymap.addpoint(45.0702032, -85.2652117, "#FF0000") geo_region() # regions_map.addpoint(44.3148443, -85.60236429999999) def map_coords(): for x in region_coords: regions_map.addpoint(x) # regions_map.addpoint(44.3148443, -85.60236429999999) map_coords() regions_map.draw('./mymap.html')
def do_map(json_output, options): """ Creates a google map HTML page with points plotted for every point in known, and draws a line between each. """ gmap = pygmaps.maps(json_output[0]['latitude'], json_output[0]['longitude'], options.map_zoom) for track in json_output: gmap.addpoint(track['latitude'], track['longitude'], "#0000FF") logging.debug("All points: %s" % [(track['latitude'], track['longitude']) for track in json_output]) gmap.addpath([(track['latitude'], track['longitude']) for track in json_output]) gmap.draw(map_output)
def drawLayer(labels, cluster_centers, n_clusters_, loc, layerNum): mymap = pygmaps.maps(37.78713, -122.42392, 13) for k in range(n_clusters_): my_members = labels == k for j in range(0,len(loc[my_members, 0])): mymap.addpoint(loc[my_members, 1][j], loc[my_members, 0][j], colors[k%7], title = str(k)) # mymap.addpoint(cluster_centers[k][1], cluster_centers[k][0], colors[8], title = str(k)) pageName = 'sf layer'+str(layerNum)+'.html' mymap.draw(pageName) url = pageName webbrowser.open_new_tab(url)
def buildMap(monumento, tuits, radio): lon, lat = monumento['geometry']['coordinates'] mymap = pygmaps.maps(lat, lon, 16) mymap.addpoint(lat, lon, '#00BBFF') mymap.addradpoint(lat, lon, radio, '#00BBFF') for tuit in tuits: mymap.addpoint(tuit['coordenadas']['latitud'], tuit['coordenadas']['longitud'], '#FFBB00') build(mymap, './index.html')
def map_clusters_by_groundtruth(data, labels, colors, map_individuals=False): import pygmaps from matplotlib import colors as matcol colormap = plt.cm.get_cmap() import random r = random.sample(list(range(len(set(labels)))), len(set(labels))) rand = [] clusters = len(set(labels)) for i in range(len(labels)): rand.append(old_div(r[labels[i]], float(clusters))) if map_individuals: for color in set(colors): first = True num_paths = 0 for i in range(len(colors)): if colors[i] == color: num_paths += 1 start_lat = data[i].trip_start_location.lat start_lon = data[i].trip_start_location.lon end_lat = data[i].trip_end_location.lat end_lon = data[i].trip_end_location.lon if first: mymap = pygmaps.maps(start_lat, start_lon, 10) first = False path = [(start_lat, start_lon), (end_lat, end_lon)] mymap.addpath(path, matcol.rgb2hex(colormap(rand[i]))) mymap.draw('./mycluster' + str(color) + '.html') mymap = pygmaps.maps(37.5, -122.32, 10) for i in range(len(data)): start_lat = data[i].trip_start_location.lat start_lon = data[i].trip_start_location.lon end_lat = data[i].trip_end_location.lat end_lon = data[i].trip_end_location.lon path = [(start_lat, start_lon), (end_lat, end_lon)] mymap.addpath( path, matcol.rgb2hex( colormap(old_div(float(colors[i]), len(set(colors)))))) mymap.draw('./mymap.html')
def map_clusters(self): import pygmaps from matplotlib import colors as matcol colormap = plt.cm.get_cmap() mymap = pygmaps.maps(37.5, -122.32, 10) for i in range(len(self.points)): start_lat = self.data[i]['trip_start_location'][1] start_lon = self.data[i]['trip_start_location'][0] end_lat = self.data[i]['trip_end_location'][1] end_lon = self.data[i]['trip_end_location'][0] path = [(start_lat, start_lon), (end_lat, end_lon)] mymap.addpath(path, matcol.rgb2hex(colormap(float(self.colors[i])/len(set(self.colors))))) mymap.draw('./mymap.html') mymap2 = pygmaps.maps(37.5, -122.32, 10) for i in range(len(self.points)): start_lat = self.data[i]['trip_start_location'][1] start_lon = self.data[i]['trip_start_location'][0] end_lat = self.data[i]['trip_end_location'][1] end_lon = self.data[i]['trip_end_location'][0] path = [(start_lat, start_lon), (end_lat, end_lon)] mymap2.addpath(path, matcol.rgb2hex(colormap(float(self.labels[i])/self.clusters))) mymap2.draw('./mylabels.html')
def map(self): import pygmaps mymap = pygmaps.maps(37.5, -122.32, 10) for t in self.reps: start_lat = t.trip_start_location.lat start_lon = t.trip_start_location.lon end_lat = t.trip_end_location.lat end_lon = t.trip_end_location.lon path = [(start_lat, start_lon), (end_lat, end_lon)] mymap.addpath(path) for l in self.locs: mymap.addpoint(l.lat, l.lon, '#0000FF') mymap.draw('./myreps.html')
def test(self): homeDetection = pygmaps.maps(37.8656475757, -122.258774009,14) for user in get_section_db().distinct('user_id'): user_home=home.detect_home(user) print user if user_home == 'N/A' or '': print '--- USER HOME ADDRESS UNAVAILABLE ---' else: print(Geocoder.reverse_geocode(user_home[0], user_home[1])[0]) homeDetection.addpoint(user_home[0], user_home[1], "#FF0000") print '...' if not os.path.exists('gmap_display'): os.makedirs('gmap_display') homeDetection.draw('gmap_display/homeDetection.html')
def test(self): workDetection = pygmaps.maps(37.8656475757, -122.258774009,14) for user in get_section_db().distinct('user_id'): user_work=work_place.detect_work_office(user) print user if user_work == 'N/A' or '': print '--- USER WORK ADDRESS UNAVAILABLE ---' else: print(Geocoder.reverse_geocode(user_work[0], user_work[1])[0]) workDetection.addpoint(user_work[0], user_work[1], "#FF0000") print '...' if not os.path.exists('gmap_display'): os.makedirs('gmap_display') workDetection.draw('gmap_display/workDetection.html')
def func8(signal_data): #Creating a dictionary with keys and values as times when vehicle speed was zero #We want for 1 second resolution and we want distinct time values timestamps = {} for line in signal_data: if ('vehicle_speed' in line.values()) and (float(line['value']) == 0): time = float(line['timestamp']) timestamps[round(time, 0)] = 1 #Declaring an empty list to hold the list of coordinates coordinates = {} #Declaring a smaller list to hold the current coordinates position = [] count = 0 for line in signal_data: if 'latitude' in line.values() and count is 0: position.append(float(line['value'])) count = count + 1 continue if 'latitude' in line.values() and count is 1: position.insert(0,float(line['value'])) time = float(line['timestamp']) coordinates[round(time, 0)] = (tuple(position)) #Reinitialize position to empty list when both coordinates are found position = [] count = 0 continue if 'longitude' in line.values() and count is 0: position.append(float(line['value'])) count = count + 1 continue if 'longitude' in line.values() and count is 1: position.append(float(line['value'])) time = float(line['timestamp']) coordinates[round(time, 0)] = (tuple(position)) #Reinitialize position to empty list when both coordinates are found position = [] count = 0 continue #Creating a list of points where we have latitude and longitude values for times when vehicle speed was zero points = [] for time in timestamps.keys(): for line in coordinates.keys(): if (time == line): points.append(coordinates[line]) #Plotting those points on a google map mymap = pygmaps.maps(points[0][0], points[0][1],20) for point in points: mymap.addpoint(point[0], point[1], "#FF0000") print('Created a plot--> check mystop.html file') mymap.draw('./mystop.html')
def func7(e1): lst=[] lst_a=[] lst_1=[] lst1=[] lst2=[] for i in e1: if(i['name']== 'transmission_gear_position'): lst.append(i['value']) #print(lst) for k in range(len(lst)): if(lst[k]=='first'): lst[k]=1 elif(lst[k]=='second'): lst[k]=2 elif(lst[k]=='three'): lst[k]=3 elif(lst[k]=='second'): lst[k]=4 else: lst[k]=0 #for 'neutral' gear print(lst) for i in e1: if(i['name']== 'transmission_gear_position'): if not i['value'] in lst_a: lst_a.append(i['value']) print(lst_a) import pygmaps import webbrowser for i in e1: lst_1.append(i['timestamp']) for i in e1: if(i['name']== 'latitude'): lst1.append(i['value']) for i in e1: if(i['name']== 'longitude'): lst2.append(i['value']) mymap = pygmaps.maps(lst1[int((len(lst1))/2)], lst2[int((len(lst2))/2)], 16) path = list(zip(lst1,lst2)) mymap.addpath(path,"#00FF00") mymap.draw('./mymap.html')