Create Vector Data Interactively
This notebook demonstrates how to create vector data interactively using the leafmap
Python package.
Uncomment the following line to install leafmap if needed.
# %pip install "leafmap[maplibre]"
Import libraries.
import os
import leafmap.maplibregl as leafmap
To use Mapillary street level imagery, you will need to sign up for a free account at Mapillary and get an access token. Please visit the Mapillary API page for more information on how to get an access token.
Once you have an access token, uncomment the following line and replace YOUR_ACCESS_TOKEN
with your actual access token.
# os.environ["MAPILLARY_API_KEY"] = "YOUR_ACCESS_TOKEN"
Create an interactive map.
m = leafmap.Map(center=[-74.1935, 40.6681], zoom=15, style="liberty")
m.add_basemap("Satellite")
m.add_mapillary()
m.add_layer_control()
m.add_draw_control(
controls=["point", "polygon", "line_string", "trash"], position="top-right"
)
Set up default parameters for drawn features.
properties = {
"Type": ["Residential", "Commercial", "Industrial"],
"Area": 3000,
"Name": "Building",
"City": "New York",
}
Display the map.
widget = leafmap.create_vector_data(
m, properties, file_ext="geojson", add_mapillary=True
)
widget
Use the drawing tools to create vector data interactively on the map. Change the properties of the drawn features as needed. Click on the Save button to save the properties of the drawn features. Once you are done, click on the Export button to export the drawn features to a GeoJSON file.