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

Source: https://djangotv.com/videos/djangocon-us/2026/geodjango-at-city-scale-spatial-data-for-urban-systems-with-drishti-jain/
Date: 2026-10-26
Speakers: Drishti Jain
Text: lightly edited for readability (verbatim on the page)

## Transcript

[00:14] So today we are going to talk about something 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 Jain. 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 agentic 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 solutions which do not require a technical solution in the first place.

[01: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, our biggest power is sharing knowledge that we gain. And in this fast-moving world of AI, 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 adopting something that's just new for the sake of it.

[01:47] So I would also encourage all of you to 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 make from there on get wrong. All city systems run on spatial questions. If a data model cannot answer them natively, teams write slow, bug-prone code. And even if there's a one-off difference in the geometry code, people are relying on the answers you give out of your systems, and that can all be wrong.

[02:35] Right from considering 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 actually driving an EV around, that is not right. It is not equitable infrastructure. The environmental risk: Which buildings sit inside a floodplain? With time, with the climate changing around us, flood maps change as well. If we do not 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 them, and we are not helping out regions which actually need it in case of a flood.

[03: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 GeoDjango 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: Django plus GeoDjango, 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...

[04: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 an ORM that speaks geometry. So things like within, intersects. 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 built-in functions we'll be looking at later on in the hands-on as well. And PostGIS underneath 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...

[05:09] ...within which the numbers are written. If we look at this, if I'm building out a point field, 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 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 longitude, latitude. So that is an interesting point to note, especially people who are getting started with GeoDjango...

[05:55] ...in the first place tend to swap these numbers because we have been learning about systems as latitude, comma, longitude, 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 represent your sensors, transit stops, and, say, EV chargers, these are point systems that you are trying to identify. So they can be shaped directly as a point. So your location can be a model's point field. For roads, transit routes, pipelines...

[06:40] ...this includes any and everything: your water pipeline, your 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 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. And it is like a book's index, but for shapes. So instead of reading every page in Post...

[07:27] ...GIS, you can jump straight to the handful of geometries that could possibly match. 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. 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.

[08:16] So things like within—the PostGIS function is called ST_Within. 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: if there are any shared points. 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...

[09:02] Now that we have a quick vocabulary of all 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 parameters as and when you want it. But if we look at the building, we have what the model actually looks like, what the footprint is. So this—and if you see, 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...

[09:47] ...different transit stops because people will be waiting to charge their EV, and I also want, say, 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] ...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...

[11:19] ...charger radius. What this result would look like is like this. I'm identifying points which are 500 meters 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 an electric-first approach or promote electric vehicles, practically on the 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 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 off 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 chargers. 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 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 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 already very healthcare-focused. There's 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 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? 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. 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 associated with a bigger space where you have access to actually implement, buy sensors, place sensors, and 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 emergency happens, all the emergency services are dispatched accordingly. So it is the same predicate, one direction reversed, 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 sensors one to ten which give me these 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 a point and polygon come into place. So for every location within a district boundary, you are trying to find out the sensors that are there.

[15:09] With `__within`, you can check containment: which shape is fully inside of the other. It compiles to an index-assisted ST_Within, 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 have a constraint set of your district boundaries, say, 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 GeoDjango and PostGIS that gives you spatial storage and spatial predicates in itself.

[15:58] Whenever you're solving a problem, especially if you are someone who's hearing about GeoDjango for the first time through my talk, I would ask you to think of yourself 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 a city boundary, and you have buildings in it or special-access buildings or special services. And now you want to connect a particular neighborhood to some service. So again, you need to propose a new road path or make a particular road one-way rather than having it both ways to manage traffic better.

[16:44] So it again is a shortest-distance problem, right? 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: Whenever you think about something that has to be 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 pgRouting's Dijkstra, 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 for a real city, that would not be the case. For every query that you run for 100 rows, whereas a real metro area or a real city area has 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 in this simulation I ran, it was 3,410 milliseconds. Whereas with the index that I created for the

[18:18] building footprint, it is 6.2 milliseconds. They're way apart. 6.2 milliseconds is almost instant. So when somebody clicks on “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 them. And how would you know that an index that you have applied was on the correct geometry column or not? Because if you're especially in the learning phase and it is a new set of data, even if you are a domain expert for something else and this is a new domain you're trying to apply your logic and code to, how would you know it actually worked? It is through EXPLAIN ANALYZE. So you should use EXPLAIN ANALYZE to understand how it is working and 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 at that time, I would suggest that you create three logical tables: one time-based, one geographic-based, and one hybrid. Especially for things like sensors, having a high granularity that matches real access patterns would be the way to go. And never ship the whole table. Scope out every list query to the client's current map bounds. This will help you, especially when you're building a proper web app, or even if it is an API response you're feeding into something else. All of this is like a ripple effect when you're building it for scale.

[19:52] So, a quick checklist when you're building for scale, when you move from your demo that you've tested and verified to scale: For your database, use EXPLAIN ANALYZE, have your GiST index, and partition when you have millions of queries. In your APIs, I would say paginate every list endpoint and simplify geometry when you're zoomed out. Say, when you are having 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 10 points on your map, maybe have a single bigger one or use color intensities: a deeper color for more points, a lighter color for fewer points. And use vector tiles as well.

[20:42] Now, how would all of this work when we're talking about handling live data? Buildings and chargers barely move, whereas things like traffic, air quality, flood sensors, and reports will change constantly. And in that scenario, the spatial reasoning also needs to change. So when we look at it from sensor to live 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 and longitude, which is able to create objects on the go, and, based on how your objects are changing and 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, especially if you're trying to solve for greenery around a particular neighborhood or green spaces around a particular neighborhood. Satellite and aerial imagery is what will give you insights that even sensors would not give you. That is the big eye, the bird's-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] or 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, which will serve as a native output for Leaflet map library, GL, and OpenLayers. So make use of 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] These live sensors are everything, not just sensors. Then that goes into our GeoDjango plus PostGIS, and you do have it indexed. That feeds into your APIs, which create 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 to know 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 you have all your basic components together. All of that comes together in your GeoDjango, which creates spatial queries which you can. These queries are going to help you identify different gaps: what is already contained, what isn't, and what are different routes to take. This will help you create dashboards, APIs, and alerts, and ultimately lead to decisions, so that you can make an informed and correct decision. And with this, 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 say this is what you should probably build your next grocery chain to be. Your park equity checker: does a particular neighborhood have access to parks? Are there transit gaps? 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. 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.
