# Cartagen4py, an open source Python library for map generalisation

Guillaume Touya, Justin Berli, Azelle Courtial

► To cite this version:

Guillaume Touya, Justin Berli, Azelle Courtial. Cartagen4py, an open source Python library for map generalisation. Generalisation Constraint Monitors to Assess Tactile Maps, Jun 2023, Delft, Netherlands. [hal-04131816](https://hal.science/hal-04131816)

HAL Id: hal-04131816

https://hal.science/hal-04131816

Submitted on 17 Jun 2023

HAL is a multi-disciplinary open access
archive for the deposit and dissemination of sci-
entific research documents, whether they are pub-
lished or not. The documents may come from
teaching and research institutions in France or
abroad, or from public or private research centers.

L'archive ouverte pluridisciplinaire HAL, est
destinée au dépôt et à la diffusion de documents
scientifiques de niveau recherche, publiés ou non,
émanant des établissements d'enseignement et de
recherche français ou étrangers, des laboratoires
publics ou privés.

<figure><img src="image_1.png" /></figure>

Distributed under a Creative Commons Attribution 4.0 International License
# Cartagen4py, an open source Python library for map generalisation

Guillaume Touya<sup>a, *</sup>, Justin Berli<sup>a</sup>, Azelle Courtial<sup>a</sup>

**Keywords:** algorithms, Python library, open source, QGIS

**Abstract:**

This abstract presents cartagen4py, a new open source Python library for map generalisation. The creation of cartagen4py stems from two observations: (1) Python is the predominant scripting language for GI science and cartography, and can be used to add plugins to ArcGIS and QGIS software; (2) researchers and practitioners need open solutions for map generalisation, for better access to the state of the art techniques, and to compare different techniques in different use cases (Foerster et al. 2008, Touya et al. 2019). On the one hand, the current Python libraries such as shapely<fnref n="1" /> or PySAL<fnref n="2" /> do not contain substantive map generalisation functionalities beyond the Douglas & Peucker algorithm. On the other hand, the previous attempts to provide open and shareable map generalisation functionalities, such as WebGen (Neun et al. 2008) or CartAGen (Touya et al. 2019), are not easily usable in a Python script.

The environment to develop script in Python is already composed of open libraries that are used often by GI scientists, such as GeoPandas<fnref n="3" /> to load and structure spatial data, shapely to handle geometries, or PySAL to use spatial analysis methods. The cartagen4py library does not replace these libraries but is complementary to them to provide map generalisation tools. All geometric operations are based on shapely, and the input of the cartagen4py algorithms and processes is either a shapely geometry or a GeoPandas dataframe (when the semantic attributes are required, or when you need to keep track of the generalised features. The operations on the network features use the networkX library.

<figure><img src="image_2.png" /><figcaption>Figure 1. Results of the building simplification from Ruas (1988), previously implemented in the AGENT project. Original buildings (from OpenStreetMap) are rendered in blue, and a generalised version is printed in red.</figcaption></figure>

The cartagen4py is mainly designed to exhibit as many algorithms from the literature, as these algorithms form the core of the library, e.g. the building simplification algorithm used during the AGENT project (Figure 1). In that sense, cartagen4py is closer in its ambition to WebGen than CartAGen (Table 1). Before applying generalisation algorithms, it is usually necessary to enrich the data with implicit geographic features, and cartagen4py also intends to provide such data enrichment tools, to help the design of automated generalisation workflows or systems. The library does not contain any implementation of generalisation workflows yet, i.e. techniques that combine or orchestrate several generalisation operations, but the library will not be limited to simple algorithms. For instance, at the time this abstract is submitted, two main features are being added to the library with the AGENT model (Barrault et al. 2001) and the

<footnote><sup>a</sup> LASTIG, Univ Gustave Eiffel, IGN-ENSG, F-77420 Champs-sur-Marne, France, {firstname.lastname}@ign.fr</footnote>

<footnote>* Corresponding author</footnote>

<footnote n="1">¹ https://shapely.readthedocs.io/en/stable/</footnote>

<footnote n="2">² https://pysal.org/</footnote>

<footnote n="3">³ https://geopandas.org/en/stable/</footnote>
least squares (Harrie, 1999). AGENT orchestrates different algorithms to generalise buildings in cities using a multi-agent system. The least squares adjust the shape and position of multiple map features, solving proximity constraints while preserving the shape. Finally, the library also tends to contain evaluation methods, even though they are for now limited to basic monitor constraints (Touya, 2012). This evaluation part of the library is particularly important if we want to develop benchmarks of map generalisation, to compare different solutions for a similar dataset.

<table><caption>Table 1. List of algorithms currently implemented in cartagen4py.</caption><thead><tr><th></th><th></th></tr></thead><tbody><tr><td>Generalisation operation</td><td>Algorithms implemented in cartagen4py</td></tr><tr><td>Line simplification</td><td>Visvalingam-Whyatt (Visvalingam & Whyatt, 1993), Raposo (Raposo, 2013), Gaussian smoothing</td></tr><tr><td>Building operations</td><td>Enlarge to rectangle, simplification, squaring (Lokhat & Touya, 2016), amalgamation (Damen et al., 2008)</td></tr><tr><td>Displacement</td><td>Random displacement (from CartAGen)</td></tr></tbody></table>

As mentioned earlier, the code of the library is open under the CeCILL-C license which is a French equivalent of the LGPL. It is available on Github<fnref n="4" />. As map generalisation is usually computationally intensive when processing large datasets, the library should provide a performance that goes beyond the testing of small datasets. By heavily relying on shapely for all basic geometrical operations, there is a guarantee of performance for these basic operations, as shapely is a Python wrap of the C library GEOS.

Using cartagen4py in a Python script is an advance use, mainly dedicated to researchers or scientist developing an automated generalisation workflow. But to ease the use of the techniques exhibited in the library, we are also developing a QGIS plugin that makes a selection of algorithms available as a process in the QGIS toolbox. Then, the algorithms can be used individually by filling the GUI, or chained using the QGIS model builder. Though the development is not currently on-going, we plan to provide a similar plugin for ArcGIS users.

The documentation is currently under construction, but it will be a key factor for the adoption of the library. Besides the usual documentation of the functions available in the library using Read the docs<fnref n="5" />, we plan to propose Jupyter notebooks where new users can try several generalisation methods with provided sample datasets.

Although the current team of developers will continue porting new algorithms from CartAGen, and introducing new features to the library from the literature. New developers are welcome in the team, and we plan to organise a seminar by the end of 2023 to researchers and practitioners willing to help us in the development of the library.

## Acknowledgement

This project has received funding from the European Research Council (ERC) under the European Union's Horizon 2020 research and innovation programme (grant agreement No. 101003012 - LostInZoom).

## References

Barraault, Mathieu, Nicolas Regnauld, Cécile Duchêne, K. Haire, Christophe Baeijs, Yves Demazeau, Paul Hardy, William A. Mackaness, Anne Ruas, Robert Weibel. Integrating multi-agent, object-oriented, and algorithmic techniques for improved automated map generalisation. In *20th International Cartographic Conference*, 3:2110-16. ICA, 2001.

Damen, Jonathan, Marc van Kreveld, Bert Spaan. High Quality Building Generalization by Extending the Morphological Operators. In *Proceedings of 12th ICA Workshop on Generalization and Multiple Representation*. Montpellier, France, 2008. https://kartographie.geo.tu-dresden.de/downloads/ica-gen/workshop2008/04_Damen_et_al.pdf.

Foerster, Theodor, Dirk Burghardt, Moritz Neun, Nicolas Regnauld, Jerry Swan, Robert Weibel. Towards an Interoperable Web Generalisation Services Framework – Current Work in Progress. In *Proceedings of 11th ICA Workshop on Generalisation and Multiple Representation*. Montpellier, France, 2008.

<footnote n="4">⁴ https://github.com/LostInZoom/CartAGen4Py</footnote>

<footnote n="5">⁵ https://readthedocs.org/</footnote>
Harrie, Lars E. The Constraint Method for Solving Spatial Conflicts in Cartographic Generalization. Cartography and Geographic Information Science 26, nº 1 (1999): 55-69. https://doi.org/10.1559/152304099782424884.

Lokhat, Imran, Guillaume Touya. Enhancing building footprints with squaring operations. Journal of Spatial Information Science 13 (2016): 33-60. https://doi.org/10.5311/JOSIS.2016.13.276.

Neun, Moritz, Dirk Burghardt, Robert Weibel. Web service approaches for providing enriched data structures to generalisation operators. International Journal of Geographical Information Science 22, nº 2 (2008): 133-65. https://doi.org/10.1080/13658810701348997.

Raposo, Paulo. Scale-specific automated line simplification by vertex clustering on a hexagonal tessellation. Cartography and Geographic Information Science 40, nº 5 (2013): 427-43. https://doi.org/10.1080/15230406.2013.803707.

Ruas, Anne. Généralisation d'immeubles. Master's Thesis, ENSG, 1988.

Touya, Guillaume. Social Welfare to Assess the Global Legibility of a Generalized Map. In Geographic Information Science 7th International Conference, GIScience 2012, (eds) Ningchuan Xiao, Mei-Po Kwan, Michael F. Goodchild, Shashi Shekhar, 7478:198-211. Lecture Notes in Computer Science. Berlin, Heidelberg: Springer Berlin / Heidelberg, 2012. https://doi.org/10.1007/978-3-642-33024-7_15.

Touya, Guillaume, Imran Lokhat, Cécile Duchêne. CartAGen: An Open Source Research Platform for Map Generalization. Proceedings of the ICA 2 (2019): 1-9. https://doi.org/10.5194/ica-proc-2-134-2019.

Visvalingam, M., J. D. Wyatt. Line Generalization by Repeated Elimination of Points. The Cartographic Journal 30, nº 1 (1993): 46-51.