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

This video features Samweli Mwakisambwe at DjangoCon US 2024 in Durham, North Carolina, USA.

Open-source Python tools to visualize and analyse geospatial data. with Samweli Mwakisambwe
0:20:29
Published December 6, 2024
155 views

The talk will provide an overview of the available Python related geospatial tools that can be used to analyze location data highlighting the possibilities and the potential of this attendees will be able to grasp what tools they can use to access particular location data.
Among the available python geospatial tools we will discuss the main and most used in accessing location data types raster and vector, we will have a look at how these base tools can be used to access the types and their benefits.
We will then dive into one of the tools called QGIS and use it as an exemplar of how we can now interact, analyze, and visualize geospatial data in Python. A step-by-step guide on how to import and use QGIS features in Python.
QGIS is a freely downloadable open-source GIS software suite that contains a desktop option, mobile, and web components. QGIS version 3.14 was released with a Temporal Controller an interesting feature that allows immersive and creative visualization of time-based geospatial data.
Then we will see how QGIS can be used inside Django as a package. Showing how to achieve a link between the two tools.
At the end of the talk attendees should expect to have a comprehensive understanding of different Python geospatial tools, whether you are a developer or a professional learning new ways of technology, this talk will equip you with the knowledge on the right geospatial tools.

This talk was presented at: https://2024.djangocon.us/talks/open-source-python-tools-to-visualize-and-analyse-geospatial-data/

LINKS:
Follow Samweli Mwakisambwe 👇
On X: https://x.com/SamweliTwesa
Website: https://samweli.github.io/

Follow DjangoCon US 👇
https://fosstodon.org/@djangocon
https://x.com/djangocon

Follow DEFNA 👇
https://www.defna.org/

Video production by Confreaks
Follow Confreaks 👇
https://confreaks.com
https://x.com/confreaks

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.

Key takeaways

  • Rasterio is suited to reading, writing, updating, and visualising raster geospatial data, including vegetation-index data such as NDVI.
  • GeoPandas handles a wider range of geospatial data formats and can be combined with Plotly for map visualisation.
  • QGIS is a free desktop GIS with Python bindings, allowing its mapping, processing, and temporal-visualisation features to be used in Python applications.
  • Django can expose existing QGIS processing logic through an API, allowing demanding geospatial work to run on a remote server instead of a user's computer.
  • GeoDjango provides Django's main built-in support for geospatial applications, although its format support and documentation could be improved.

Summarised automatically from the transcript.

Transcript

2,598 words · auto-generated Show

Automatically transcribed, so expect mistakes in names and technical terms.

0:19

Speaker 1: Oh, thank you. Um 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 Mokisambwe. I'm from Dareslam, Tanzania. I'm a software developer at Katoza. Katoza is a South African Technology company

1:05

Speaker 1: that provides training, maintenance, and development of geospatial services. I'm also a QGIS core and uh 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 Uh familiar or haven't worked before with geospatial data. Then we are going to

1:51

Speaker 1: dive into our main context for the talk, which is the Python open source tools. We're going to look at the uh the lange uh of uh the range list of the of the of the available python open source tools we're just gonna select um 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. Um then we're gonna have uh few examples. Um So we just can have uh uh visual examples. I was planning to have some live uh uh coding, but my other computer didn't work So we're just gonna have some examples and then um in the end of the talk I'm gonna share my um resources.

2:40

Speaker 1: You can visit them later and then you can see how those uh 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. Um there's a a number of services, um That are available that you could start using with the geospatial data. And notably these are open source services I've uh mentioned a few of them there, but uh

3:25

Speaker 1: if you um if you take a look at the uh world ecosystem, there's a very huge number of um available services and tools that are enabling the storage and management and then the access and the visualization of all Um at the top there you can see um 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 um which is the tool used for um sharing and publishing

4:11

Speaker 1: uh 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 uh And publish maps, time maps. And then you have uh um leaflet and um open layers, uh which is uh just uh uh a few a few examples of uh their variables. Um libraries are responsible for visualizing um geospartial Now the open source tools um for Python that are available for um

4:59

Speaker 1: 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. Um, 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 uh and tools. So there's pandas, there's um sheprey, there's pottery, there's uh um

5:46

Speaker 1: Uh really um there's NAMP uh which is uh multipurpose but it's also used in uh 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. Um Raster IO is a Python package that is used to lead and write uh geospatialized data. So the main purpose of Rasterio is for um interacting and accessing and uh writing updating the the the rest of that and its

6:31

Speaker 1: use case is um is is very simple um you just install it as a package um and then you import it and use it in your uh um in your application The example there is um Rasrayo is reading a a T file and um and 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 um color schemes for

7:17

Speaker 1: just partial data. So on the right there you can see that there's a NDVI which is the vegetation index that shows um how healthy the vegetation is And also we have GeoPanda. Um so Geopanda itself um Is a package that works with a variety of um geospatial data formats. Um compared to RasterI, which is working only with the geospatial raster data, um the geopanda works with um A range of rest of the geospatial data. So right there you can see that's how you can

8:03

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

8:48

Speaker 1: 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 uh visualization using QGS. So what is QGS? QGS is the um desktop application that's used for the creation of um um geospatial data creation of maps edition of maps and the public publication of maps um qjs itself um is is um is developed in c plus 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.

9:36

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

10:22

Speaker 1: as you mentioned, is free to download and use and uh it has a number of features that um that enable the visualization So this is the look of the QGIS. Um there are a couple of features that um 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 um uh uh in in in in in looking at different weather data

11:12

Speaker 1: Um this uh this is an example of QGIS uh being loaded as a as a package in a Python uh 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 um uh we're adding it to the to the canvas. Yeah so this is where I wanted to um uh show

11:57

Speaker 1: you the visualization example. One example that I wanted to show you is the how you could use geo panda to show um the public transit data that we once uh worked on back in direction. And then another example that I wanted to show you was um 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. Um and you can try it on your own. Yeah, so um uh Django integration. So currently Django um supports uh geospatial data

12:42

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

13:23

Speaker 2: 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 um Okay, let me let you answer the first question.

13:40

Speaker 1: Yeah, um I I think the biggest challenge um For me it was the so this the first time when I was trying to use Django with QGIS, there was no um much resource out that I could uh lookup it was like um I'm the first in the area kind of moment uh and that because um there's no so much documentation about the process and there's the awareness is a bit low. But um you know as um 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 uh if people have any issues, they know where to go and what to reach out. So that's the the main challenge. But after figuring out how like QGS is available in Conda, I can use

14:27

Speaker 1: 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 the the application itself yeah

14:44

Speaker 3: Thank you, Samueli. Um 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 uh GIS.

14:58

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

15:43

Speaker 1: and then at some point we um we got this challenge that um 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 um 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 uh instead of um there's no there's no way you could um post qjs in a remote server as a you know as a web application. So what we did is we uh created an API using Django and inside that API, um Django API, inside that Django application We installed QJS as a Python package.

16:30

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

17:16

Speaker 1: 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 um yeah we we we are working a lot of uh awesome projects. Um the temporal controller, the feature that enables QGS visualization is the work that um was done uh at Catoza together with um uh Northrod and and and other uh other stakeholders. Yeah Thank you. Okay.

17:54

Speaker 4: Um I have a question. Um do you find uh 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?

18:09

Speaker 1: Yeah, yeah, I think I think it's uh it's one it's it's a good framework. Um because currently there's I don't think there's any other support uh for for just partial application inside Django uh unless otherwise you use Geo Django. Yeah so I think uh I think it's it's very good. Uh I didn't have any change only thing that uh there's just a couple of improvement that need to to happen. The way that you know the 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 uh it's something that you know GeoJango can improve upon.

18:57

Speaker 1: So that's the I think that's the only uh challenge that I had. Have I answered your question? Yeah, yeah, yeah. Thank you. Uh

19:05

Speaker 5: good presentation. My name is Adam from Kenya. I'm a geospecial uh developer. Uh if you compare uh uh 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 uh QGs, Py QGs? Okay

19:27

Speaker 1: I'm sorry, you say Odium? Folium

19:31

Speaker 5: Folium. There's a geospecial dribble called folium. Yeah.

19:36

Speaker 1: Yeah, I've heard about forum but um and uh unfortunately I haven't worked with it so I uh can't compare it with QGIS. Is it open source Yeah.

19:52

Speaker 4: Well uh thank you Samwelli. Uh please uh big round of applause for Samwelli.

Questions this talk answers

What is Rasterio used for in Python geospatial projects?

Rasterio is a Python package for accessing, reading, writing, and updating geospatial raster data. It can also be used with plotting tools to display raster datasets and color schemes such as NDVI.

Discussed at 5:46

What is the difference between Rasterio and GeoPandas?

Rasterio is focused on geospatial raster data, while GeoPandas works with a broader range of geospatial data formats and can plot vector datasets such as city boroughs.

Discussed at 7:17

Can QGIS be used as a Python package?

Yes. QGIS is a desktop application for creating, editing, and publishing maps, but its Python bindings also allow it to be used inside Python applications, including through Conda.

Discussed at 8:48

How can Python geospatial tools be used in Django?

Django supports geospatial applications through GeoDjango, and packages such as QGIS, GeoPandas, and pandas can also be installed and used inside a Django application.

Discussed at 12:42

What is the biggest challenge when integrating Django with QGIS?

The main challenge was the lack of documentation and examples for the integration. Once QGIS was available through Conda, it could be used like another Python package, with some additional application configuration.

Discussed at 13:40

How did the speaker use Django and QGIS to run geospatial processing remotely?

They exposed the existing QGIS-based land and land-cover-change processing through a Django API, installing QGIS as a Python package on the backend. This let users access the processing on a remote server instead of needing sufficient resources on their own computers, while reusing most of the existing QGIS logic.

Discussed at 15:43

What are the advantages of using GeoDjango for geospatial data in Django?

GeoDjango provides Django’s main support for geospatial applications and is considered a good framework for handling geospatial data. The speaker notes that it could still improve its format support compared with QGIS’s dependency on GDAL.

Discussed at 18:09

Note: We understand that names change, people change, and bodies change. We respect each individual's journey and privacy. If you have any concerns about a video or need us to remove content, please don't hesitate to contact us. We will handle your request with care and promptly address any issues.

More videos from DjangoCon US