Import geopandas as gpd from otting import save, figure from bokeh.models import GeoJSONDataSource addresses_fp = r'/home/geo/addresses.shp' roads_fp = r'/home/geo/roads.shp' # Read the data addresses = gpd. add_tools ( phover ) # Output filepath to HTML output_file = r"/home/geo/accessibility_map_Helsinki.html" # Save the map save ( p, output_file ) tooltips = ghover = HoverTool ( renderers = ) ghover. circle ( x =, y =, name = "point", size = 6, color = "yellow" ) # Add two separate hover tools for the data phover = HoverTool ( renderers = ) phover. orientation = "vertical" # Insert a circle on top of the Central Railway Station (coords in EurefFIN-TM35FIN) station_x = 385752.214 station_y = 6672143.803 circle = p. multi_line ( 'x', 'y', source = mdfsource, color = "red" ) # Modify legend location p. multi_line ( 'x', 'y', source = rdfsource, color = "grey" ) # Add metro m = p. patches ( 'x', 'y', source = dfsource, name = "grid", fill_color =, fill_alpha = 1.0, line_color = "black", line_width = 0.03, legend = "label_pt" ) # Add roads r = p. grid_line_color = None # Add polygon grid and a legend for it grid = p. reverse () color_mapper = LogColorMapper ( palette = palette ) p = figure ( title = "Travel times to Helsinki city center by public transportation", tools = TOOLS, plot_width = 650, plot_height = 500, active_scroll = "wheel_zoom" ) # Do not add grid line p. # Select only necessary columns for our plotting to keep the amount of data minumum df = data ] dfsource = ColumnDataSource ( data = df ) # Include only coordinates from roads (exclude 'geometry' column) rdf = roads ] rdfsource = ColumnDataSource ( data = rdf ) # Include only coordinates from metro (exclude 'geometry' column) mdf = metro ] mdfsource = ColumnDataSource ( data = mdf ) # Specify the tools that we want to use TOOLS = "pan,wheel_zoom,box_zoom,reset,save" # Flip the colors in color palette palette. Calculate the x and y coordinates of the grid.Now we can apply our functions and calculate the x and y coordinates of any kind of geometry by using the same function, i.e. geom_type # "Normal" geometries # - if gtype = "Point" : return getPointCoords ( geom, coord_type ) elif gtype = "LineString" : return list ( getLineCoords ( geom, coord_type ) ) elif gtype = "Polygon" : return list ( getPol圜oords ( geom, coord_type ) ) # Multi geometries # - else : return list ( multiGeomHandler ( geom, coord_type, gtype ) ) """ # Get geometry geom = row # Check the geometry type gtype = geom. concatenate () # Return the coordinates return coord_arrays def getCoords ( row, geom_col, coord_type ): """ Returns coordinates ('x' or 'y') of a geometry (Point, LineString or Polygon) as a list (if geometry is LineString or Polygon). concatenate () elif geom_type = "MultiPolygon" : coord_arrays = np. concatenate () elif geom_type = "MultiLineString" : coord_arrays = np. nan ) else : if geom_type = "MultiPoint" : coord_arrays = np. append ( getPol圜oords ( part, coord_type ), np. nan ) elif geom_type = "MultiPolygon" : coord_arrays = np. append ( getLineCoords ( part, coord_type ), np. nan ) elif geom_type = "MultiLineString" : coord_arrays = np. append ( getPointCoords ( part, coord_type ), np. # Bokeh documentation regarding the Multi-geometry issues can be found here (it is an open issue) # """ for i, part in enumerate ( multi_geometry ): # On the first part of the Multi-geometry initialize the coord_array (np.array) if i = 0 : if geom_type = "MultiPoint" : coord_arrays = np. Individual geometries are separated with np.nan which is how Bokeh wants them. Returns a list of coordinates where all parts of Multi-geometries are merged into a single list. Can be MultiPoint, MultiLineString or MultiPolygon. y def multiGeomHandler ( multi_geometry, coord_type, geom_type ): """ Function for handling multi-geometries. x elif coord_type = 'y' : return geometry. exterior return getXYCoords ( ext, coord_type ) def getLineCoords ( geometry, coord_type ): """ Returns Coordinates of Linestring object.""" return getXYCoords ( geometry, coord_type ) def getPointCoords ( geometry, coord_type ): """ Returns Coordinates of Point object.""" if coord_type = 'x' : return geometry. xy def getPol圜oords ( geometry, coord_type ): """ Returns Coordinates of Polygon using the Exterior of the Polygon.""" ext = geometry. xy elif coord_type = 'y' : return geometry. Used with LineString and Polygon geometries.""" if coord_type = 'x' : return geometry. Def getXYCoords ( geometry, coord_type ): """ Returns either x or y coordinates from geometry coordinate sequence.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |