Introduction to Jupyter Notebooks for Spatial Analysis¶
In this tutorial, we are going to be using the Jupyter Notebooks to analyse spatial data
Installing ArcGIS API for Python¶
Following the steps below, you will be able to install the API on your machine and get to work with this Rich Python Library for Spatial Data Science
Download Anaconda¶
- Navigate to Anaconda Website and get to downlaod the Anaconda application which is going to download all the python libraries and install Jupyter Notebooks which are much needed for this tutorial
- Run the installation file to install it on your machine
Run Commands¶
- click on the Start Menu,
- find Anaconda folder,
- click on it to expand it
- Right Click the Jupyter NoteBook icon and Open file location
- Right click on the Command Prompt and Run as Administrator
The command line tool will open and input the following code:
- installing the ArcGIS Python Libraries onto your machine
conda install -c esri arcgis
- Type y to accept the packages listed to install on your machine
- that’s it. Python API is installed
Open Jupyter NoteBooks¶
Now we need to start working and we just need to run one more command in the command prompt.
Type and run,
jupyter notebook
- the environment opens
- navigate to a Folder in which you want to work in
- create a Python 3 Notebook by clicking on New which is on the tool bar
- a new tab opens and you are ready to begin
CONGRATULATIONS ON YOUR FIRST STEP¶
Creating Maps & Adding Layers¶
Importing the Python Libraries into our project.
- call the ArcGIS library
- import the GIS capabilities
- declare a variable and assign the GIS Methods to it
from arcgis.gis import GIS
gis = GIS()
We just imported the ArcGIS API for Python by calling it from the arcgis library for the Python language.
Let’s create a simple map using a named location¶
- create a variable named map or any other name you might give it
- call the variable in order to display an out
If you do not call the variable after declaring it, then no output is displayed
map = gis.map("Africa")
map
Styling The Map¶
We can edit attributes like Centering and Zooming among others which we will touch on in future tutorials
map.center = [-19.0154, 29.1549]
map.zoom = 7
Get the JSON feedback for all available Basemaps to use within the map display
map.basemaps
Change the basemap to the original map.
Take note that the map variable is still the one in use and it will just change the map displayed above
map.basemap = 'dark-gray-vector'
Searching and Retrieving OpenData¶
- create a variable to store results
- define the search terms
- define the item types you want to search
- if you don’t want to flood your screen with results, define the maximum items to display
- call the variable to display the results
display_content = gis.content.search("Zimbabwe COVID-19", item_type="Feature Layer", max_items=10)
display_content
display the results in a pleasing way than just text format
Using the same variable declared above.
from IPython.display import display
for item in display_content:
display(item)
Adding Content to Map¶
poi = display_content
map.add_layer(poi)
Some Layers not added to the map, because they do not belong to us and for that we need access tokens which we can get in the ArcGIS Developers Dashboard meaning, if you haven’t already you need to create an account for that
You can view the full (31-minute tutorial) video on YouTube
[embedyt] https://www.youtube.com/watch?v=572QvhSUhmM[/embedyt]
Kumbirai is a GIS & MEAL specialist using geospatial analytics to advance global health and social impact. A certified Data Protection Officer (DPO), an open-data advocate and self-taught software developer, he builds web GIS tools that turn field data into decisions. He lectures in GIS/Remote Sensing and mentors emerging practitioners. Founder of a geospatial startup and nonprofit, he believes, “Real geospatial innovation happens when we empower communities with the right tools and knowledge.” Open to consulting and collaborations.