GeoDjango at City Scale: Spatial Data for Urban Systems with Drishti Jain

This video features Drishti Jain at DjangoCon US 2026 in Chicago, Illinois, USA.

GeoDjango at City Scale: Spatial Data for Urban Systems with Drishti Jain
0:25:54
Published October 26, 2026
237 views

In this talk, I’ll delve into how GeoDjango can be used to build scalable spatial data platforms for smart cities and urban systems. Cities are fundamentally spatial systems—roads, buildings, utilities, mobility flows, and environmental sensors all exist in geographic space—and modeling these systems requires tools that can handle geospatial data at scale. GeoDjango, combined with PostGIS, provides a powerful framework for representing, querying, and visualizing this spatial information in web applications.
I’ll begin by exploring how urban entities such as buildings, transit routes, sensor locations, and zoning boundaries can be modeled using GeoDjango’s spatial fields and ORM abstractions. Attendees will see how spatial indexes and geospatial queries enable proximity search, containment checks, routing queries, and large-scale spatial analytics directly from Django applications.
Next, I’ll examine architectural and performance considerations for city-scale spatial systems, including indexing strategies, partitioning spatial datasets, and optimizing geospatial queries for low latency. We’ll discuss how GeoDjango fits into modern data pipelines, integrating with streaming telemetry, GIS data sources, and visualization layers such as interactive maps and dashboards.
Finally, I’ll discuss how spatial data platforms inform urban planning, infrastructure management, and policy decisions, and how Django-based systems can serve as the backbone for civic analytics and public data platforms. Throughout the talk, attendees will gain practical and conceptual tools for building geospatially-aware web systems and a deeper understanding of how Django can power the spatial intelligence layer of modern cities.

This talk was presented by Drishti Jain at DjangoCon US 2026 in Chicago, Illinois, USA
https://2026.djangocon.us/talks/geodjango-at-city-scale-spatial-data-for-urban-systems/

Transcript

4,139 words · auto-generated · en Show

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

0:14

So today we are going to talk about something uh that all of us can actually build on our own. I'll give you a Good blueprint so that you can use your favorite AI agent and get started with it today right after the talk itself A quick introduction about me. I'm Drishti Jen. If you scan that QR code, those are all my links. I'm a software developer. I did a lot of machine learning during my master's at Georgia Tech. And now I'm also into the Agentec AI space. So right now I talk to Claude a lot. That is what I figured in life. A lot into MCPs, harnesses, building agents that actually solve problems and don't just spam out code and just solutions which do not require a technical solution in the first place.

1:00

I'm a published technical book author. I'm a social entrepreneur. I build a lot of projects for tech for good as well, helping out the community in a real sense wherein tech has a lot of potential, which a lot of underserved communities Will benefit from using it. As an international tech speaker, I love to share my knowledge and any and everything that I'm building with the community. I feel that In the tech community, the our biggest power is sharing knowledge that we gain. And in this fast-moving world of AIN, wherein new technologies are coming, there are so many new libraries out there. It'll be good to have a fellow builder tell us if this library has some pros, some cons instead of just adapting something that's just new just for the sake of it.

1:47

So I would also encourage all of you to like contribute back to the community, share your learnings, and that overall helps the community to build better products. and learn from each other. When we talk about geospatial analysis, the base of everything is the geometry on which we are building it. If we get the geometry wrong, all the decisions that we do from there on get wrong. All city systems run on spatial questions. If a data model cannot answer them uh natively, teams write slow bug prone code and even if there's a one-off uh difference in the geometry code, People are relying on the answers you give out of your systems, and that can all be wrong.

2:35

Right from consider something like an emergency response. Which units, which building units or apartment units are inside an affected zone? These need to be answered in milliseconds, not even minutes. You need to build equitable infrastructure. Which neighborhoods actually lack EV access? People are encouraged to buy electric vehicles, but if there's no infrastructure supporting uh actually driving an EV around. That is not right. It is not an equitable infrastructure that was built. The environmental risk. Which buildings sit inside a flood plan? With time, with um the climate changing around us, flood maps change as well if we do not c um account for The way the flood maps are changing, which new areas are now in the flood-prone zone, we might be building solutions for areas which do not need it, and we are not helping out regions which actually need it in case of a flood.

3:33

Now let's use Django and give Django a sense of the place. So every city is built from things that live in that space Right from buildings, roads, sensors, transit stops. And GeoDjango is Django's toolkit for treating geography as a first-class part of your data model. So Geo Django is our solution to building that intelligence layer so that we are able to analyze the tons of data we get from our sensors , from geometry intelligence that we built. To give you a mind map of what it actually looks like, so Django plus Geo Django, along with the power of because we are dealing with a lot of data, we need a good place to store all of that data. Using Postgres

4:19

and PostGIS, we are able to build on a lot of functions, a lot of methods for it, which leads to different maps and dashboards. So in our Django models we have spatial fields like points, lines, and polygons, and ORM that speaks geometry. So things like within intersects. If you're If you're building anything for a particular point, so something that has to be within 500 meters of that point or within a mile of that point, those terms are in-built functions we'll be looking at later on in the hands-on as well. And Post GIS underneath, which does the geometric heavy lifting on the database. Before I dive deeper, let me talk about SRID, which is the spatial reference system identifier So every geometry carries an SRID, which is like a coordinate system

5:09

with in which the numbers are written in. If we look at this, if I'm building out a point field, so SRID, if you do not specify it, it is the default way. A parallel to draw is like base 64. It is the system on which different uh uh number systems understand. Similarly for GPS systems, your latitude-longitudes are in SRID 4326. Interesting point to note here is when we are declaring a point like this, for example point minus 12237, it isn't latitude-longitude as our instinct would tell us. It is actually uh longitude, latitude. So that is an interesting point to note, especially people who are getting started at starting with um Geo Django

5:55

in the first place tend to swap these numbers because we have been uh learning about systems as like latitude, comma, longitude, and but actually while declaring it's the other way around Let's look at what shapes and spatial indexes are. A quick overview: these are three key shapes that you need to map out anything: point, line string, and polygon. Directly if you want to if you want to represent your sensors, transistors, and say EV chargers. So these are point systems that you are trying to identify. So they can be um shaped directly as a point. So your location can be models. point field for roads, transit routes, pipelines.

6:40

This includes any and everything, your water pipeline, your um C-H pipelines, all lines that you are mapping out on a map, those can be represented as a line string field. And polygons are your zones, your schools, your buildings, different parcels of land. All of those are polygon fields. These are the only three things you need to map out anything. While we have so many things, an important aspect to make things quick. If you remember you want answers in milliseconds, right? So you have so much of data. If you're indexing through everything, why not have an index which will help you query it faster? So that is what is called a spatial index. Um and it is like a books index, books index, but for shapes. So instead of reading every page in post

7:27

GIS, you can jump straight to the handful of geometries that could be possibly matching to you. So your spatial query goes through your spatial index to generate the candidate geometries that is the focus area on your map to get the exact geometry test. What is the use of actually having a spatial index? If you do not have one, in every query you are scanning every row. Whereas if you have an index, you are directly targeting the set of candidate points that you are interested in. Now these are a few verbs like Whenever we are talking about geometry, just think of maps. If you have a big map in front of you, you want to identify if a particular point is within a mile's radius.

8:16

So things like within, uh the post GIS function is called st underscore within. Um so something like A is fully inside B. So you want to identify something that is within something. If it is contains, so A fully contains B. Basically B is fully inside of A. Intersects. So if there are any shared points. Well, while building public infrastructure especially, you want to know if there's a lot of overlap, a lot of intersection already. If there is, that is not your focus point. You need to identify your sparse areas, areas which are not served All of that in your ORM lookup is through intersects. And distance is within a distance for your latitude-longitude. If you have two points and you're trying to identify what distance is between them.

9:02

Now we have uh now that we have like a quick vocabulary of everything of the building blocks, let's actually model. Let's find EV charger coverage gaps. There are four core urban entities we'll require, a building, a transit stop, a road, and a district. And if you see these are simple classes which can have more um parameters as and when you want it. But if we look at um the building, we have what the model actually looks like, what the footprint um Is so this and if you see I've i I have a spatial index on everything. I want my queries to be faster. I have a transit stop. These are points wherein I'll have different

9:47

um different transit stops uh because people will be waiting on to charge their EV and I also want say a a restaurant or a place for people to sit and eat. and district and our center line is like the road. We want to identify what the roads are in order to have EV chargers accessible to the roads Now, a question that we might come across is which buildings in the city are more than 500 meters from the nearest EV charger? So that will be a problem to solve. And for this we'll need two classes, building and the EV charger. Once we have this, now is where everything actually happens. So

10:32

uh Django already has GIS as a library, and we are going to use that in order to identify what the coverage for each of the chargers is. If you see here, I'm trying to create a union between I'm trying to merge every charger 's 500 meter service radius. That is the radius I want to solve for. So I'm trying to identify that which approximately is 0. 0045 of a buffer and gaps, the variable gaps, stores all the buildings which do not fall under my footprint intersects. This way now I have a count of buildings that sit outside of a 500 meter radius from my um

11:19

Charger radius. What this result would look like is like this. I'm identifying points which are 500 meters Across outside of my EV charger zone. And once I have this, I am now able to calculate how many of my neighborhoods are actually underserved. Neighborhoods which do not have EV charging stations. It means that even if you try and implement a electric first or promote electric vehicles. Practically on ground, it is not going to be possible. Residents do not have a way of using the car or using the vehicle at all. So there are many, this is one pattern, but there are many questions that it can solve. Look at um EV chargers and say if my radius is 500 meters.

12:05

That is through the modeling we did. I'm trying to solve where my next charger should go. It should be in a place. Even as an EV charger company, I'm trying to make money of people charging their vehicles. So I need a place which will create more revenue. I do not want to add in chargers wherein there are already a lot of charges. It's not going to make me a lot of money, especially given the cost it takes to set up an EV charger. Or grocery stores. Which block is a food desert? There are no food stores. There are a lot of neighborhoods wherein it is only you have to drive in order to go to a grocery store. So maybe opening a grocery store in a high density neighborhood is the right way for a grocery food chain. Or look at clinics.

12:51

Where is the healthcare access the weakest? Even if it is a simple, say a dentist, if there are regions wherein for like 20 miles you do not have a dentist, It is a better idea to have a dentist there as compared to a place which is like very healthcare focused already. There's like a hospital, there's urgent care, emergency room, everything, and you add in one more dentist there Of course it will serve patients, but if it was if it was like right in your neighborhood, you'll have a higher probability of going to your nearest dentist. Or parks, which residents lack nearby green space? Is there enough green space? Is there not enough green space? What is the right question? Uh you need to find what the right question is

13:36

and the same model can be applied. You're trying to find gaps. So let's look at different query patterns. So which sensors are there in this district? This is also a good way to implement things even right now as a fellow developer, even if you are not saying associated. uh with a bigger space wherein you have the access to actually implement buy sensors, play sensors, get the permits. There are a lot of sensors that the city has. So find out which sensors are there in this district for a given district boundary, which sensors, buildings, or incidents fall inside of it right now. This is the backbone of every district level dashboard. This is actually used for all emergency services.

14:24

When any kind of an emergency happens, all the emergency services services are dispatched accordingly. So it is the same predicate, uh one direction reversed, uh, which is containment, not proximity. So here I'm trying to have you think a little differently from our previous modeling. You're trying to identify That okay, I have uh sensors one to ten which give me these like four or five different categories of data. What can I make use of this data to actually serve or solve a question that I had And that is where in a point and polygon comes in place. So for every location within for a district boundary, you are trying to find out the sensors that are there.

15:09

With underscore within, you can check containment, which shape is fully inside of the other, and then compiles to an index assisted ST within and not just a Python loop So here you have a fixed boundary. It is not that you keep looping around and keep expanding your radius. You on your own have a constraint set. Of your district boundaries, say like these four coordinates. So you are fixed on this and now you're focusing on this And for every routing, you need a different tool. A lot of folks have a misconception that GeoDjango provides routing But not actually. It is a combination of GeoTjango and Post GIS that gives you spatial storage and spatial predicates in itself.

15:58

Whenever you're solving for a problem, especially say when you're if you are someone who's hearing about Geo Django for the first time through my talk, um, I would ask you to think of as a problem solver rather than wanting to use the new tech directly. So now that you know there's a district, there are these sensors, and maybe you also have like city bound um You have a city boundary and you have like buildings in it or like special access buildings or special services. And now you want to connect a particular neighborhood to um a particular neighborhood to um some service. So again you need to say propose a new road path or make a particular road as one way over having it both ways to manage traffic better

16:44

So it again is a shortest distance problem, right? It does you do not need to use a new library or function always. Be a problem solver first and make use of that rather than just trying to implement a function. So the three questions like pro anytime you think about something has to be uh within the proximity of a particular thing, think of distance LTE. If it has to be contained within, then think of within. If it is routing, then PGR digestras, which is like you're trying to implement a shortest path algorithm. Now that we've built for our particular district for our particular city, let's build for scale. So any demo can run instantly, correct, on our computers when we are working with a small set of data.

17:32

But in But for a real city, that would not be the case. So for every query that you run for 100 rows, whereas a real metro area or a real city area has like 10 million plus building footprints. At that time, you need to take care of your execution time. You cannot take a lot of time to give results, otherwise your solution is not really scalable or implementable. There is one field that helps you fix that and that is using an index right on your complete data. If you're doing it without the index, like this is the simulation I ran. So it was like 3410 milliseconds. Whereas with the index that I created for the

18:18

building footprint, it is 6. 2 milliseconds They're way apart. This is 6. 2 milliseconds is almost instant. So when somebody clicks on like get result, you're getting it instantly, which is solving the issue you had and getting the results and people are able to act upon results. And how would you know that an index that you have applied if it was on the correct geometry column or not? Because if you're especially in the learning phase and if it is a new set of data, even if You you are a domain expert for something else and this is a new domain you're trying to apply your um logic and code to. How would you know it actually worked? It is through explain analyze. So you should explain analyze to understand how it is working and uh if it is working the way you are expecting it or not.

19:06

And there will be many times when one single table would not be enough. And that time I would suggest that you Create like three logical tables, a one be time-based, one be geographic-based, and one can be a hybrid, especially for things like sensors, having a high granularity which matches real access patterns would be the way to go. And uh never ship the whole table. Uh scope out every list query to the client's current map pounds This will help you uh especially when you're building a proper uh web app or even if it is like an API response you're feeding into something else. All of this It's like a ripple effect when you're building it for scale.

19:52

So quick checklist when you're building for scale, when you move from your demo that you've tested, verified to scale For your database, use explain analyze, have your just index, and partition when you have like millions of queries. In your APIs, I would say page in it every list endpoint and simplify geometry when you are low zooming. Say when you are having like a bird's eye view, it should be simplified geometry, not too complex, so that you're able to debug On the front end, cluster dense points, instead of having like 10 points on your map, maybe have a single bigger or use color intensities, have a deeper color for like more points. a lighter color for lesser points and use vector tiles um as well.

20:42

Now how would all of this work when we're talking about handling live data? So buildings and chargers barely move, whereas uh things like traffic, air quality, flood sensors, um The reports will change constantly. And in that scenario, the spatial reasoning also needs to change So when we look at from sensor to life map, it is the spatial reasoning layer that sits on top of the stream, which becomes a bottleneck for us. And for that, having a handler which is able to take care of your latitude, longitude, which is able to create objects on the go, and based on how your objects are changing, how your results are changing, you are modifying your algorithm logic as well.

21:31

And sensors are one input among many. I have been using the example of sensors because that is the first instinct as developers we have used, especially with our hardware projects for our tinkering But there are a lot of other things. There are satellite and aerial imagery that gives you real-time insight into what geographies are changing. You'll see a lot of especially if you're um say trying to solve for greenery around a particular neighborhood or green spaces around a particular neighborhood, um satellite and aerial imagery is what will give you insights that even sensors would not give you. That is like the big eye uh the bird-eye view that you have in order to understand how regions are changing. And the more the regions change, all of the way you are analyzing data, even your results

22:20

are Places of interest will change as well. And in order to have that handoff, there is GeoJSON that you can use in order to serialize your objects based on your locations as well as your coordinates and which will serve as a native output for leaflet map map library GL and open layers So make use of different different inputs that you can use for your algorithms. You can have your sensors, your aerial imagery, and all of that Comes into the bigger picture of what the full data pipeline looks like. So we looked at all of these one by one. We have the GIS as well as the live sensors.

23:07

This live sensors is everything, not just sensors, then that goes into our Geo Django plus G post GIS and do have it indexed. That feeds into your APIs, which creates your maps and dashboards. And that leads to your decisions, your urban decisions that you want to make. The impact that this has is many. Right from mobility If you want what traffic flow analysis should be like, are there any transit accessibility scores? How can you improve the score? Infrastructure, right from utility network management, there are still areas wherein it is very dominated by one service provider, making it a very corporate-centric area which is being served, which needs to actually

23:53

change so that there are more competitors and we are not overpaying for services from environment to planning as well. I'm going to quickly glance through the end slides because I'm up on time. How all of this ties together is Is you have all your basic components together, all of that comes together in your Geojle, which creates spatial queries which you can These queries are going to help you identify different gaps, what is already contained, what isn't, what are different routes to take, which will help you create dashboards, APIs, alerts, and ultimately lead to decisions. So that you can make an informed and the correct decision. And with this, um I would say what you can build this week. Find out if you need a grocery

24:40

chain in a particular area and probably email one of the big grocery chains that have identified these gaps and this is what you should probably build your next grocery chain to be Your park equity checker, do you have uh does a particular neighborhood have access to parks? Uh are there transit gaps? Uh is there a flood risk overlay or not? And Things that you should take home from the talk today, model your space explicitly, query with the right verbs, index before you scale, and You can build this today. It is not something complex. It is think of it as a problem that you would want to solve and then make use of GeoDjango in order to solve it. And with that, thank you so much.

25:26

It was great sharing with you different use cases that I'm doing, and I would highly encourage all of you to make use of all the publicly available data we get from our cities Make use of it and build something cool today and share it with the community. Thank you.

Presenters

Conference

DjangoCon US

August 24 - 28, 2026

Chicago, Illinois, USA

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 by Drishti Jain

More videos from DjangoCon US