One Pipeline in JGIS¶
Collision Analysis In JGIS¶
In this notebook, we assume that you went through all of the Basics
examples at the very least. The following showcases a Urban Pipeline about collisions
(motor vehicles) in Downtown Brooklyn New York City
, in the United States, added straight into Jupyter GIS for collaborative exploration of the pipeline
Data source:
More readings:
from urban_mapper import UrbanMapper
from urban_mapper.mixins.jupyter_gis import LayerStyle
Initialise UrbanMapper¶
We start by initialising the UrbanMapper object, which will serve as the foundation for building our data pipelines and visualisations.
um = UrbanMapper()
Reusing the Collision Pipeline¶
This section utilises the collision pipeline previously saved from the notebook located at:
examples/Study Cases/Downtown BK Collisions Study/[4]Downtown_BK_Collisions_Advanced_Pipeline_Extras.ipynb
Alternatively, you may reuse one of the following pipelines:
examples/Study Cases/Downtown BK Collisions Study/[3]Downtown_BK_Collisions_Advanced_Pipeline.ipynb
examples/Study Cases/Downtown BK Collisions Study/[2]Downtown_BK_Collisions_Pipeline.ipynb
Instructions¶
To reuse a pipeline:
- Open and execute the desired notebook.
- Invoke the
save
method on the composed pipeline object. - This will generate a serialised file (e.g.,
name_of_pipeline.dill
) containing the pipeline for later use, such as in this next cell.
Note¶
You also can create your pipline straight here in this jupyter notebook then pass it into the pipeline
parameter of .with_pipeline(.)
introduced afterward without any issue. .with_pipeline(.)
deals with 1) pipeline saved, pipeline non-composed and pipeline already composed under the hood for you.
Here we show via an already-saved pipeline to gain time and show how fast it is.
Enjoy working with the pipeline!
Define Visualisation Style for Collisions¶
To make the map visually informative, we define a style for the collision data. The color gradient ranges from yellow (fewer collisions) to dark red (many collisions), based on the collision_count
attribute.
collision_style = LayerStyle(
attribute="collision_count",
stops={
50: [255, 255, 0, 1], # Yellow
200: [255, 215, 0, 1], # Gold
500: [255, 165, 0, 1], # Orange
1500: [255, 0, 0, 1], # Red
3000: [139, 0, 0, 1] # Dark red
},
interpolation_type="discrete",
default_value=[0, 0, 0, 1]
)
Create the Interactive Map¶
We use Jupyter GIS to create an interactive map. This includes:
- A dark base map from CartoDB. (Optional, not needed as we default this anyway.
- The collision layer styled as circles, with opacity set to 0.7 for visibility.
The map is set to a zoom level of 15 and uses the EPSG:4326 projection.
jgis_analysis, jgis_doc = (
um.jupyter_gis.with_document_settings(
zoom=15,
latitude=40.6961,
longitude=-73.9845,
)
.with_raster_layer(
url="http://basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png",
name="Dark Base Map",
attribution="© OpenStreetMap contributors",
opacity=0.9
)
.with_pipeline(
pipeline="<path_to>/collisions_advanced_pipeline.dill",
layer_name="Collision Hotspots",
layer_style=collision_style,
opacity=0.7,
type="circle"
)
.build()
)
Save the Map¶
Finally, we save the interactive map as a .jGIS
file, which can be reopened or shared for further exploration.
DISCLAIMER: A file on the left will be created. Make sure to open it, and tada!
In the meantime, you can play with the jgis_doc
directly in this notebook if of interest too!
jgis_analysis.save("collision_analysis.jGIS")