Ejemplo n.º 1
0
 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()))
Ejemplo n.º 2
0
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()
Ejemplo n.º 4
0
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()
Ejemplo n.º 5
0
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 = {}
Ejemplo n.º 6
0
 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)
Ejemplo n.º 7
0
 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])
Ejemplo n.º 8
0
 def bbox(self):
     return BoundingBox(north=40.110222,
                        west=115.924463,
                        south=39.705711,
                        east=116.803369)
Ejemplo n.º 9
0
        
        # 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()

Ejemplo n.º 10
0
 def bbox(self):
     return BoundingBox(north=9, west=110, south=1, east=95) #set boundingbox
Ejemplo n.º 11
0
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()
Ejemplo n.º 12
0
 def bbox(self):
     return BoundingBox(north=37.801421,
                        west=-122.517339,
                        south=37.730097,
                        east=-122.424474)
Ejemplo n.º 13
0
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()