Did you know you can directly edit and add vector data while analyzing and working it within a Jupyter-Notebook? That's right.
In most cases, people analyze data with interactive Notebooks and when it comes to making a few changes, Pandas is usually the tool for the job. This article reduces the amount of code one needs to write in order to manipulate vector data.
I will introduce a python package, leafmap.
Leafmap is a Python package for interactive mapping and geospatial analysis with minimal coding in a Jupyter environment.
The list of Geospatial libraries in Python is almost impossible to finish. A good thing is that most of them are usually open-source geospatial libraries.
You can check out my previous article on some of these packages just to get a glimpse.
Like most packages, you need to install them first. Without installation, it's like trying to drive a car without fuel👀.
Within your JupyterNotebook, within a cell type
!pip install leafmap and let the package install itself.
Some prefer or a familiar with Conda, you can run
conda install -c conda-forge leafmap in the terminal.
Once that has been executed successfully, Leafmap will also include all its dependencies, so if you are already running JupyterNotebooks for sometime, do not worry about the warning messages.
When the fuel is in, we need to tell our Jupyter Environment that we need to use our leafmap package.
To do that, we import leafmap like so;
from leafmap import leafmap
Let's create an interactive map now.
m = leafmap.Map(center=(-19.0154,29.1549), zoom=12) m.add_basemap() m
Let's add some vector data to our map. For this, we will use data in GeoJSON format from one of my Open-Data repositories.
We will grab the Zimbabwe Districts GeoJSON file for this visualization.
url = "https://raw.githubusercontent.com/Surveyor-Jr/Zimbabwe-Open-Data/main/adminstrative_boundaries/zimbabwe_districts.geojson" m.edit_vector(url)
This will add Edit privileges to the vector data already added within the notebook.
Use the drawing tools and once you are done, you can then save the result vector data with the code below.
my_vector is the folder to which you want to store your final outputs.
Hope this will help out in manipulating Vector data in a notebook environment.
You can also check out more information about the leafmap package.
Check out the source code for this article in the PyBlog repository.