Fall 2017

Harness the Power of GIS with the ArcGIS API for Python

This article as a PDF.


The ArcGIS API for Python is a new Python library for working with maps and geospatial data that is powered by Web GIS, whether online or on-premises. It is a Pythonic API that uses Python best practices in its design and employs standard Python constructs and data structures with clean, readable idioms.

The ArcGIS API for Python allows you to perform sophisticated spatial analysis as well as administer and manage the components of your Web GIS.

Use this API to work with your data and access ready-to-use maps and curated geographic data from Esri and other authoritative sources. It has simple and efficient tools for sophisticated vector and raster analysis, geocoding, mapmaking, routing, and generating directions, as well as for organizing and managing the users, groups, and content associated with an organization’s Web GIS.

Because the Python language is developed under an open-source license, it is freely usable and distributable. The ArcGIS API for Python is also free. Both Python and the API can be installed on any number of machines, whether local computers or servers. The lightweight Python API is distributed through Conda, a popular package manager for Python libraries. It works well with open-source Python libraries, such as pandas, SciPy, and NumPy, and machine learning packages.

The Python API is intuitive and easy to learn and designed to lower the barrier of entry to both GIS and programming. It benefits experienced Python developers who want to quickly get started with GIS and seasoned GIS professionals who want to automate administrative tasks and perform analyses.

No matter what your role, objectives, or tasks, this API offers functionality that you can use. Through the Python API, you can harness the full power of your GIS to script and automate processes. This aspect of the API may remind longtime GIS users of the ARC Macro Language (AML) or the Avenue scripting language used with earlier versions of Esri GIS software.

Manage Your GIS Efficiently

The gis module, in light green, provides the entry point into the GIS. Other modules in green are used to access spatial capabilities or geographic datasets in the GIS and include geoprocessing functions, types, and other helper objects for working with spatial data of a particular type. Blue modules provide additional functionality for workflows and include the geocoding, geometry, and geoprocessing modules. Orange modules are used to visualize GIS data and analysis and include the MapView Jupyter Notebook widget for visualizing maps and layers. The Mapping module shown in orange has types and functions for working with web maps and web layers.

GIS administrators or developer operations engineers can use the API to quickly automate the process of creating an organization in ArcGIS Enterprise or ArcGIS Online. User accounts can be batch created using a CSV file to assign roles to users and users to groups. Seed content can be published and assigned to each user. The API can be used to set up mirrors of the organization’s portal so one can be used for development and the other for production. The process of cloning the portal and keeping content, groups, and users synchronized can be efficiently scripted.

Automating day-to-day administrative tasks can save lots of time and effort. Listing all items belonging to a user, searching for content based on a particular criterion, listing content published before a specific date, creating a new user account for new group members, removing user accounts and their content when members leave, and sorting items based on their popularity are a few of the tasks that can be scripted.

With a few lines of code, easily manage important tasks such as assigning licenses and entitlements to various ArcGIS apps, managing and monitoring ArcGIS Online credits, or migrating content from one user to another. The API provides rich features for querying server and portal logs and monitoring their health through usage metrics and statistics. Easily create charts of these statistics to identify choke points and optimize operations.

Use the API to publish and share web layers and web maps or list maps or scenes with broken links to layers and fix them. Keep content up to date through editing or overwriting web layers and schedule those tasks to run periodically during off-peak hours.

Use the Analytical Capabilities of GIS

Perform exploratory data analysis in Jupyter Notebook using the Python API.

Data scientists and GIS analysts can harness the full power of the rich analytical tools available in ArcGIS by not only executing spatial analyses but also performing distributed processing on big data by calling GeoAnalytics functionality and distributed raster analysis tools available with ArcGIS Enterprise. It can also perform geocoding and routing analyses and employ custom tools that have been exposed as geoprocessing web tasks.

Power users who know a lot about Web GIS, use it every day, and want to become more efficient by automating workflows can really benefit from the ArcGIS API for Python. The very readable and flexible Python language is well suited to new programmers. Conversely, Python programmers who are not very experienced with GIS will find that the ArcGIS API for Python provides a gentle introduction to the concepts of a modern GIS through its simple and intuitive design.

How the API Is Structured

Perform routing and directions analysis using the Python API in Jupyter Notebook.

The elegant and modular design of the ArcGIS API for Python was built after studying and reflecting on other popular, well-designed Python APIs. It has been perfected through multiple initial iterations. At its core is the gis module, which provides an entry point to a Web GIS with a rich set of classes to search, monitor, and administer it. Other modules represent different aspects of the Web GIS platform.

The features module works with vector data in the form of feature layers or collections of feature layers hosted by the GIS. Analysis tools can be applied to this vector data to summarize data, analyze patterns, perform spatial enrichment, or perform proximity analysis using just a few lines of code. This module is tightly integrated with pandas, a Python library for data analysis, so the feature data can be queried into a pandas DataFrame object.

Pandas by itself provides a powerful set of analytical tools, and its integration with countless plotting and machine learning libraries means every ArcGIS API for Python user can not only use the tools available in ArcGIS but also the whole data science ecosystem that is built around Python. The API works well with other popular data science libraries such as the SciPy stack and scikit-learn. The 1.2 version of the API introduced SpatialDataFrames, which spatially extended the DataFrame object and allows importing and exporting of a greater variety of geospatial data; performing spatial queries and joins; and working with data in a “pandorable” manner.

The raster module provides a new way of working with imagery and raster datasets. The API allows raster analysis in an elegant and concise manner by exposing powerful, dynamic raster functions as native Python functions. For the first time, map algebra can be performed on Web GIS and processed at source resolution using the distributed raster analysis capability available from ArcGIS Image Server.

The geoanalytics module exposes a series of big data analytical tools. Once data is registered with the GeoAnalytics Server, the API can be used to aggregate and analyze it and even schedule scripts to run so that as new data comes into the system, it can be periodically analyzed. With the geocoding and network modules, address and point of interest (POI) information can be turned into spatial data and used in routing and direction analysis.

The realtime module enables work with streaming data. The geoprocessing module helps execute custom web tasks published as geoprocessing services. The geometry module provides the geometric representation of feature data that can be built using raw coordinates. Author and edit web maps and scenes using the mapping module. It works hand in hand with the widgets module, which provides interactive map and scene widgets that can be embedded in a Jupyter Notebook for visualizing GIS content. (For more information on using Jupyter Notebook with the ArcGIS API for Python, see the accompanying article, “A Whole New Way to Experience GIS.”) The API provides a seamless experience because as you search for content or perform a spatial analysis task, it returns appropriate classes from different modules.

So Many Resources for Getting Started

All the information you need to start using this API—installation information, helpful guides, and getting started exercises presented in Jupyter Notebook format—is available at developers.arcgis.com/python. Case studies in Jupyter Notebook format explain how the various modules of the API can be put together to solve problems from an applications point of view. The Forum tab on the website will take you to the ArcGIS API for Python Group on GeoNet, Esri’s question and answer network. All the guide chapters and samples from the website and talks delivered by the development team at various conferences are available in Jupyter Notebook format on GitHub at github.com/esri/arcgis-python-api.

One of the easiest ways to get started with the ArcGIS API for Python is to try it out live in the sandbox environment at notebooks.esri.com. Make sure to download any work because the site resets after you leave it. You can also download the samples from GitHub and run them locally.

Conclusion

The ArcGIS API for Python enables the use of a simple, expressive language that everyone—not just developers—can learn and use to work more efficiently by scripting and automating workflows and performing analyses. It not only exposes the rich analytical capabilities that are built in the ArcGIS platform but also integrates very well with the scientific Python ecosystem and includes rich support for pandas and Jupyter Notebook.