Notice, we also need the ‘geoid’ column that we created earlier. Lets take it a bit further, by classifiying the population column again with Natural Breaks from PySAL.Ĭreate Choropleth map where the colors are now related to the column “pop_km2”. In : folium.LayerControl(collapsed=True).add_to(m) # create a basic choropleth map, just polygons with some style information # Notice: 'geoid' column that we created earlier needs to be assigned always as the first column # Create Choropleth map from the polygons where the colors are coming from a column "Population". In : m = folium.Map(location=, tiles='Stamen terrain', zoom_start=8, control_scale=True, prefer_canvas=True, width=600, height=450) You remember, the classic map with coloured polygons based on an attribute value. At first we want to make a choropleth map. So let’s prepare our visualisation step by step. The roads are barely visible, and the school point markers are fancy, but there are too many on top of each other. While we can see the geometries, shapes etc, it is not really a helpful map. In : folium.GeoJson(schools_jsontxt).add_to(m) In : folium.GeoJson(roads_jsontxt).add_to(m) In : folium.GeoJson(grid_jsontxt).add_to(m) In : m = folium.Map(location=, zoom_start=11, control_scale=True, prefer_canvas=True, width=600, height=450) Now we can start visualizing our data with Folium. variables as GeoJSON format which basically contains theĭata as text in a similar way that it would be written in a. Now we have our data stored in the grid_jsontxt etc. to_json () In : schools_jsontxt = schools. astype ( str ) # Select data In : grid = grid ] In : roads = roads ] In : schools = schools ] # convert the dataframe to geojson In : grid_jsontxt = grid. loc > 0 )] # Create a Geo-id which is needed by the Folium (it needs to have a unique identifier for each row) In : grid = grid. to_crs ( epsg = 4326 ) # Make a selection (only data above 0 and below 1000) In : grid = grid. to_crs ( epsg = 4326 ) In : schools = schools. to_crs ( epsg = 4326 ) In : roads = roads. read_file ( schools_fp ) # Re-project to WGS84, Folium requires all data to be in WGS84 In : grid = grid. read_file ( roads_fp ) In : schools = gpd. In : import geopandas as gpd In : from fiona.crs import from_epsg In : from shapely.geometry import LineString, MultiLineString # Filepaths In : grid_fp = "source/_static/data/L6/population_square_km.shp" In : roads_fp = "source/_static/data/L6/roads.shp" In : schools_fp = "source/_static/data/L6/schools_tartu.shp" # Read files In : grid = gpd. Alternative installation method for Conda environments.Installation and setup for Python with Miniconda.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |