1. Getting Started with Leafmap#
1.1. Introduction#
Welcome to the world of geospatial data science! In this chapter, we will introduce the leafmap Python package for interactive visualization and analysis of geospatial data. We will demonstrate how to use it to create interactive maps using different mapping backends and change basemaps interactively. We will also show you how to use leafmap with various cloud-computing platforms, including Google Colab, Amazon SageMaker Studio Lab, and Microsoft Planetary Computer.
1.2. Geospatial data science#
1.3. Introducing leafmap#
1.4. Key features#
1.5. Installing leafmap#
1.5.1. Installing with conda#
conda create -n geo python
conda activate geo
conda install -c conda-forge mamba
mamba install -c conda-forge leafmap
mamba install -c conda-forge pygis
1.5.2. Installing with pip#
pip install leafmap
1.5.3. Installing from source#
git clone https://github.com/opengeos/leafmap
cd leafmap
pip install .
pip install git+https://github.com/opengeos/leafmap
1.5.4. Upgrading leafmap#
pip install -U leafmap
conda update -c conda-forge leafmap
import leafmap
leafmap.update_package()
1.5.5. Using Docker#
docker run -it -p 8888:8888 giswqs/leafmap:latest
1.6. JupyterLab#
conda activate geo
jupyter lab
import leafmap
m = leafmap.Map()
m
1.7. Google Colab#
%pip install leafmap
import leafmap
m = leafmap.Map()
m
1.8. Amazon SageMaker Studio Lab#
!conda install -c conda-forge leafmap -y
import leafmap
m = leafmap.Map()
m
1.9. Microsoft Planetary Computer#
!mamba update -c conda-forge leafmap -y
import leafmap
m = leafmap.Map()
m
1.10. Mapping backends#
mamba install -c conda-forge pygis
1.10.1. Ipyleaflet#
import leafmap
m = leafmap.Map(center=[37.75, -122.43], zoom=12, height='550px')
m
m = leafmap.Map(toolbar_control=False, draw_control=False)
m
m.clear_controls()
m
m.to_html("map.html", title="My Map", width="100%", height="800px")
1.10.2. Folium#
import leafmap.foliumap as leafmap
m = leafmap.Map(center=[37.75, -122.43], zoom=12, height='500px')
m
m.to_html('folium.html')
1.10.3. Bokeh#
import leafmap.bokehmap as leafmap
m = leafmap.Map(center=[40, -100], zoom=4, height=400)
m
1.10.4. Plotly#
import leafmap.plotlymap as leafmap
m = leafmap.Map(center=[20, 0], zoom=1, height=400)
m
# leafmap.fix_widget_error()
1.10.5. Pydeck#
import leafmap.deck as leafmap
m = leafmap.Map(center=[20, 0], zoom=1)
m
1.10.6. KeplerGL#
import leafmap.kepler as leafmap
m = leafmap.Map(center=[20, 0], zoom=1)
m
1.11. Adding basemaps#
1.11.1. Built-in basemaps#
import leafmap
m = leafmap.Map(basemap='OpenTopoMap')
m
m.add_basemap('Stamen.Terrain')
for basemap in leafmap.basemaps.keys():
print(basemap)
len(leafmap.basemaps)
1.11.2. XYZ tiles#
m = leafmap.Map(center=[40, -100], zoom=4)
m.add_tile_layer(
url="https://a.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png",
name="OpenStreetMap.HOT",
attribution="OpenStreetMap",
)
m
1.11.3. WMS tiles#
m = leafmap.Map(center=[40, -100], zoom=4, height='500px')
url = 'https://imagery.nationalmap.gov/arcgis/services/USGSNAIPPlus/ImageServer/WMSServer?'
m.add_wms_layer(
url=url,
layers='USGSNAIPPlus:NaturalColor',
name='NAIP',
format='image/png',
attribution='USGS',
transparent=True,
)
m