Geo-Spatial Rest Backend using GeoDjango

What is GIS?

 

  • Store geo information in layer
  • Operation on map data can be
    • create
    •  manipulated
    • analyzed
    • visualized

Geographic Map Data

+

Map Analysis and Queries

What is Geospatial?

  • Geospatial is used to define the collective data and  associated technology has a geographic or locational component.
  • The system leverages well known services for map data.

  • If we summarise GIS and GeoSpatial, geo spatial is GIS - the whole map data.

Only Map Analysis and Queries

We would use below stack...

  • Python
  • Django
  • Django Rest Framework
  • Postgres (with postgis extension)

Spatial Reference System ID(SRID)

  • Every geometric shape has a spatial reference system associated with it
  • It specifies which units (degrees/metres) are going to be used to represent the geometry types.
  • We are going to use SRID 4326

* Measuring Unit for geographical points like we measure liquid in litres, m, solid kg 

...a small caveat

  • Longitude is x
  • Latitude is y
  • ...not the other way around

(30,15)

Geometry Types

  • Point
  • LineString
  • Polygon

Simple Types

Collection Types

  • MultiPoint
  • MultiLineString
  • MultiPolygon
  • GeometryCollection

Geometries Representations

  • GeoJson
  • Geographic Mark-up Language
<gml:Point gml:id="p21" srsName="http://www.opengis.net/def/crs/EPSG/0/4326">
    <gml:coordinates>45.67, 88.56</gml:coordinates>
 </gml:Point>
  • Well Known Text (WKT) - 

"POINT (30 10)"

"LINESTRING (30 10, 10 30, 40 40)"

"POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))"

Point as GeoJson

Linestring as GeoJson

Polygon as GeoJson

Our System Architecture

Geos API

  • GEOS stands for Geometry Engine - Open Source
  • GeoDjango has its own implementation of the GEOS library.
  • The geometries are defined in django.contrib.gis.geos module. e.g.
    • Point(5, 23)
    • LineString((0, 0), (0, 50), (50, 50), (50, 0), (0, 0))
    • Polygon( ((0.0, 0.0), (0.0, 50.0), (50.0, 50.0), (50.0, 0.0), (0.0, 0.0)) )

GEOS Predicate Functions

.contains

  • It checks if a geometry is inside another geometry.
  • Invoked as geometry1.contains(geometry2)

GEOS Predicate Functions

...others

  • .covers(geom)
  • .intersects(geom)
  • .touches(geom)

GEOS methods & properties

.distance

  • Returns the distance between the closest point in this geometry and the other geometry
  • Invoked as geometry1.distance(geometry2)

...others

GEOS methods & properties

  • .area
  • .extent
  • .length
  • .transform(900913, clone=True)

GIS ORM (QuerySet) API

contains

Factory.objects.filter(geofence__contains=geom)

intersects

GIS ORM (QuerySet) API

Factory.objects.filter(geofence__intersects=geom)

GIS ORM (QuerySet) API

...others

  • overlaps

  • bboverlaps

  • bbcontains

  • etc.

Thank You

Copy of Geo-Spatial REST Service using GeoDjango

By gaurav porwal

Copy of Geo-Spatial REST Service using GeoDjango

  • 157