Skip to content

African Surveyors Connect | GeoConnect

The geospatial platform for visionaries and those who dare to dream

Menu
  • Posts
    • News
    • General
    • Educational
    • Spotlight
  • Jobs
  • Events
  • More
    • Learn-GIS
    • Magazine
    • Podcast
    • Academy
Menu

Introduction to ArcGIS API for Python

Posted on February 27, 2021 by KUMBIRAI MATINGO

 

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¶

Congratulations GIF


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
In [5]:
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

In [6]:
map = gis.map("Africa")
map

>> Your Map Depending On Your Chosen Location Will Appear Here <<

Styling The Map¶

We can edit attributes like Centering and Zooming among others which we will touch on in future tutorials

In [7]:
map.center = [-19.0154, 29.1549]
map.zoom = 7

Get the JSON feedback for all available Basemaps to use within the map display

In [8]:
map.basemaps
Out[8]:
['dark-gray',
 'dark-gray-vector',
 'gray',
 'gray-vector',
 'hybrid',
 'national-geographic',
 'oceans',
 'osm',
 'satellite',
 'streets',
 'streets-navigation-vector',
 'streets-night-vector',
 'streets-relief-vector',
 'streets-vector',
 'terrain',
 'topo',
 'topo-vector']

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

In [9]:
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
In [11]:
display_content = gis.content.search("Zimbabwe COVID-19", item_type="Feature Layer", max_items=10)
display_content
Out[11]:
[<Item title:"CASES IN ZIMBABWE" type:Feature Layer Collection owner:mohcccovid19>,
 <Item title:"SexDistrubution" type:Table Layer owner:surveyor_jr>,
 <Item title:"Vaccine Distribution Program" type:Feature Layer Collection owner:surveyor_jr>,
 <Item title:"CaseFatalityRateByAgeGroup" type:Table Layer owner:surveyor_jr>,
 <Item title:"CasesAndDeathsPerAgeGroup" type:Table Layer owner:surveyor_jr>,
 <Item title:"CASES IN ZIMBABWE" type:Feature Layer Collection owner:yona@esri_southernafrica>,
 <Item title:"POSITIVE CASES IN ZIMBABWE" type:Feature Layer Collection owner:yona@esri_southernafrica>,
 <Item title:"case_distribution_by_district_WFL1" type:Feature Layer Collection owner:surveyor_jr>]

display the results in a pleasing way than just text format

Using the same variable declared above.

In [12]:
from IPython.display import display 
for item in display_content:
    display(item)


CASES IN ZIMBABWE

Feature Layer Collection by mohcccovid19

Last Modified: April 14, 2020

0 comments, 23 views



SexDistrubution

Table Layer by surveyor_jr

Last Modified: December 07, 2020

0 comments, 4 views



Vaccine Distribution Program

A collection of the Coronavirus Vaccination roll-out and progress in ZimbabweFeature Layer Collection by surveyor_jr

Last Modified: February 18, 2021

0 comments, 345 views



CaseFatalityRateByAgeGroup

Table Layer by surveyor_jr

Last Modified: December 07, 2020

0 comments, 3 views



CasesAndDeathsPerAgeGroup

Table Layer by surveyor_jr

Last Modified: December 07, 2020

0 comments, 2 views



CASES IN ZIMBABWE

Feature Layer Collection by yona@esri_southernafrica

Last Modified: December 18, 2020

0 comments, 946 views



POSITIVE CASES IN ZIMBABWE

Feature Layer Collection by yona@esri_southernafrica

Last Modified: April 01, 2020

0 comments, 332 views



case_distribution_by_district_WFL1

Feature Layer Collection by surveyor_jr

Last Modified: January 31, 2021

0 comments, 154 views

Adding Content to Map¶

In [13]:
poi = display_content 
map.add_layer(poi)
Token Required
Token Required
(Error Code: 499)
Item.layers is a 'NoneType' object: nothing to be added to map
Token Required
Token Required
(Error Code: 499)
Token Required
Token Required
(Error Code: 499)
Item.layers is a 'NoneType' object: nothing to be added to map
Token Required
Token Required
(Error Code: 499)

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

In [ ]:
 
You can view the full (31-minute tutorial) video on YouTube 

[embedyt] https://www.youtube.com/watch?v=572QvhSUhmM[/embedyt]



KUMBIRAI MATINGO
KUMBIRAI MATINGO

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.

Share this:

  • Tweet
  • Click to share on Telegram (Opens in new window) Telegram
  • Click to share on WhatsApp (Opens in new window) WhatsApp
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to print (Opens in new window) Print

Related Articles You Might Like

Search for Articles

Latest Posts

  • Deploying a GeoDjango App on Heroku
  • The Truth About Self-Taught Skills No One Tells You
  • Transformative Mapping Event Launches in Chinhoyi: A Testament to Youth Engagement and Community Collaboration 
  • GeoConnect Awarded Grant for Transformative OpenStreetMap Project in Chinhoyi, Zimbabwe
  • Unlocking Data Treasure Troves: A Guide to Accessing Zimbabwe’s Geospatial Datasets

In today’s digital age, a website is the face of your brand, and having a well-designed and functional website is essential for businesses to succeed online. Our web development services combine creativity and technical expertise to build custom websites that not only look great but also deliver a seamless user experience across all devices.

From responsive design to e-commerce integration, our team of web developers has the skills and experience to bring your vision to life and help your business thrive in the online world. Let us help you create a website that showcases your brand and drives growth for your business. Get in touch via WhatsApp on +263-77-6-887-606 or send me an Email on matingonk@gmail.com

While we have renamed and re-branded to GeoConnect, we have dedicated this platform to continue our work in sharing and exchanging knowledge with the community that has helped us become what we are today.

The journey and legacy continues. Learn more about Geo-Connect.

Quick Links / Resources

  • Legal
  • About Us
© 2025 African Surveyors Connect | GeoConnect | Developed for the profession with support from KM-Spatial