Skip to Content

Python, le domaine géospatial et les livres disponibles en 2015 (modules, PyQGIS, ArcPy)

Niveau Intermédiaire
Logiciels utilisés
Plateforme Windows | Mac | Linux | FreeBSD

Beaucoup d'eau s'est écoulée depuis l'article Python: géospatial, dialectes (standard, pour ESRI, pour FME, pour GvSIG etc.) et incompréhensions...(2011) et l'appel « Where's the book » de Sean Gillies. Depuis lors les livres sur ArcPy sont bien arrivés, mais de nombreux livres sur Python et le géospatial et sur PyQGIS aussi.

Caractéristiques générales

Il n'y a, malheureusement pour certains, aucun livre en français.

Une des questions préalables est de savoir s'il faut connaître Python avant de les aborder. Suivant ce critère, les ouvrages proposés peuvent être classés en deux catégories, chacune suscitant des critiques diverses, voire contradictoires dans certains cas:

Le livre aborde d'abord les principes généraux de Python avant de passer à l'utilisation de certains modules spécifiques:

  • C'est le cas essentiellement des livres consacrés à ArcPy et c'est une question de culture, car le monde ESRI découvre Python (un langage de scripts parmi d'autres après AML, Avenue, VBA, .NET, etc.) dans un environnement uniquement Windows.

Cette approche suscite des critiques diverses comme celles de James Fee dans Book Review – Python Scripting for ArcGIS:  "it focuses on integrating an introduction to Python with the industry specific materials. As Frank mentioned when he highlighted the book in a previous podcast, this allows users to gain exposure to Python, but it doesn’t fall back on the (in my opinion) bad habit of most programming texts of spending half of the book on the language and concepts before even getting to the application in the specific area. There is a time and place for that approach in Python specific books. When you add another software library to a book, then use it from the get go") et dans Book Review: Programming ArcGIS 10.1 with Python Cookbook , "The style of the scripts seems to mimic the Esri style so I’m guessing the author is very familiar with ArcPy; I don’t write my scripts this way but at least it should help you move from the book to Esri documentation quickly" 

Cet "ESRI style" serait dû à la manière très formatée (utilisation des commandes d'ArcGIS) dont Python est enseigné dans les ouvrages, avec, entre autres, la relative méconnaissance de tous les modules hors ArcPy (ce qui amène souvent les utilisateurs à souvent vouloir « réinventer la roue» alors qu'il y a des multiples modules qui existent pour le faire) et certains « tics » comme la multiplication des try/except (gestion des erreurs) inutiles pour un travail personnel et qui alourdissent et ralentissent les scripts (il y a des alternatives).

Le livre débute directement par l'utilisation des modules, présupposant que Python est connu ou qu'il y a des livres spécifiques pour apprendre:

C'est le cas:

  • de ceux consacrés aux solutions en Python seul, car, somme toute, il faut le connaître préalablement pour s'en servir avec profit;
  • dans une moindre mesure, de ceux consacrés à PyQGIS qui se situent entre ces deux extrêmes, se focalisant surtout sur la bonne compréhension des caractéristiques de l'API.

Les critiques  estiment alors que la démarche conduit à des simples copier/coller de scripts (sans approfondissement du langage) avec comme résultats, que les utilisateurs sont complètement perdus s'ils doivent sortir du cadre de l'exemple (« simples recettes de cuisine »). Cette particularité  est particulièrement visible dans de nombreuses questions posées sur des sites de questions/réponses comme Gis Stack Exchange (les utilisateurs n'ayant apparemment pas le temps d'apprendre Python ou de chercher par eux mêmes...).

Pour moi, qui  rêve toujours d'un monde où l'on pourrait tout mélanger, cela me parait encore impossible: les « cultures » me semblent trop différentes (de même que les licences). En illustration de cet aspect, certains doutent que l'annonce par ESRI de l'adoption de SciPy (Esri Advances Scientific Analysis with SciPy ) intéresse l'utilisateur lambda qui utilise Python pour ses scripts ou les utilisateurs professionnels (c'est quoi Scipy, ça sert à quoi ?) alors que pour les autres, c'est un élément de base de la chaîne de traitements (This is a huge shift and one that I think everyone should be excited about.  SciPy is a great analysis tool that you can use anywhere, just not Esri.  You don’t need to worry about an Esri license being available for ArcPy, just use it wherever you wish.  Now short term this is probably just a niche thing as only the bleeding edge ArcGIS Pro supports it, but the plans are to back port it to the classic ArcGIS Desktop enabling you to work with your existing projects.  I can’t stress enough that people should learn how to use SciPy with Esri if only to broaden their marketability. (SpatialTau v2.1 – Scripting , toujours James Fee qui est le plus dynamique sur ce sujet).

Les prix

Ils s'échelonnent entre 23 et 80 euros suivant l'option choisie (papier, PDF, EPUB, ..., certains moins chers en version Kindle). L'éditeur Packt Publishing est le plus dynamique et offre souvent des réductions conséquentes en fonction de certains évènements (il faut en profiter...). Les livres de Esri Press sont généralemnt les plus chers.

Python seul

Ils s'intéressent aux solutions en Python seul à l'aide des modules à finalité géospatiale (Les modules Python à finalités géospatiales: quid, quando, ubi ?). Une bonne connaissance de Python est donc indispensable.

- Python Geospatial Development – Second Edition de Eric Westra (2013), 508 pages

L'auteur  attaque directement les traitements avec les modules GDAL (osgeo), Shapely, Mapnik, Django/GeoDjango (shapefiles, bases de données spatiales, OpenStreetMap, webmapping). L'accent est surtout mis sur le module Mapnik et la création d'une application complète avec Django/GeoDjango.

Chapter 1: Geospatial Development Using Python
Chapter 2: GIS
Chapter 3: Python Libraries for Geospatial Development
Chapter 4: Sources of Geospatial Data
Chapter 5: Working with Ceospatial Data in Python
Chapter 6: GIS in the Database
Chapter 7: Working with Spatial Data
Chapter8: Using Python and Mapnik to Generate Maps
Chapter 9: Putting It All Together – a Complete Mapping System
Chapter 10: ShapeEditor – Implementing List View, Import, and Export
Chapter 11: ShapeEditor – Selecting and Editing Features

- Learning Geospatial Analysis with Python de  Joel Lawhead (2013), 364 pages

Joel Lawhead est le créateur du module PyShp et du blog GeospatialPython. Tous les aspects sont abordés. Son ouvrage est une véritable mine d'informations: la plupart des modules géospatiaux sont traités (installation sur Linux, Mac OS X, Windows, principes d'utilisation) avec une multitude d'exemples pratiques dans tous les domaines.

Chapter 1: Learning Geospatial Analysis with Python
Chapter 2: Geospatial Data
Chapter 3:The Geospatial Technology Landscape
Chapter 4: Geospatial Python Toolbox
Chapter 5: Python and Geographic Information Systems
Chapter 6: Python and Remote Sensing
Chapter 7: Python and Elevation Data
Chapter 8: Advanced Geospatial Python Modelling
Chapter 9: Real-Time Data
Chapter 10: Putting lt All Together

Il faut aussi signaler l'ouvrage Geoprocessing with Python de Chris Garrard (sous presse), 400 pages  consacrées aux traitements avec le module GDAL (osgeo) et qui est le prolongement de son cours universitaire en ligne  Geoprocessing with Python using Open Source GIS à la UtahState University/GIS Laboratory déjà cité sur le Portail (merci ThomasG77).

  1: Introduction 
  2: Python basics 
  3: Representing the world as shapes: Points, lines, and polygons 
  4: Reading vector data with OGR
  5: Writing vector data with OGR
  6: Filtering data with OCR
  7: Manipulating geometries with OGR
  8: Using spatial reference systems
  9: Representing the world as a set of numbers
10: Reading and writing raster data
11: Working with raster data
12: Analyzing raster data: NumPy
13: Visualizing data with Matplotlib

PyQGIS

Une remarque s'impose, si vous voulez seulement apprendre à créer un plugin, ces livres ne sont pas pour vous. Ils traitent essentiellement des caractéristiques de PyQGIS et de leurs compréhensions avec des exemples pratiques (l'aspect plugin est abordé sommairement). Ils comblent ainsi, en partie, les lacunes de la documentation officielle. Ils sont néanmoins difficiles à aborder si vous n'avez pas quelques notions préalables de Python.

- The PyQGIS Programmer's Guide de Gary Sherman (2014), 197 pages

Gary Sherman est le créateur de QGIS: c'est lui qui a conçu les premières versions du programme. Il est aussi le créateur du plugin Script Runner (voir sur le Portail QGIS : lancer des scripts Python ou des commandes Shell depuis la Console Python ou avec Script Runner (sans créer d'extension) ). Le livre s'attache essentiellement à la bonne compréhension de ce qu'il appelle l'écosystème QGIS/Python, nécessaire avant de penser à créer un plugin.

Python Basics
Setting UpYour Development Tools
The QGIS/Python Ecosystem
Navigating the QGIS API
Using the Console
Running Scripts
Tips and Techniques
Extending the API
Writing Piugins
Creating a Development Workflow
Writing a Standalone Application

- Building Mapping Applications with QGIS de Erik Westra (2014), 264 pages

Comme le précedent, il aborde tous les aspects pratiques de PyQGIS, mais disserte un peu plus sur la création de plugins et la création d'applications autonomes.

Chapter 1: Getting Started with QGIS
Chapter 2: The QCIS Python Console
Chapter 3: Learning the QCIS Python API
Chapter 4: Creating QGIS Plugins
Chapter 5: Using QGIS in External Application
Chapter 6: Mastering the QGIS Python API
Chapter 7: Selecting and Editing Features in a PyQGIS Application
Chapter 8: Building a Complete Mapping Application using Python and QGIS
Chapter 9: Completing the ForestTrails Application

- QGIS Python Programming Cookbook de Joel Lawhead, 340 pages

Ce livre est le pendant de Learning Geospatial Analysis with Python, c'est une véritable caverne d'Ali Baba de trucs et d'astuces pratiques à réaliser avec PyQGIS dans tous les domaines. (depuis le débogage des scripts jusqu'à la composition complète de cartes) plutôt qu'une simple introduction à l'API.

Chapter 1: Automating QCIS
Chapter 2: Querying Vector Data
Chapter 3: Editing Vector Data
Chapter 4: Using Raster Data
Chapter 5: Creating Dynamic Maps
Chapter 6: Composing Static Maps
Chapter 7: Interacting with the User
Chapter 8: QGIS Workflows
Chapter 9: Other Tips and Tricks

Signalons qu'Anita Graser dans la deuxieme édition de son livre Learning QGIS - Second Edition  (2014, 150 pages)

propose une petite introduction à PyQGIS (18 pages)

Chapter 6: Extending QGIS with Pvthon
   Getting to know the Pvthon console
    Creating custom geoprocessing scripts using Python
    Developing your first plugin

ArcGIS, ArcPy

Ici, je suis pénalisé, car je ne connais pas le module ArcPy et je ne permettrai donc aucun commentaire. Je me contenterai donc ici de présenter les tables des matières, laissant à d'autres le soin de juger.

- A Python Primer for ArcGIS® de Nathan Jennings(2011), 462 pages

 

Chapter 1: Python and ArcGIS
Chapter 2: ModelBuilder and Python
Chapter 3: Python Constructs
Chapter 4: Writing a Basic Geoprocessing Python Script
Chapter 5: Querying and Selecting Data
Chapter 6: Creating and Using Cursorss and Table Joins
Chapter 7: Describing Data and Operating on Lists
Chapter 8: Custom Error Handling and Creating Log Files
Chapter 9: Mapping Module
Chapter 10: Custom ArcGIS Tools and Python Scripts
Chapter 11: Automating Geoprocessing Scripts

Ce livre a été réédité en version plus complète en 2015 (3 volumes prévus):

A Python Primer for ArcGIS®: Workbook I et A Python Primer for ArcGIS®: Workbook II  (2015, le Worbook III est sous presse)

 

 

- Python Scripting for ArcGIS  de Paul A. Zandbergen (2013, 2015)


C'est le premier livre consacré à Python estampillé du logo ESRI. 

Chapter 1: Introducing Python
Chapter 2: Geoprocessing in ArcGIS
Chapter 3: Using the Python window
Chapter 4: Learning Python language fundamental
Chapter 5: Geoprocessing using Python
Chapter 6: Exploring spatial data
Chapter 7: Manipulating spatial data
Chapter 8: Working with geometries
Chapter 9: Working with rasters
Chapter 10: Map scripting
Chapter 11: Debugging and error handling
Chapter 12: Creating Python functions and classes
Chapter 13: Creating custom tools_
Chapter 14: Sharing tools

- Programming ArcGIS 10.1 with Python Cookbook de Eric Pimpler (2013), 304 pages

 

Chapter 1: Fundamentals of the Python Language for ArcGIS
Chapter 2. Writing Basic Ceoprocessing Scripts with ArcPy
Chapter 3: Managing Map Documents and Layers
Chapter 4: Finding and fixing Broken Data Links
Chapter 5: Automating Slap Production and Printing
Chapter 6: Executing Ceoprocessing Tools from Scripts
Chapter 7: Creating Custom Ceoprocessing Tools
Chapter 8: Querying and Selecting Data
Chapter 9: Using the Arcpy Data Access Module to Select, Insert, and Update Geographic Data and Tables.
Chapter l0: Listing and Describing CIS Data
Chapter 11: Customizing the ArcCIS Interface with Add-Ins
Chapter 12: Error Handling and Troubleshooting

- GIS Tutorial for Python Scripting de David W. Allen (2014), 284 pages

Chapter 1: Using Python in labeling and field calculations
Chapter 2: Writing stand-alone Python scripts
Chapter 3: The ArcPy mapping module
Chapter 4: Python toolboxes
Chapter 5: Python add-ins

- ArcPy and ArcGIS – Geospatial Analysis with Python de Silas Toms (2015), 224 pages

Chapter 1: Introduction to Python for ArcGIS
Chapter 2: Configuring the Python Environment
Chapter 3: Creating the first Python Script
Chapter 4: Complex ArcPy Scripts and Generalizing Functions
Chapter 5: ArcPy Cursors: Search, Insert and Update
Chapter 6: Working with ArcPy Geometry Objects
Chapter 7: Creating a Script Tool
Chapter 8: introduction to ArcPy.Mapping
Chapter 9: More Arcpy Mapping Techniques
Chapter 10: Advanced Geometry Object Methods
Chapter 11: Network Analyst and Spatial Analyst with with ArcPy
Chapter 12: The End of the Beginning

Conclusions

Il ne faut pas oublier que Python peut aussi être utilisé dans GRASS GIS (GRASS GIS v. 6.4.2: la nouvelle console Python (Shell Python), exemple d'utilisation simple ou avec le module Shapely, aspect encore plus développé dans la version 7 avec PyGRASS), GvSIG, OpenJUMP et consorts (Jython et le géospatial: exemples avec GeoScript (GeoTools) , JTS ( Java Topology Suite), OpenJump, gvSIG, WorldWind ou Geoserver),  PostgreSQL/PostGIS, les bases de données NoSQL, mais aussi dans des logiciels annexes et utiles comme Inkscape, Gimp, ParaView, Blender (entre autres, voir Python Success Stories).

Alors, la question faut-il connaître Python avant ou l'apprendre avec un module particulier reste toujours d'actualité....

Mais tout cela ne fait que souligner la vitalité du langage qui est en train de devenir LE langage de scripts scientifiques par excellence, notamment plébiscité par la revue Nature (Programming: Pick up Python ) et qu'il faut l'apprendre d'une manière ou de l'autre (Python is Now the Most Popular Introductory Teaching Language at Top U.S. Universities).

Ah oui, quels sont mes livres de chevet actuels... (les plus pratiques)

Site officiel : Python
Site officiel : Python: Topic :: Scientific/Engineering :: GIS
Site officiel : PyQGIS
Site officiel : ESRI ArcPy


Creative Commons License
licence Creative Commons Paternité-Pas d'Utilisation Commerciale-Pas de Modification 2.0 France

Commentaires

merci, ajouté

Je l'ai ajouté aux références

Titre intéressant non mentionné

Merci pour cette liste très intéressante.

Je tiens à signaler le livre "Geoprocessing with Python" de Chris Garrard http://www.manning.com/garrard/ (en cours) qui est l'auteur du cours "de base" sur l'utilisation de GDAL avec Python (https://trac.osgeo.org/gdal/wiki/GdalOgrInPython)

Poster un nouveau commentaire

Le contenu de ce champ sera maintenu privé et ne sera pas affiché publiquement.