# Open-source Python tools to visualize and analyse geospatial data. with Samweli Mwakisambwe

Source: https://djangotv.com/videos/djangocon-us/2024/open-source-python-tools-to-visualize-and-analyse-geospatial-data-with-samweli-mwakisambwe/
Date: 2024-12-06
Speakers: Samweli Mwakisambwe, Speaker 2, Speaker 3, Speaker 4, Speaker 5

## Summary

Samweli Mwakisambwe outlines the open-source Python ecosystem for working with geospatial data, beginning with related services such as PostgreSQL/PostGIS, GeoServer, GeoNode, QGIS, GDAL, Leaflet, and OpenLayers. He focuses on Rasterio for reading and writing raster data, GeoPandas for working with multiple geospatial formats and producing plots, and QGIS for creating, editing, publishing, and visualising maps, including through its Python bindings and temporal controller. He explains that these tools can be combined in Django, alongside GeoDjango, and describes a real project where QGIS processing logic was moved from a desktop plugin into a Django API so it could run on a better-equipped remote server. He argues that the tools are practical and complementary, while noting that QGIS–Django integration is still under-documented and that GeoDjango could improve its support for the range of geospatial formats available through GDAL.

## Transcript

### [00:00] Introduction and Talk Overview

**Samweli Mwakisambwe:** [00:19] Oh, thank you. In this talk we are going to Take a look and I'm going to present and show you the available Python open source tools that you could use to visualize and analyze geospartial data. We are also going to look at the different tools that you could use with different geospatial data because there's a lot of types of geospatial data. So we are also going to take a peek at that. My name is Samweli Mwakisambwe. I'm from Dareslam, Tanzania. I'm a software developer at Katoza. Katoza is a South African Technology company

[01:05] that provides training, maintenance, and development of geospatial services. I'm also a QGIS core and QGIS Python developer. I'll touch more about QGIS at some point later. The following are the topics that we are going to cover. We are going to look at the world geospatial ecosystem. the number of services that are available and just an introduction on what you should be aware with when you are starting to deal with geospatial data, especially for those who are not familiar or haven't worked before with geospatial data. Then we are going to

[01:51] dive into our main context for the talk, which is the Python open source tools. We're going to look at the lange of the range list of the of the of the available python open source tools we're just gonna select A few of them because there's a the risk is huge, but we're just gonna select a few of them and then we're gonna take a look at how they work. Then we're gonna have few examples. So we just can have visual examples. I was planning to have some live coding, but my other computer didn't work So we're just gonna have some examples and then in the end of the talk I'm gonna share my resources.

### [02:40] The Geospatial Open-Source Ecosystem

**Samweli Mwakisambwe:** [02:40] You can visit them later and then you can see how those examples actually work And then at last we're going to touch a bit about how all these open source tools slash packages can be used inside Django and the current support of geospatial data inside Django. Now the ecosystem. There's a number of services, That are available that you could start using with the geospatial data. And notably these are open source services I've mentioned a few of them there, but

[03:25] if you if you take a look at the world ecosystem, there's a very huge number of available services and tools that are enabling the storage and management and then the access and the visualization of all at the top there you can see we have Postgres SQL, which is the database for the location data. And then alongside you have PostGIS, which is an extension to the PostGS database. It has a lot of functionality, a lot of ability to deal with the location data and the your special data inside Postbus and then you have GeoServer which is the tool used for sharing and publishing

[04:11] Geographical information. You also have Geonaud, which is a content manager for the geospatial data. And then you have QJS and GDAO, which are working hand in hand to enable users to be able to create maps, edit maps, and publish maps, time maps. And then you have leaflet and open layers, which is just a few a few examples of their variables. Libraries are responsible for visualizing geospartial Now the open source tools for Python that are available for

### [04:59] Python Geospatial Tools

**Samweli Mwakisambwe:** [04:59] visualizing and analyzing and doing analysis for the for the for the geospatial data. As I mentioned, the list is very huge, but for this talk we're gonna focus On Raster. io, GeoPanda, and QGIS. I'm gonna touch a bit about what is Rasterio. And when can you use LastRio? And then we're gonna look at the same questions for the GeoPanda and then for QGIS We're going to leave other libraries and tools. So there's pandas, there's sheprey, there's pottery, there's

### [05:46] Rasterio

**Samweli Mwakisambwe:** [05:46] Really there's NAMP which is multipurpose but it's also used in geospatial data. I'm going to include them in the resource for this presentation and then you can have a look at your own time. So raster IO. Raster IO is a Python package that is used to lead and write geospatialized data. So the main purpose of Rasterio is for interacting and accessing and writing updating the rest of that and its

[06:31] use case is very simple you just install it as a package and then you import it and use it in your in your application The example there is Rasrayo is reading a T file and plotting it on a on a on a On the canvas. The other examples that you can see on the left there is that the last IO is has been able also to read the teeth But with the with the help of Portly, RasterI also is able to catalogize and show you different color schemes for

### [07:17] GeoPandas

**Samweli Mwakisambwe:** [07:17] just partial data. So on the right there you can see that there's a NDVI which is the vegetation index that shows how healthy the vegetation is And also we have GeoPanda. So Geopanda itself Is a package that works with a variety of geospatial data formats. Compared to RasterI, which is working only with the geospatial raster data, the geopanda works with A range of rest of the geospatial data. So right there you can see that's how you can

[08:03] use geo panda. So Geo dataset is a module from GeoPanda and from this example is the code is trying to show the borough of the New York City and then after that they you plot the it plots those boroughs to a to a campus so the same example also is possible to add pottery, which plotly, which is the a package for showing different visualization, showing different data inside a canvas.

### [08:48] QGIS and Python

**Samweli Mwakisambwe:** [08:48] So you can see there we have there's a map on the on the background and on the top there's a New York New York City Bros. Okay now visualization using QGS. So what is QGS? QGS is the desktop application that's used for the creation of geospatial data creation of maps edition of maps and the public publication of maps qjs itself is developed in c plus But it has support for Python through Python SIP bindings. So it's possible to use QGIS as a Python package inside a Python application.

[09:36] It's developed at the team efforts and then it's available free to download. It's a supposed for Python as I mentioned. You could either use Python inside QJS itself as inside the desktop application, or you can Download or you can you can install QGS as the package and it's current available as a package inside the conda index On the left are the picture of the QJ's contributors from the contributor meeting. And

[10:22] as you mentioned, is free to download and use and it has a number of features that that enable the visualization So this is the look of the QGIS. There are a couple of features that it enables QGIS to Stand high in the visualization and one of them is the temporal controller. So you see in one of the examples that I'll provide in my presentation, you can see that we are using the temporal controller from QGS itself. And then we are using it inside a Python application as the in looking at different weather data

[11:12] This is an example of QGIS being loaded as a as a package in a Python application. From the left there you can see there are some imports from the from the keyjs API. And then after that we are initializing the actual application. And then we are fetching data from Alaska. So you can see down there the Rastafari URI. And then we are setting up the canvas and then we are showing it to the we're adding it to the to the canvas. Yeah so this is where I wanted to show

### [11:57] Visualization Examples and Django Integration

**Samweli Mwakisambwe:** [11:57] you the visualization example. One example that I wanted to show you is the how you could use geo panda to show the public transit data that we once worked on back in direction. And then another example that I wanted to show you was How QGIS is able to fetch data as a inside a Python application. So if you just go to the resource link there, you'll find a couple of examples. And you can try it on your own. Yeah, so Django integration. So currently Django supports geospatial data

[12:42] use usage via a Geojle framework. I think a couple of you might be aware of that but also as I mentioned we have QGS, we have GeoPanda, we have pandas, and all these all these Packages can be installed and used as Python packages inside Django. So that's it

### [13:23] Questions and Project Experience

**Speaker 2:** [13:23] Hi, thank you so much for the presentation. I have a very simple question. What's your biggest challenge that you've had when integrating Django with QGIS? And the second part is Okay, let me let you answer the first question.

**Samweli Mwakisambwe:** [13:40] Yeah, I think the biggest challenge For me it was the so this the first time when I was trying to use Django with QGIS, there was no much resource out that I could lookup it was like I'm the first in the area kind of moment and that because there's no so much documentation about the process and there's the awareness is a bit low. But you know as doing this presentation is one part of the of the aim, you know, try to get the odd out there that it's possible. And if people have any issues, they know where to go and what to reach out. So that's the main challenge. But after figuring out how like QGS is available in Conda, I can use

[14:27] as just another python package there's just some few configuration that I need to do you know and not in conda in how you set up the application itself yeah

**Speaker 3:** [14:44] Thank you, Samueli. Can you say a little bit more about your own work or the company's work or your hobby projects that and the kind of insights that you're getting from through Django and GIS.

**Samweli Mwakisambwe:** [14:58] Yeah. I think so asin catals are heavily using QGIS and We have been exposed mostly in geospatial data and trying to do analysis with geospatial data. visual and geospatial data almost every day. And one of the beautiful experiences that I had with the Django is that we We're working with this Python application QGS plugin we can call that allows processing of analysis of land or land cover changes. So we are doing this on QGIS

[15:43] and then at some point we got this challenge that You know, some people might use this Python application inside their computer and they didn't have enough, let's say, resources. So we need this to move this to a remote server so they can just go there and access it. with where we have a lot of resources. So that's when we Django came in the press because instead of there's no there's no way you could post qjs in a remote server as a you know as a web application. So what we did is we created an API using Django and inside that API, Django API, inside that Django application We installed QJS as a Python package.

[16:30] And we didn't have a lot of work because of rewriting the logic because the main Python application already had qjs logic. So we just ported that qjs logic from the desktop to the back end I mean I think that saved us a lot of work and that's because we we've been able to figure out the integration between QGIS and in general. But we are we are doing a lot of work. We are we also have a plugin that work on identify women discrimination that use geopanda, Rasta. io and QGIS

[17:16] all together. And something that I 'll add to the presentation resources so people can have a peek and look. It has a lot of cool visualization. And yeah we are working a lot of awesome projects. The temporal controller, the feature that enables QGS visualization is the work that was done at Catoza together with Northrod and other stakeholders. Yeah Thank you. Okay.

**Speaker 4:** [17:54] I have a question. Do you find any advantages of using Geo Django when you're using but More in the in the sense of the admin or how to handle the geospatial data?

**Samweli Mwakisambwe:** [18:09] Yeah, yeah, I think I think it's it's one it's it's a good framework. Because currently there's I don't think there's any other support for just partial application inside Django unless otherwise you use Geo Django. Yeah so I think I think it's it's very good. I didn't have any change only thing that there's just a couple of improvement that need to happen. The way that you know the for example for QGS, QGS is dependent on JDA, which is a an abstraction library and has a almost all formats for GeoSparad, which is not the same for GeoJango. But it's it's something that you know GeoJango can improve upon.

[18:57] So that's the I think that's the only challenge that I had. Have I answered your question? Yeah, yeah, yeah. Thank you.

**Speaker 5:** [19:05] good presentation. My name is Adam from Kenya. I'm a geospecial developer. If you compare do you also use a folium for your work or you Have you ever used it? It's also a special library that I use it. How do you compare it with QGs, Py QGs? Okay

**Samweli Mwakisambwe:** [19:27] I'm sorry, you say Odium? Folium

**Speaker 5:** [19:31] Folium. There's a geospecial dribble called folium. Yeah.

**Samweli Mwakisambwe:** [19:36] Yeah, I've heard about forum but and unfortunately I haven't worked with it so I can't compare it with QGIS. Is it open source Yeah.

**Speaker 4:** [19:52] Well thank you Samwelli. Please big round of applause for Samwelli.
