Working with GIS Data using Python

| |


Scripting and programming languages leverage most of the problem-solving in science; spatial science is not an exception to this. As a high-level programming language, python brings a lot of flexibility and features to deploy in GIS.  Its usage as a scripting language enables automation of certain functionalities within another program (e.g. arcpy for ArcGIS).   Therefore, it is not a surprise that it is the most widely used language in spatial science.  It is easy to use due to its simple syntax, and power as an object-oriented language.  You don’t need to have the specialist knowledge of programming since it hides much of the technical details that system programming languages need to handle.  The most outstanding application possibilities of python in spatial science can be discussed under spatial data handling, spatial data analysis, and spatial data visualization.

Spatial Data Handling

Without any question, data is the core of any GIS project. Thanks to the new developments in the technology and computational science, data acquisition and data quality are increasing intensely which brings the necessity to manage data most efficiently. Especially in spatial science, when we are dealing with complex models and higher dimensions, the need for a computationally boost up becomes compulsory. Therefore, parallel computing solutions by using python libraries, such as PyOpenCL, ParallelPython(PP), and Multiprocessing are getting attention. As an extensive advanced spatial analysis and geospatial file handling example, Rey and his co-workers [1], introduced parallelization across the spatial analysis with Python Spatial Analysis Library (PySAL) which can be reached from  [2].

Popular python data analysis library Pandas has been extended to Geopandas in order to allow users to do spatial operations.  It makes it possible to add a base map for your existing plot by only writing less than 20 lines of code and executes the whole process with a total running time of less than a minute. Examples and documentation of this open-source project can be found in

Adding a background map to plots by using geopandas Taken from:
Adding a background map to plots by using geopandas.  Image: Adding a background map to plots,

Spatial Data Analysis

Esri’s python library arcpy enables users to both handle and analyze spatial data by calling some built-in tools which ArcGIS users are familiar with. For someone who would like to start with arcpy, Python Scripting for ArcGIS (Amazon affiliate link) is a fundamental book to begin with. The book is designed to introduce python scripting for people who have no experience of writing codes [3].

In order to write and compile your stand-alone spatial analysis python scripts, the first thing is to install a user-friendly IDLE (integrated development environment) so that you can debug and test your codes. For the ArcGIS user, there is no additional cost to install python or any editor since the software already comes with this option. However, if you are seeking other options, such as open source alternatives, a useful software bundle Anaconda [4] helps as an IDLE for Linux, Windows and Mac OS X users to download scientific packages, manage libraries and dependencies in Conda environment.  Examples of this type of standalone spatial applications are getting popularity environmental modeling in especially in uncertainty and sensitivity analysis for land suitability evaluation, urban growth and land-use change, and flood vulnerability [5][6][7].

Especially when working with raster data, numpy library, which is the fundamental package for any scientific computing with python, brings an ability to handle powerful multi-dimensional arrays. Extensive online support and tutorials can be found at https://www.numpy.og. PCRasterPython library, which is developed by Karssenberg and his co-authors [8], is another useful Python library for matrix algebra and for modelling in 3D.

Spatial Data Visualization

After handling and analyzing the spatial data, the representation of the final output is the last but far the least part of a project. The effort becomes to produce maps that are effective to reach target audiences. Cartopy and Descartes have extensive cartography tools for making pretty maps. With its complete 2D and limited 3D support, matplotlib is a useful library to produce any publication quality figures. It is also possible to use cartopy along with matplotlib if you are interested to add any graph on your existing map [9].


Using Cartopy with Matplotlib Taken from:
Using Cartopy with Matplotlib.  Image:

An interesting GitHub work (Vincent library) which combines the data capabilities of python with visualization capabilities of JavaScript, explains how to create map visualization in less than 10 lines of python code [10]. Another toolbox, geoplotlib[11], is available on GitHubto fork for creaking maps and visualizing geographic data.  This library requires numpyand piglet(a cross-platform windowing and multimedia library for python) as a prerequisite, however, once all the packages are complete, it gives a lot of options to produce choropleth, heat or dot density maps.

Overall, whether you are a native python speaker or a beginner, python is a powerful language to communicate with a computer to solve the spatial communication of GIS users.


[1] Rey, S.J. and Anselin, L., 2010. PySAL: a Python library of spatial analytical methods. In: M.M. Fischer and A. Getis, eds. Handbook of applied spatial analysis. Berlin: Springer, 175–193.

[2] Sergio J. Rey, Luc Anselin, Robert Pahle, Xing Kang & Philip Stephens (2013) Parallel optimal choropleth map classification in PySAL, International Journal of Geographical Information Science, 27:5, 1023-1039, DOI: 10.1080/13658816.2012.752094

[3] Zandbergen, P.A.(2013). Python Scripting for ArcGIS. ESRI Press, Redlands, California.


[5] Ligmann-Zielinska, A. and Jankowski, P., 2014. Spatially-explicit integrated uncertainty and sensitivity analysis of criteria weights in multicriteria land suitability evaluation. Environmental Modelling and Software, 57, 235–247.

[6] Seda Şalap-Ayça, Piotr Jankowski, Keith C Clarke, Phaedon C Kyriakidis & Atsushi Nara (2018) A meta-modeling approach for spatio-temporal uncertainty and sensitivity analysis: an application for a cellular automata-based Urban growth and land-use change model, International Journal of Geographical Information Science, 32:4, 637-662, DOI: 10.1080/13658816.2017.1406944

[7] Mariana Madruga de Brito, Adrian Almoradie & Mariele Evers (2019): Spatially explicit sensitivity and uncertainty analysis in a MCDA-based flood vulnerability model, International Journal of Geographical Information Science, DOI: 10.1080/13658816.2019.1599125

[8] D. Karssenberg, K. de Jong & J. van der Kwast (2007) Modelling landscape dynamics with Python, International Journal of Geographical Information Science, 21:5, 483-495, DOI: 10.1080/13658810601063936

[9] Using cartopy with matplotlib





Using Historical Photographs to Map Landscape Change

EthicalGeo Launches With a $7,500 Contest