Jupyter GIS (JGIS) Mixin¶
What is Jupyter GIS Mixin?
The Jupyter GIS
mixin is responsible to deliver a way to explore your UrbanMapper's pipeline in a more
collaborative in real-time manner within your Jupyter Notebooks' workflow via the great JGIS.
See more about Jupyter GIS, in their documentation.
A mixin, in this very instance, is nothing more than a class that connects external libraries for their use
directly adapted towards the UrbanMapper
workflow.
Documentation Under Alpha Construction
This documentation is in its early stages and still being developed. The API may therefore change, and some parts might be incomplete or inaccurate.
Use at your own risk, and please report anything that seems incorrect
/ outdated
you find.
jupyter_gis
¶
InterpolationType
¶
Bases: Enum
Enumeration of interpolation types for layer styling.
Attributes:
Name | Type | Description |
---|---|---|
LINEAR |
str
|
Smooth transition between values. |
DISCRETE |
str
|
Step changes at threshold values. |
EXACT |
str
|
Only exact matches to specific values. |
Source code in src/urban_mapper/mixins/jupyter_gis.py
JupyterGisMixin
¶
Mixin for creating interactive geospatial visualisations using JupyterGIS
following a UrbanMapper pipeline
This mixin provides a fluent chaining-based methods interface for building interactive maps from
UrbanMapper pipeline
results and other geospatial data sources. It integrates
with the JupyterGIS library
to create rich, web-based map visualisations
directly in Jupyter notebooks navigatable together and in real-time.
Examples:
>>> from urban_mapper import UrbanMapper
>>>
>>> # Initialise UrbanMapper
>>> mapper = UrbanMapper()
>>>
>>> # Have a UrbanPipeline ready in a variable `pipeline`.
>>>
>>> # Create a styling configuration
>>> style = LayerStyle(
... attribute="passenger_count",
... stops={1: [0, 0, 255, 1.0], 4: [255, 0, 0, 1.0]},
... interpolation_type="linear"
... )
>>>
>>> # Create and display an interactive map
>>> _, doc = mapper.jupyter_gis.with_pipeline(
... pipeline=pipeline,
... layer_name="Taxi Trips",
... layer_style=style,
... opacity=0.8
... ).with_document_settings(
... title="Brooklyn Taxi Trips",
... zoom=12
... ).build()
>>>
>>> # Display the map
>>> doc
Source code in src/urban_mapper/mixins/jupyter_gis.py
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 |
|
build()
¶
Build the interactive map from all configured components.
This method creates a JupyterGIS
document from all the configured
pipelines
, layers
, and settings
, and returns it for display.
Returns:
Type | Description |
---|---|
Tuple[JupyterGisMixin, GISDocument]: A tuple containing:
|
Raises:
Type | Description |
---|---|
ValueError
|
If a pipeline's geometry type is not supported or if the styling configuration is invalid. |
JGIS is a build from scratch type of library
- If no base map (raster layer) is added, a default dark basemap will be used
- If no map extent is specified, it will be calculated automatically from the combined bounds of all pipeline layers
JGIS Is In Its Early Stages
We recommend looking into their documentation in case of something not going as expected. If something is outdated, feel free to open an issue on our GitHub repository.
Examples:
>>> # Build the map after configuring all components
>>> _, doc = mapper.jupyter_gis ... .with_pipeline(pipeline=taxi_pipeline, layer_name="Taxi Trips", layer_style=style) ... .with_document_settings(title="NYC Urban Analysis") ... .build()
>>>
>>> # Display the map in the notebook
>>> doc
Source code in src/urban_mapper/mixins/jupyter_gis.py
730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 |
|
save(filepath)
¶
Save the interactive map to a JGIS-based file
JGIS Is In Its Early Stages
We recommend looking into their documentation in case of something not going as expected. If something is outdated, feel free to open an issue on our GitHub repository.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filepath
|
str
|
The path where the JGIS file should be saved. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If build() hasn't been called yet. |
Examples:
>>> # Build the map and save it to a file
>>> mapper.jupyter_gis ... .with_pipeline(pipeline=taxi_pipeline, layer_name="Taxi Trips", layer_style=style) ... .build()[0] ... .save("taxi_map.JGIS")
Source code in src/urban_mapper/mixins/jupyter_gis.py
with_document_settings(**settings)
¶
Configure settings for the JupyterGIS
document.
This method allows setting various properties of the map document, such as
title
, zoom level
, and initial extent
.
JGIS Is In Its Early Stages
We recommend looking into their documentation in case of something not going as expected. If something is outdated, feel free to open an issue on our GitHub repository.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**settings
|
Any
|
Keyword arguments for document settings. Common settings include: - title (str): The title of the map document. - zoom (int): The initial zoom level of the map. - extent (List[float]): The initial extent of the map [min_lon, min_lat, max_lon, max_lat]. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
JupyterGisMixin |
JupyterGisMixin
|
The mixin instance for method chaining. |
Examples:
>>> gis_map = mapper.jupyter_gis.with_document_settings(
... title="Urban Analysis Map",
... zoom=14,
... extent=[-74.01, 40.71, -73.99, 40.73]
... )
Source code in src/urban_mapper/mixins/jupyter_gis.py
with_filter(layer_id, logical_op, feature, operator, value)
¶
Add a filter to a layer based on a condition.
Filters allow you to control which features are displayed on the map based on their attributes.
JGIS Is In Its Early Stages
We recommend looking into their documentation in case of something not going as expected. If something is outdated, feel free to open an issue on our GitHub repository.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
layer_id
|
str
|
The ID of the layer to apply the filter to. |
required |
logical_op
|
str
|
The logical operator to use for combining filters (e.g., "and", "or"). |
required |
feature
|
str
|
The feature attribute to filter on. |
required |
operator
|
str
|
The comparison operator (e.g., "==", ">", "<"). |
required |
value
|
Union[str, int, float]
|
The value to compare against. |
required |
Returns:
Name | Type | Description |
---|---|---|
JupyterGisMixin |
JupyterGisMixin
|
The mixin instance for method chaining. |
Examples:
>>> gis_map = mapper.jupyter_gis.with_filter(
... layer_id="Taxi Trips",
... logical_op="and",
... feature="passenger_count",
... operator=">",
... value=3
... )
Source code in src/urban_mapper/mixins/jupyter_gis.py
with_heatmap_layer(feature, path=None, data=None, name='Heatmap Layer', opacity=1.0, blur=15, radius=8, gradient=None)
¶
Add a heatmap layer to the map.
Heatmap layers visualise the density of points or other features.
JGIS Is In Its Early Stages
We recommend looking into their documentation in case of something not going as expected. If something is outdated, feel free to open an issue on our GitHub repository.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
feature
|
str
|
The feature to visualise in the heatmap. |
required |
path
|
Optional[str]
|
Path to the data source. Defaults to None. |
None
|
data
|
Optional[Dict]
|
Data for the heatmap. Defaults to None. |
None
|
name
|
str
|
The name of the layer. Defaults to "Heatmap Layer". |
'Heatmap Layer'
|
opacity
|
float
|
The opacity of the layer (0.0 to 1.0). Defaults to 1.0. |
1.0
|
blur
|
int
|
The blur radius for the heatmap. Defaults to 15. |
15
|
radius
|
int
|
The radius of influence for each point. Defaults to 8. |
8
|
gradient
|
Optional[List[str]]
|
The colour gradient for the heatmap. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
JupyterGisMixin |
JupyterGisMixin
|
The mixin instance for method chaining. |
Examples:
>>> gis_map = mapper.jupyter_gis.with_heatmap_layer(
... feature="pickup_locations",
... path="path/to/data.geojson",
... name="Pickup Heatmap",
... blur=10,
... radius=5
... )
Source code in src/urban_mapper/mixins/jupyter_gis.py
with_hillshade_layer(url, name='Hillshade Layer', urlParameters=None, attribution='')
¶
Add a hillshade layer to the map.
Hillshade layers provide a shaded relief effect based on elevation data.
JGIS Is In Its Early Stages
We recommend looking into their documentation in case of something not going as expected. If something is outdated, feel free to open an issue on our GitHub repository.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url
|
str
|
The URL of the hillshade data. |
required |
name
|
str
|
The name of the layer. Defaults to "Hillshade Layer". |
'Hillshade Layer'
|
urlParameters
|
Optional[Dict]
|
Additional parameters for the URL. Defaults to None. |
None
|
attribution
|
str
|
Attribution text for the layer. Defaults to "". |
''
|
Returns:
Name | Type | Description |
---|---|---|
JupyterGisMixin |
JupyterGisMixin
|
The mixin instance for method chaining. |
Examples:
>>> gis_map = mapper.jupyter_gis.with_hillshade_layer(
... url="path/to/hillshade.tif",
... name="Elevation Hillshade"
... )
Source code in src/urban_mapper/mixins/jupyter_gis.py
with_image_layer(url, coordinates, name='Image Layer', opacity=1.0)
¶
Add an image layer to the map.
Image layers are used to display georeferenced images on the map.
JGIS Is In Its Early Stages
We recommend looking into their documentation in case of something not going as expected. If something is outdated, feel free to open an issue on our GitHub repository.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url
|
str
|
The URL of the image. |
required |
coordinates
|
List[List[float]]
|
The coordinates defining the image's position. |
required |
name
|
str
|
The name of the layer. Defaults to "Image Layer". |
'Image Layer'
|
opacity
|
float
|
The opacity of the layer (0.0 to 1.0). Defaults to 1.0. |
1.0
|
Returns:
Name | Type | Description |
---|---|---|
JupyterGisMixin |
JupyterGisMixin
|
The mixin instance for method chaining. |
Examples:
>>> gis_map = mapper.jupyter_gis.with_image_layer(
... url="path/to/image.png",
... coordinates=[[min_lon, min_lat], [max_lon, max_lat]],
... name="Aerial Imagery"
... )
Source code in src/urban_mapper/mixins/jupyter_gis.py
with_pipeline(pipeline, layer_name, layer_style, opacity=1.0, type=None)
¶
Add an UrbanMapper pipeline
result as a styled layer on the map.
This method takes an UrbanMapper pipeline
and its styling configuration
and adds the pipeline's urban layer as a layer on the interactive map.
Urban Pipeline as an object, yet also as a file path
Note that the pipeline can be passed as an UrbanPipeline
object or as a file path to a saved / received
/ downloaded pipeline.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pipeline
|
Union[str, Any]
|
Either an |
required |
layer_name
|
str
|
The name to display for this layer in the map legend. |
required |
layer_style
|
LayerStyle
|
A LayerStyle object defining how to style the features based on attributes. |
required |
opacity
|
float
|
The opacity of the layer (0.0 to 1.0). Defaults to 1.0. |
1.0
|
type
|
Optional[str]
|
Override the automatic layer type detection with a specific type ("circle", "line", or "fill"). If not provided, the type will be determined based on the geometry type of the features. |
None
|
Returns:
Name | Type | Description |
---|---|---|
JupyterGisMixin |
The mixin instance for method chaining. |
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If pipeline is a string path that doesn't exist. |
ValueError
|
If pipeline is not a valid |
Examples:
>>> # Style based on a numeric attribute with colour gradient
>>> style = LayerStyle(
... attribute="trip_count",
... stops={0: [0, 0, 255, 1.0], 100: [255, 0, 0, 1.0]},
... interpolation_type="linear"
... )
>>>
>>> # Add the pipeline result as a map layer
>>> gis_map = mapper.jupyter_gis.with_pipeline(
... pipeline=my_pipeline,
... layer_name="Taxi Trip Destinations",
... layer_style=style,
... opacity=0.7
... )
Source code in src/urban_mapper/mixins/jupyter_gis.py
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 |
|
with_raster_layer(url, name='Raster Layer', attribution='', opacity=1.0)
¶
Add a raster layer to the map.
Raster layers are typically used for base maps or background imagery.
JGIS Is In Its Early Stages
We recommend looking into their documentation in case of something not going as expected. If something is outdated, feel free to open an issue on our GitHub repository.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url
|
str
|
The URL of the raster tiles. |
required |
name
|
str
|
The name of the layer. Defaults to "Raster Layer". |
'Raster Layer'
|
attribution
|
str
|
Attribution text for the layer. Defaults to "". |
''
|
opacity
|
float
|
The opacity of the layer (0.0 to 1.0). Defaults to 1.0. |
1.0
|
Returns:
Name | Type | Description |
---|---|---|
JupyterGisMixin |
JupyterGisMixin
|
The mixin instance for method chaining. |
Examples:
>>> gis_map = mapper.jupyter_gis.with_raster_layer(
... url="https://tile.openstreetmap.org/{z}/{x}/{y}.png",
... name="OpenStreetMap",
... attribution="Β© OpenStreetMap contributors"
... )
Source code in src/urban_mapper/mixins/jupyter_gis.py
with_tiff_layer(url, min=None, max=None, name='Tiff Layer', normalize=True, wrapX=False, attribution='', opacity=1.0, color_expr=None)
¶
Add a TIFF layer to the map.
TIFF layers are used for displaying georeferenced raster data.
JGIS Is In Its Early Stages
We recommend looking into their documentation in case of something not going as expected. If something is outdated, feel free to open an issue on our GitHub repository.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url
|
str
|
The URL of the TIFF file. |
required |
min
|
Optional[int]
|
Minimum value for scaling. Defaults to None. |
None
|
max
|
Optional[int]
|
Maximum value for scaling. Defaults to None. |
None
|
name
|
str
|
The name of the layer. Defaults to "Tiff Layer". |
'Tiff Layer'
|
normalize
|
bool
|
Whether to normalise the data. Defaults to True. |
True
|
wrapX
|
bool
|
Whether to wrap the X coordinate. Defaults to False. |
False
|
attribution
|
str
|
Attribution text for the layer. Defaults to "". |
''
|
opacity
|
float
|
The opacity of the layer (0.0 to 1.0). Defaults to 1.0. |
1.0
|
colour_expr
|
Optional[Any]
|
Colour expression for styling. Defaults to None. |
required |
Returns:
Name | Type | Description |
---|---|---|
JupyterGisMixin |
JupyterGisMixin
|
The mixin instance for method chaining. |
Examples:
>>> gis_map = mapper.jupyter_gis.with_tiff_layer(
... url="path/to/raster.tif",
... name="Elevation Data",
... min=0,
... max=255
... )
Source code in src/urban_mapper/mixins/jupyter_gis.py
LayerStyle
¶
Style configuration for map layers in JupyterGIS.
This class defines how features in a geographic layer should be styled based on attribute values. It supports various interpolation types and styling options like colour gradients and numeric value ranges.
Attributes:
Name | Type | Description |
---|---|---|
attribute |
str
|
The feature attribute to style based on (e.g., "population", "trip_count"). |
stops |
Union[Dict[Union[float, str], Union[List[float], float]], List[Tuple[Union[float, str], Union[List[float], float]]]]
|
The mapping of attribute values to style values (colours or numeric values). For colours, use [r, g, b, a] format with RGB values in range 0-255 and alpha 0-1. |
interpolation_type |
str
|
The type of interpolation to use:
|
default_value |
Optional[Union[List[float], float]]
|
The fallback value to use when no conditions match. Required for "discrete" and "exact" interpolation types. |
Examples:
>>> # Linear colour gradient based on population
>>> style = LayerStyle(
... attribute="population",
... stops={0: [240, 240, 240, 1.0], 1000000: [0, 0, 255, 1.0]},
... interpolation_type="linear"
... )
>>>
>>> # Discrete categories for land use types
>>> style = LayerStyle(
... attribute="land_use",
... stops={"residential": [255, 0, 0, 1.0], "commercial": [0, 0, 255, 1.0]},
... interpolation_type="exact",
... default_value=[100, 100, 100, 1.0] # Grey for other categories
... )
Source code in src/urban_mapper/mixins/jupyter_gis.py
create_style_expression(style_property, attribute, interpolation_type, stops, default_value=None)
¶
Create a style expression for a given style property based on an attribute.
This function generates a style expression that can be used in map layers to dynamically style features based on their attribute values. It supports different interpolation types to handle how the styling transitions between defined stops.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
style_property
|
str
|
The style property to apply the expression to (e.g., 'stroke-colour', 'circle-radius'). |
required |
attribute
|
str
|
The feature attribute to base the styling on (e.g., 'pickup_count'). |
required |
interpolation_type
|
InterpolationType
|
The type of interpolation: LINEAR, DISCRETE, or EXACT. |
required |
stops
|
Union[Dict[Union[float, str], Union[List[float], float]], List[Tuple[Union[float, str], Union[List[float], float]]]]
|
A dictionary or list of tuples mapping attribute values to style values (colours as [r, g, b, a] or numbers). |
required |
default_value
|
Optional[Union[List[float], float]]
|
A fallback value if no conditions match (required for DISCRETE and EXACT). Defaults to None. |
None
|
Returns:
Type | Description |
---|---|
Dict[str, List]
|
Dict[str, List]: A dictionary containing the style expression for the specified property. |
Raises:
Type | Description |
---|---|
ValueError
|
If the provided parameters are invalid or incompatible with the interpolation type. |
Examples:
>>> # Linear interpolation for 'fill-colour'
>>> stops = {0.0: [0, 255, 255, 1.0], 100.0: [255, 165, 0, 1.0]}
>>> expr = create_style_expression("fill-colour", "count", InterpolationType.LINEAR, stops)
>>> # Result: {'fill-colour': ['interpolate', ['linear'], ['get', 'count'], 0.0, [0, 255, 255, 1.0], 100.0, [255, 165, 0, 1.0]]}
>>> # Discrete interpolation for 'stroke-colour'
>>> stops = [(50.0, [173, 216, 230, 1.0]), (200.0, [255, 255, 0, 1.0])]
>>> expr = create_style_expression("stroke-colour", "value", InterpolationType.DISCRETE, stops, [64, 64, 64, 1.0])
>>> # Result: {'stroke-colour': ['case', ['<=', ['get', 'value'], 50.0], [173, 216, 230, 1.0], ['<=', ['get', 'value'], 200.0], [255, 255, 0, 1.0], [64, 64, 64, 1.0]]}
>>> # Exact matching for 'circle-radius'
>>> stops = {1.0: 5.0, 2.0: 10.0}
>>> expr = create_style_expression("circle-radius", "id", InterpolationType.EXACT, stops, 2.0)
>>> # Result: {'circle-radius': ['case', ['==', ['get', 'id'], 1.0], 5.0, ['==', ['get', 'id'], 2.0], 10.0, 2.0]}
Source code in src/urban_mapper/mixins/jupyter_gis.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
|