def __update_bbox(self, lon, lat): if self.boundingbox is None: self.boundingbox = BoundingBox(north=lat.max(), south=lat.min(), west=lon.min(), east=lon.max()) else: self.boundingbox = BoundingBox( north=max(self.boundingbox.north, lat.max()), south=min(self.boundingbox.south, lat.min()), west=min(self.boundingbox.west, lon.min()), east=max(self.boundingbox.east, lon.max()))
def start(self): # pyglet.options['debug_gl'] = False if self.geoplotlib_config.bbox is not None: self.proj.fit(self.geoplotlib_config.bbox) elif len(self.geoplotlib_config.layers) > 0: self.proj.fit(BoundingBox.from_bboxes([l.bbox() for l in self.geoplotlib_config.layers])) for l in self.geoplotlib_config.layers: l.invalidate(self.proj) pyglet.app.run()
def start(self): #pyglet.options['debug_gl'] = False if self.geoplotlib_config.bbox is not None: self.proj.fit(self.geoplotlib_config.bbox, force_zoom=self.geoplotlib_config.requested_zoom) elif len(self.geoplotlib_config.layers) > 0: self.proj.fit(BoundingBox.from_bboxes([l.bbox() for l in self.geoplotlib_config.layers]), force_zoom=self.geoplotlib_config.requested_zoom) for l in self.geoplotlib_config.layers: l.invalidate(self.proj) pyglet.app.run()
def draw(self, proj, mouse_x, mouse_y, ui_manager): self.painter = BatchPainter() self.painter.set_color([0,0,255]) df = self.data.where((self.data['timestamp'] > self.t) & (self.data['timestamp'] <= self.t + 30*60)) proj.fit(BoundingBox.from_points(lons=df['lon'], lats=df['lat']), max_zoom=14) x, y = proj.lonlat_to_screen(df['lon'], df['lat']) self.painter.linestrip(x, y, 10) self.t += 30 if self.t > self.data['timestamp'].max(): self.t = self.data['timestamp'].min() self.painter.batch_draw() ui_manager.info(epoch_to_str(self.t))
def draw_grid(nodes, unfiltered=None): """ Draw grid using computed nodes. Args: nodes (numpy.ndarray): Data points to plot unfiltered (numpy.ndarray): Unfiltered data points. If not None, plot using different color. """ # Layer for plotting the nodes class PointsLayer(BaseLayer): def __init__(self, data, color, point_size): self.data = data self.color = color self.point_size = point_size def invalidate(self, proj): x, y = proj.lonlat_to_screen(self.data['lon'], self.data['lat']) self.painter = BatchPainter() self.painter.set_color(self.color) self.painter.points(x, y, point_size=self.point_size, rounded=True) def draw(self, proj, mouse_x, mouse_y, ui_manager): self.painter.batch_draw() # Get grid node data into dict format. data_grid = {'lat': nodes[:, 0], 'lon': nodes[:, 1]} # If unfiltered nodes specified, get data into dict format. if unfiltered is not None: data_unfiltered = {'lat': unfiltered[:, 0], 'lon': unfiltered[:, 1]} # If unfiltered nodes specified, plot on layer. if unfiltered is not None: geoplotlib.add_layer( PointsLayer(data_unfiltered, color=[255, 0, 0], point_size=4)) # Plot grid nodes. geoplotlib.add_layer( PointsLayer(data_grid, color=[0, 0, 255], point_size=7)) # Set bounding box and show. geoplotlib.set_bbox( BoundingBox(north=40.897994, west=-73.199040, south=40.595581, east=-74.55040)) geoplotlib.show()
def visualize_heatmap_for_data(self, df): """ Normally visualize accidents distributions across borough :param df: Dataset :return: None """ geo_data_for_plotting = {"lat": df["LATITUDE"], "lon": df["LONGITUDE"]} geoplotlib.kde(geo_data_for_plotting, 1) east = max(df["LONGITUDE"]) west = min(df["LONGITUDE"]) south = max(df["LATITUDE"]) north = min(df["LATITUDE"]) bbox = BoundingBox(north=north, west=west, south=south, east=east) geoplotlib.set_bbox(bbox) geoplotlib.tiles_provider('toner-lite') geoplotlib.show()
def _draw_hot(day, hour, minute): """ geoplotlib热力图 :param day: :param hour, minute: :param tp: :return: """ data = da.loc_state(day, hour, minute) bbox1 = BoundingBox(north=32, south=30.7, west=122.2, east=120.8) gp.set_bbox(bbox1) # gp.shapefiles('F:\\road_datas\\ShangHai\\boundary', shape_type='empty') gp.kde(data, bw=[0.5, 0.5], cmap='jet', scaling='wjk') gp.savefig('001') gp.show()
def drawmap(self): """ Multiple examples of kernel density estimation visualization """ data = self.get_dao_object() # geoplotlib.kde(data, bw=5, cut_below=1e-4) # lowering clip_above changes the max value in the color scale # geoplotlib.kde(data, bw=5, cut_below=1e-4, clip_above=.1) # different bandwidths geoplotlib.kde(data, bw=20, cmap=self.cmap, cut_below=1e-4) # geoplotlib.kde(data, bw=2, cmap='PuBuGn', cut_below=1e-4) # linear colorscale # geoplotlib.kde(data, bw=5, cmap='jet', cut_below=1e-4, scaling='lin') geoplotlib.set_bbox(BoundingBox.from_nominatim('CHINA')) geoplotlib.savefig(self.ouput_filename)
def saveGeoData(dataFrame, feature, label, tag): plot_inc_d = {} for inc in dataFrame[feature].unique(): accidents = dataFrame.loc[dataFrame[feature].isin([inc])] plot_inc = {} plot_inc = accidents[['LATITUDE', 'LONGITUDE']] plot_inc.columns = ['lat', 'lon'] for col in plot_inc.columns: plot_inc_d[col] = plot_inc[col].tolist() # Plotting the data w. geoplotlib print label + ":", inc print "Samples:", len(accidents) gpl.kde(plot_inc_d, bw=1, cut_below=2e-4) gpl.set_bbox( BoundingBox(north=40.93, west=-73.85, south=40.53, east=-73.83)) gpl.savefig('geo' + str(tag) + "_" + str(inc)) plot_inc_d = {}
import sys import numpy import geoplotlib from geoplotlib.utils import read_csv, BoundingBox from geoplotlib.colors import ColorMap data = read_csv('data/out_FL.csv') #TODO: apply filtering here rather than when making the csv bb = BoundingBox.from_points(lons=data['lon'], lats=data['lat']) #TODO: utilize layers #mark the station locations geoplotlib.dot(data, color=[0, 0, 0, 255]) #TODO: show based on zoom level #geoplotlib.labels(data,'Station Name (LEA)', color=[150,150,190,255], font_size=9, anchor_x='center') #geoplotlib.voronoi(data, cmap='Blues_r', max_area=8e3, alpha=200, f_tooltip=lambda d:d['Station Name (LEA)'] ) geoplotlib.kde(data, cmap='Blues_r', bw=10, cut_below=1e-4, scaling='lin') #geoplotlib.delaunay(data,cmap='hot_r') ##post geoplotlib.set_bbox(bb) geoplotlib.set_smoothing(True) geoplotlib.show()
def bbox(self): north, west = self.num2deg(self.xtile, self.ytile, self.zoom) south, east = self.num2deg(self.xtile + self.tiles_horizontally, self.ytile + self.tiles_vertically, self.zoom) return BoundingBox(north=north, west=west, south=south, east=east)
def bbox(self): return BoundingBox.from_points(lons=self.data['lon'], lats=self.data['lat'])
def bbox(self): return BoundingBox(north=self.lat_edges[-1], south=self.lat_edges[0], west=self.lon_edges[0], east=self.lon_edges[-1])
def bbox(self): return BoundingBox(north=37.801421, west=-122.517339, south=37.730097, east=-122.424474)
def bbox(self): return BoundingBox.from_points( lons=np.hstack([self.data[self.src_lon], self.data[self.dest_lon]]), lats=np.hstack([self.data[self.src_lat], self.data[self.dest_lat]]))
def bbox(self): """ Return the bounding box for this layer """ return BoundingBox.from_points(lons=self.data['lon'], lats=self.data['lat'])
f = open("VLOCs.csv", "w+") f.close() #write csv to be read by geoplotlib with open('VLOCs.csv', mode='w', newline='') as VLOCs: VLOCs = csv.writer(VLOCs, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL) VLOCs.writerow(['name', 'S_lat', 'S_lon', 'D_lat', 'D_lon']) for station in Locations: VLOCs.writerow([station[0], station[1], station[2], station[3], station[4]]) #empty SLOCs.csv f = open("SLOCs.csv", "w+") f.close() #write csv to be read by geoplotlib with open('SLOCs.csv', mode='w', newline='') as SLOCs: SLOCs = csv.writer(SLOCs, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL) SLOCs.writerow(['name', 'lat', 'lon']) for station in Locations: SLOCs.writerow([station[0], station[1], station[2]]) #plot stations Plotdata1 = read_csv('VLOCs.csv') Plotdata2 = read_csv('SLOCs.csv') gp.set_bbox(BoundingBox(north=9, west=110, south=1, east=95)) gp.graph(Plotdata1, 'S_lat', 'S_lon', 'D_lat', 'D_lon', linewidth=2, color='Blues') gp.dot(Plotdata2, color='blue', point_size=3) gp.labels(Plotdata2, 'name', color='black', font_size=8, anchor_x='center') gp.tiles_provider('positron') gp.show()
def bbox(self): return BoundingBox(north=40.110222, west=115.924463, south=39.705711, east=116.803369)
""" Multiple examples of kernel density estimation visualization """ import geoplotlib from geoplotlib.utils import read_csv, BoundingBox, DataAccessObject data = read_csv('data/opencellid_dk.csv') #geoplotlib.kde(data, bw=5, cut_below=1e-4) # lowering clip_above changes the max value in the color scale #geoplotlib.kde(data, bw=5, cut_below=1e-4, clip_above=.1) # different bandwidths geoplotlib.kde(data, bw=20, cmap='OrRd', cut_below=1e-4) #geoplotlib.kde(data, bw=2, cmap='PuBuGn', cut_below=1e-4) # linear colorscale #geoplotlib.kde(data, bw=5, cmap='jet', cut_below=1e-4, scaling='lin') geoplotlib.set_bbox(BoundingBox.from_nominatim('CHINA')) geoplotlib.savefig('full.png') geoplotlib.show()
def bbox(self): return BoundingBox(north=9, west=110, south=1, east=95) #set boundingbox
def show_geoplot(results, mbc): data=DataAccessObject.from_dataframe(results[["lat","lon"]]) gpl.hist(data, colorscale='sqrt', binsize=4) gpl.kde(data, bw=5, cut_below=1e-3) gpl.set_bbox(BoundingBox(mbc[0],mbc[1],mbc[2],mbc[3])) gpl.show()
# If saving frames. if self.save_frames: GeoplotlibApp.screenshot(f'./results/animation_frames/{self.count}.png') if __name__ == '__main__': ### PARSE ARGUMENTS ### parser = argparse.ArgumentParser(description='Animate lists of edge lists.') parser.add_argument('--network-path', type=str, required=True, help='Path to the network corresponding to the edge list') parser.add_argument('--edgelist-path', type=str, required=True, help='Path to the edge list') parser.add_argument('--show-addresses', action='store_true', help='Show addresses corresponding to the nodes') parser.add_argument('--save-frames', action='store_true', help='Save animation frames') parser.add_argument('--line-width', type=float, default=1.3, help='Width of the lines representing the edges') args = parser.parse_args() ####################### # Parse network. network = nx.read_gpickle(args.network_path) # Parse edgelist. edgelists = np.load(args.edgelist_path, allow_pickle=True) # Add animation layer, set bounding box and show. geoplotlib.add_layer(AnimatedProcess(network, edgelists, show_addresses=args.show_addresses, save_frames=args.save_frames, line_width=args.line_width)) geoplotlib.set_bbox(BoundingBox(north=40.897994, west=-73.199040, south=40.595581, east=-74.55040)) geoplotlib.show()
def bbox(self): return BoundingBox.from_points(lons=np.hstack([self.data[self.src_lon], self.data[self.dest_lon]]), lats=np.hstack([self.data[self.src_lat], self.data[self.dest_lat]]))