We're sorry but this page doesn't work properly without JavaScript enabled. Please enable it to continue.
Feedback

Creating GIS Rest APIS using Geodjango under 30 minutes

00:00

Formal Metadata

Title
Creating GIS Rest APIS using Geodjango under 30 minutes
Title of Series
Number of Parts
156
Author
License
CC Attribution 3.0 Unported:
You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal purpose as long as the work is attributed to the author in the manner specified by the author or licensor.
Identifiers
Publisher
Release Date
Language

Content Metadata

Subject Area
Genre
Abstract
We're living in the world of APIs. CRUD operations are base of lot of operations. Many smart frameworks such as Django, Flask, Laravel provides out of the box solutions to filter the data, which covers almost all needs to separate data based on column values. When it comes to Geospatial data, we expect to filter data based on their location property instead of metadata. This is where things get complicated, if you are using framework that doesn't have package, library built to handle such use cases, you are likely to be dependent on either database or any external package to handle it. Fortunately Geodjango (Django's extension) allows us to create databases which understands geometry and can process it. It also provides support to write APIs using Rest Framework extension which takes this to next level allowing user to output the data in various formats, creating paginations inside geojson, create TMSTileFilters, etc. In this talk we'll scratch the surface of this python package and see how to build basic CRUD APIs to push, pull GIS data along with filtering it to the PostgreSQL database.
Keywords
127
Process (computing)Streaming mediaOrder (biology)Maxima and minima
Representational state transferSoftware frameworkInformation securityScale (map)Field extensionBuildingTable (information)Content (media)Library (computing)Logic gateData modelTemplate (C++)Representational state transferComputer fileMobile appDatabaseSet (mathematics)Software frameworkProjective planeSoftware architectureLine (geometry)Point (geometry)Endliche ModelltheoriePolygonSystem administratorDebuggerInstallation artDialectComplete metric spaceLogicCartesian coordinate systemOrder (biology)CASE <Informatik>Extension (kinesiology)GeometryField (computer science)Generic programmingComputer animation
File formatComputer animation
BuildingInformation securitySoftware frameworkComa BerenicesLimit (category theory)Representational state transferSoftware frameworkEndliche ModelltheorieMobile appFile formatCASE <Informatik>Serial portView (database)Computer animationLecture/Conference
Computer iconRootView (database)AxiomOpticsDisk read-and-write headLocal ringRepresentational state transferSoftware frameworkCountingElectronic mailing listRepresentational state transferComputer animation
Field extensionSoftware frameworkSoftware frameworkRepresentational state transferComputer animation
Electronic mailing listDisk read-and-write headOpticsData typeGeometryFile formatComputer animation
Game theoryGeometryRepresentational state transferSoftware frameworkMobile appFile formatField (computer science)GeometryComputer animation
Electronic mailing listContent (media)Point (geometry)File formatMultiplication signComputer animationLecture/Conference
Price indexLogic gateInstallation artPolygonSoftware frameworkGeometryCuboidMultiplicationPoint (geometry)Buffer solutionDefault (computer science)Functional (mathematics)Representational state transfer
Default (computer science)File formatCuboidComputer animation
Level (video gaming)Default (computer science)CuboidComputer animation
Least squaresComputer-assisted translationComputer animation
Transcript: English(auto-generated)
So, this is originally a 30-minute stop, but we'll try to wrap it up under five minutes. So the aim over here is that what is the minimum setup that we need in order to create special REST APIs based on the data that we have. And the flavor of Python that we are going to use over here or the framework would be Django.
So, we are going to see what is Django, what is your Django, then Django REST framework, and finally we'll end by Django REST framework GIS. So, Django, it's quite a famous framework if you want to create the complete application, and it's very easy to get started. You just start the project and just like, so in Django, essentially you build each
of your business logic as an individual app. You can also connect your database. In this case, I have connected a PostGIS since I want to do geospatial stuff with it. And then that's all. Once you run the Django, you will get a nice UI and also you'll get an admin panel that
you can do a lot of things with. Next thing that we are adding to our stack is GeoDjango, which is an extension of Django which understands GIS. So it is built with GDAL, PostGIS, Proj, Geospatialite, and OSGO 4W. So the way we start using it is by simply mentioning that we want to use Django in
install apps in the settings.py file. And if you're on M architecture, you might have to add some more settings to it as well. And then that's all. Then you can start creating your models and you can specify what kind of geometry you want to store. It can be point, line, polygon, or it can be a generic geometry field as well.
And then you can just get your data in the front end and you can use things such as like city.geometry.x and ny to get lat and long. And if you want to get a WKT, you can also get a WKT back. And there you go. So by adding GeoDjango, we can actually store the data in GIS format and also use
the data from GIS format. Next thing we are looking at is a Django REST framework, which allows us to actually get the data from our model in a serialized format. So straightforward, you just do installation, again, visit back installed apps and add REST framework over there.
Then once you create a serializer, in our case for cities and then just mention it in the views, you have a running and working REST API for you, which will allow you to get the complete data or get a specific city by sending ID.
And you can also do things such as post, put, delete. And last, I would like to wind up with introducing Django REST framework. So the very important thing that it will bring to us is that over here, as you can see that the geometry is in a WKT format, but if we use, and also for me to post the data, I have to send it as a WKT. But by adding Django REST framework GIS into installed apps and just mentioning that what
is the field that is going to be geometry, I can get the data back in a GeoJSON format. There are multiple filters that we get in it. I'm not really sure if we have time. So we do get multiple filters by default with Django REST framework, such as we can
actually filter our data by passing bounding box or we can also create the geometry on the fly. So let's say if you don't have a special data but you have lat and long as a separate column, you can actually create the geometry on the fly. You can also use various functions available.
So for example over here, I had a geometry as a point but I wanted to show it as a buffer as a polygon. And yeah, you can do that. And there you go. So you can actually see the data in a GeoJSON format and then you can also filter the data. So as I said, you can do it with bounding box filter where you can just send the bounding box.
You can also do TMS style filter where you can actually send the Z, X and Y and then that's all. Thank you.