SlideShare a Scribd company logo
A TRAVELLER'S
GUIDE TO MAPPING
TECHNOLOGIES IN
DJANGO
Anthony I. Joseph
DjangoConAU 2018
24 August 2018
anthony.djangoconau@fastmail.com
linkedin.com/in/anthony-joseph/
This work is licensed under a Creative Commons
Attribution-NonCommercial-NoDerivs 3.0
Australia License.
Image source: http://cdn.sydneybarani.com.au/assets/1_AboriginalGroupsSydney_-Cropped.jpg
TALK OVERVIEW
1. Mapping Fundamentals
2. Storing Geospatial Data
3. Querying Geospatial Data
4. Displaying Geospatial Data
5. Future Directions
6. Q&A
1. MAPPING FUNDAMENTALS
THE BASICS
Sydney Opera House
Latitude: -33.8566
Longitude: 151.21507
But what is a co-ordinate?
A GEOGRAPHIC COORDINATE SYSTEM
3D Spherical Surface
Latitude/Longitude
Angles from a
centre point
WGS84
World Geodetic
System
SRID: 4362
GEOGRAPHIC COORDINATE SYSTEMS
Advantages
No distortions
Represent any point
Disadvantages
Complicated distance/area
calculations
Display 3D point in 2D media?
Image source: https://desktop.arcgis.com/en/arcmap/10.3/guide-
books/map-projections/about-geographic-coordinate-systems.htm
PROJECTED COORDINATE SYSTEMS
Examples:
Web Mercator
GDA94
Geocentric Datum of
Australia 1994
Advantages:
Great for display
Great for analysis*
Disadvantages:
Distorted
area/distance/shape
Image source: https://www.xkcd.com/977/
COMMON DATA FORMATS
Vector Raster
Image Sources:
- https://twitter.com/PSMA/status/1031799625831854080/photo/1
- http://www.ga.gov.au/scientific-topics/national-location-information
/digital-elevation-data
COMMON DATA TYPES: POINTS
COMMON DATA TYPES: (POLY)LINES
Data source:
https://www.smh.com.au/national/nsw/sydney-s-latte-line
exposes-a-city-divided-20180327-p4z6et.html
COMMON DATA TYPES: POLYGONS
Data source:
https://www.psma.com.au/products/administrative-
boundaries
COMMON DATA TYPES: MULTI-POLYGONS
Data source:
https://www.psma.com.au/products/administrative-
boundaries
ANALYTICAL CONCEPTS
Geocoding:
“130 George Street, Sydney”  -33.8599, 151.2090
Reverse Geocoding:
-33.8599, 151.2090 
“130 George Street, Sydney”
“Museum of Contemporary Art”
…
ANALYTICAL CONCEPTS
Geolocation
IP  Latitude/Longitude
Autocomplete
Use geolocation to suggest address
ANALYTICAL CONCEPTS
Routing:
“Opera House” 
“Museum of Contemporary
Art” by walking
Transportation modes:
Walking
Public Transport
Cycling
Driving/taxi/ridesharing
SPATIAL ANALYSIS
Image source:
- https://www.mapbox.com/use-cases/data-
visualization/
- https://www.smh.com.au/national/nsw/sydney-s-
latte-line-exposes-a-city-divided-20180327-
p4z6et.html
SPATIAL ANALYSIS - ISOCHRONES
Image source:
https://app.traveltimeplatform.com
2. STORING GEOSPATIAL DATA
GIS DATA SOURCES
Web services:
Web Map Service (WMS)
Web Coverage Services
(WCS)
Open Geospatial Consortium
File formats:
Well-known text (WKT)
Keyhole Markup (KML)
GeoJSON
ESRI ArcGIS Shapefiles
MapInfo TAB files
DATABASE ENGINES
GIS extensions to database systems
OpenGIS® Implementation Standard for Geographic
information
PostgreSQL + GIS = PostGIS
SQLite + GIS = Spatialite
…MySQL/MSSQL/OracleDB
…MongoDB
DJANGO COMPATIBILITY
Source:
https://docs.djangoproject.com/en/2
.0/ref/contrib/gis/db-api/
DATABASE FIELDS
DATA TYPE FIELD TYPE
Points PointField/MultiPointField
Lines LineStringField/
MultiLineStringField
Polygons PolygonField/MultiPolygonField
Source:
https://docs.djangoproject.com/en/2.0/ref/contrib/gis/model-api
MAP PROJECTIONS / SPATIAL REFERENCES
Default:
WGS84
SRID: 4362
geography=True
Improves query
performance on
distance queries
from django.contrib.gis.db import models
class Suburb(models.Model):
postcode = models.CharField(max_length=4)
boundary = models.PolygonField(
geography=True,
# defaults
srid=4326,
spatial_index=True,
)
SPATIAL REFERENCE SYSTEMS
Data often in WGS84
May get data in other
reference systems
Convert between systems:
Reproject – ogr2ogr
Check the metadata!
SPATIAL INDEXES
Regular DB Indexes (B-trees)
index=True
Spatial Indexes (R-tree variants)
spatial_index=True
Image sources:
https://ieftimov.com/postgresql-indexes-btree
http://revenant.ca/www/postgis/workshop/indexing.html
3. QUERYING GEOSPATIAL DATA
QUERYING DATA
qs = Model.objects.filter(
<field>__<lookup_type>=<param>
)
Complete list: https://docs.djangoproject.com/en
/2.0/ref/contrib/gis/geoquerysets/
QUERYSETS: POINT IN POLYGON
Example model Example query
class Suburb(models.Model):
postcode = models.CharField()
boundary = models.PolygonField()
pnt = GEOSGeometry('POINT(151.178 -33.884)’,
srid=4326)
qs = Suburb.objects.filter(
boundary__contains=pnt)
QUERYSETS: WITHIN DISTANCE (2KM)
Example model Example query
class Store(models.Model):
name = models.CharField()
location = models.PointField()
from django.contrib.gis.measure import
D
pnt = GEOSGeometry('POINT(151.196 -33.870)’,
srid=4326)
qs = Store.objects.filter(
location__dwithin=(pnt, D(m=2000)))
)
QUERYSETS: SORT BY DISTANCE
Example model Example query
class Store(models.Model):
name = models.CharField()
location = models.PointField()
from django.contrib.gis.db.models.functions
import Distance
usr = GEOSGeometry('POINT(151.178 -33.884)’,
srid=4326)
qs = Store.objects.annotate(
distance=Distance(‘location',listing.point)
).order_by('distance')
1
2
3
GEOSPATIAL DATABASE FUNCTIONS
https://docs.djangoproject.com/en/2.0/ref/contrib/gis/functions/
4. DISPLAYING GEOSPATIAL DATA
REQUIREMENTS
>Spatial data (already have this!)
>A web mapping library
>Base maps
WEB MAPPING LIBRARIES
>Javascript-based
>Examples:
>Openlayers
>Leaflet/Mapbox
>Google Maps
>Mobile SDKs for native apps
BASE MAPS
>Tile-based imagery
>Graphics: Google Maps / Mapbox / OpenStreetMap /
ArcGIS …
>Satellite imagery: DigitalGlobe / Nearmap / US Gov (NASA
etc)
>URL formats:
>https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png
BASE MAP EXAMPLES
Apple Maps Google Maps
(Satellite)
Google
Maps
HERE Maps Mapbox
Maps
SIMPLE EXAMPLE
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet” href="https://unpkg.com/leaflet
@1.3.3/dist/leaflet.css" />
<script src="https://unpkg.com/leaflet@1.3.3 /dist/leaflet.js"></script>
</head>
<body>
<div id="map" style="width: 600px; height:
400px;"></div>
<script>
var map = L.map('map').setView([-33.8733, 151.1991],
19);
L.tileLayer(
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png’
,{attribution: 'OpenStreetMap contributors’}
).addTo(map);
L.marker([-33.8733, 151.1991]).addTo(map)
.bindPopup('You are here.')
.openPopup();
</script>
</body>
</html>
SIMPLE EXAMPLE
Web maps automatically
reproject:
>from WGS84
(geographical coordinate
system),
>to Web Mercator
(projected coordinate
system)
FORMS API
DATA TYPE FIELD TYPE
Points PointField/MultiPointField
Lines LineStringField/
MultiLineStringField
Polygons PolygonField/MultiPolygonField
Source:
https://docs.djangoproject.com/en/2.1/ref/contrib/gis/forms-api/
5. FUTURE DIRECTIONS
RELATED TECHNOLOGIES
Offline analysis:
QGIS/ArcGIS
Tableau/PowerBI
GeoMesa: big data for spatial
WebGL Maps
Mobile:
3D graphics (Unity)
Augmented/Virtual Reality
Image source: https://www.mapbox.com/augmented-reality/
DATA SOURCES
Open data
data.gov.au
Government data
PSMA: psma.com.au
Buildings API
Commercial data
MaxMind/ip2location
Check licences!
NEW AUSTRALIAN DATUM
Currently use GDA94 (EPSG
4939)
Geosciences Australian
developing GDA2020 (EPSG
7844)
Affects Australian government
data
May need to reproject data
Image source: http://www.ga.gov.au/scientific-
topics/positioning-navigation/datum-
modernisation
KEY TAKEAWAY
POINTS
The official docs are great:
don’t forget to use them!
Make use of existing
libraries/3rd party services:
“don’t roll your own crypto”!
Be careful of:
• coordinate systems
• licences
• coverage
Geospatial analysis is a lot
like statistics: easy to do
something that looks
correct, but has underlying
issues. Question assumptions and
check metadata

More Related Content

PPTX
Big Spatial(!) Data Processing mit GeoMesa. AGIT 2019, Salzburg, Austria.
PDF
AlphaEarth Foundations and the Satellite Embedding dataset
PDF
A new method of gridding for spot detection in microarray images
PDF
A new method of gridding for spot detection in microarray images
PDF
GeoDjango & HTML5 Geolocation
PPT
Gis Concepts 5/5
PDF
2017 RM-URISA Track: Spatial SQL - The Best Kept Secret in the Geospatial World
PPT
Using geobrowsers for thematic mapping
Big Spatial(!) Data Processing mit GeoMesa. AGIT 2019, Salzburg, Austria.
AlphaEarth Foundations and the Satellite Embedding dataset
A new method of gridding for spot detection in microarray images
A new method of gridding for spot detection in microarray images
GeoDjango & HTML5 Geolocation
Gis Concepts 5/5
2017 RM-URISA Track: Spatial SQL - The Best Kept Secret in the Geospatial World
Using geobrowsers for thematic mapping

Similar to A travellers guide to mapping technologies in django (20)

PPTX
Horizon DTC Integrator Event
PDF
Recod @ MediaEval 2014: Diverse Social Images Retrieval
PDF
A framework for outlier detection in
PDF
3 video segmentation
PDF
project report final
PPT
Wolfgang | Bikeability Workshop December 2010
PDF
10. Getting Spatial
 
PDF
Kk3517971799
PPTX
Anton Korsakov - Determination of an unmanned mobile object orientation by na...
PDF
Mining interesting locations and travel sequences from gps trajectories
PPTX
GeoMeetup kickoff meeting - Overview of Geospatial Landscape
PDF
Survey of indoor tracking systems using augmented reality
PDF
Hotspot Analysis - OGRS2016
PDF
Presentation for OGRS 2016 at Peruggia, Italy
PDF
Introducing Spatial Coverage in a Semantic Repository Model - Phd defence
PPTX
Final thesis presentation
PDF
PCA and Classification
PDF
Open geo data - technical issue
PPTX
EDBT 2015: Summer School Overview
PPT
3D Visibility with Vector GIS Data
Horizon DTC Integrator Event
Recod @ MediaEval 2014: Diverse Social Images Retrieval
A framework for outlier detection in
3 video segmentation
project report final
Wolfgang | Bikeability Workshop December 2010
10. Getting Spatial
 
Kk3517971799
Anton Korsakov - Determination of an unmanned mobile object orientation by na...
Mining interesting locations and travel sequences from gps trajectories
GeoMeetup kickoff meeting - Overview of Geospatial Landscape
Survey of indoor tracking systems using augmented reality
Hotspot Analysis - OGRS2016
Presentation for OGRS 2016 at Peruggia, Italy
Introducing Spatial Coverage in a Semantic Repository Model - Phd defence
Final thesis presentation
PCA and Classification
Open geo data - technical issue
EDBT 2015: Summer School Overview
3D Visibility with Vector GIS Data
Ad

Recently uploaded (20)

PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
Big Data Technologies - Introduction.pptx
PPTX
Spectroscopy.pptx food analysis technology
PDF
Approach and Philosophy of On baking technology
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
sap open course for s4hana steps from ECC to s4
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
NewMind AI Weekly Chronicles - August'25-Week II
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Spectral efficient network and resource selection model in 5G networks
Reach Out and Touch Someone: Haptics and Empathic Computing
Assigned Numbers - 2025 - Bluetooth® Document
A comparative analysis of optical character recognition models for extracting...
gpt5_lecture_notes_comprehensive_20250812015547.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Network Security Unit 5.pdf for BCA BBA.
20250228 LYD VKU AI Blended-Learning.pptx
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Big Data Technologies - Introduction.pptx
Spectroscopy.pptx food analysis technology
Approach and Philosophy of On baking technology
Programs and apps: productivity, graphics, security and other tools
sap open course for s4hana steps from ECC to s4
MYSQL Presentation for SQL database connectivity
Unlocking AI with Model Context Protocol (MCP)
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Review of recent advances in non-invasive hemoglobin estimation
NewMind AI Weekly Chronicles - August'25-Week II
Ad

A travellers guide to mapping technologies in django

  • 1. A TRAVELLER'S GUIDE TO MAPPING TECHNOLOGIES IN DJANGO Anthony I. Joseph DjangoConAU 2018 24 August 2018 anthony.djangoconau@fastmail.com linkedin.com/in/anthony-joseph/ This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Australia License.
  • 3. TALK OVERVIEW 1. Mapping Fundamentals 2. Storing Geospatial Data 3. Querying Geospatial Data 4. Displaying Geospatial Data 5. Future Directions 6. Q&A
  • 5. THE BASICS Sydney Opera House Latitude: -33.8566 Longitude: 151.21507 But what is a co-ordinate?
  • 6. A GEOGRAPHIC COORDINATE SYSTEM 3D Spherical Surface Latitude/Longitude Angles from a centre point WGS84 World Geodetic System SRID: 4362
  • 7. GEOGRAPHIC COORDINATE SYSTEMS Advantages No distortions Represent any point Disadvantages Complicated distance/area calculations Display 3D point in 2D media? Image source: https://desktop.arcgis.com/en/arcmap/10.3/guide- books/map-projections/about-geographic-coordinate-systems.htm
  • 8. PROJECTED COORDINATE SYSTEMS Examples: Web Mercator GDA94 Geocentric Datum of Australia 1994 Advantages: Great for display Great for analysis* Disadvantages: Distorted area/distance/shape Image source: https://www.xkcd.com/977/
  • 9. COMMON DATA FORMATS Vector Raster Image Sources: - https://twitter.com/PSMA/status/1031799625831854080/photo/1 - http://www.ga.gov.au/scientific-topics/national-location-information /digital-elevation-data
  • 11. COMMON DATA TYPES: (POLY)LINES Data source: https://www.smh.com.au/national/nsw/sydney-s-latte-line exposes-a-city-divided-20180327-p4z6et.html
  • 12. COMMON DATA TYPES: POLYGONS Data source: https://www.psma.com.au/products/administrative- boundaries
  • 13. COMMON DATA TYPES: MULTI-POLYGONS Data source: https://www.psma.com.au/products/administrative- boundaries
  • 14. ANALYTICAL CONCEPTS Geocoding: “130 George Street, Sydney”  -33.8599, 151.2090 Reverse Geocoding: -33.8599, 151.2090  “130 George Street, Sydney” “Museum of Contemporary Art” …
  • 15. ANALYTICAL CONCEPTS Geolocation IP  Latitude/Longitude Autocomplete Use geolocation to suggest address
  • 16. ANALYTICAL CONCEPTS Routing: “Opera House”  “Museum of Contemporary Art” by walking Transportation modes: Walking Public Transport Cycling Driving/taxi/ridesharing
  • 17. SPATIAL ANALYSIS Image source: - https://www.mapbox.com/use-cases/data- visualization/ - https://www.smh.com.au/national/nsw/sydney-s- latte-line-exposes-a-city-divided-20180327- p4z6et.html
  • 18. SPATIAL ANALYSIS - ISOCHRONES Image source: https://app.traveltimeplatform.com
  • 20. GIS DATA SOURCES Web services: Web Map Service (WMS) Web Coverage Services (WCS) Open Geospatial Consortium File formats: Well-known text (WKT) Keyhole Markup (KML) GeoJSON ESRI ArcGIS Shapefiles MapInfo TAB files
  • 21. DATABASE ENGINES GIS extensions to database systems OpenGIS® Implementation Standard for Geographic information PostgreSQL + GIS = PostGIS SQLite + GIS = Spatialite …MySQL/MSSQL/OracleDB …MongoDB
  • 23. DATABASE FIELDS DATA TYPE FIELD TYPE Points PointField/MultiPointField Lines LineStringField/ MultiLineStringField Polygons PolygonField/MultiPolygonField Source: https://docs.djangoproject.com/en/2.0/ref/contrib/gis/model-api
  • 24. MAP PROJECTIONS / SPATIAL REFERENCES Default: WGS84 SRID: 4362 geography=True Improves query performance on distance queries from django.contrib.gis.db import models class Suburb(models.Model): postcode = models.CharField(max_length=4) boundary = models.PolygonField( geography=True, # defaults srid=4326, spatial_index=True, )
  • 25. SPATIAL REFERENCE SYSTEMS Data often in WGS84 May get data in other reference systems Convert between systems: Reproject – ogr2ogr Check the metadata!
  • 26. SPATIAL INDEXES Regular DB Indexes (B-trees) index=True Spatial Indexes (R-tree variants) spatial_index=True Image sources: https://ieftimov.com/postgresql-indexes-btree http://revenant.ca/www/postgis/workshop/indexing.html
  • 28. QUERYING DATA qs = Model.objects.filter( <field>__<lookup_type>=<param> ) Complete list: https://docs.djangoproject.com/en /2.0/ref/contrib/gis/geoquerysets/
  • 29. QUERYSETS: POINT IN POLYGON Example model Example query class Suburb(models.Model): postcode = models.CharField() boundary = models.PolygonField() pnt = GEOSGeometry('POINT(151.178 -33.884)’, srid=4326) qs = Suburb.objects.filter( boundary__contains=pnt)
  • 30. QUERYSETS: WITHIN DISTANCE (2KM) Example model Example query class Store(models.Model): name = models.CharField() location = models.PointField() from django.contrib.gis.measure import D pnt = GEOSGeometry('POINT(151.196 -33.870)’, srid=4326) qs = Store.objects.filter( location__dwithin=(pnt, D(m=2000))) )
  • 31. QUERYSETS: SORT BY DISTANCE Example model Example query class Store(models.Model): name = models.CharField() location = models.PointField() from django.contrib.gis.db.models.functions import Distance usr = GEOSGeometry('POINT(151.178 -33.884)’, srid=4326) qs = Store.objects.annotate( distance=Distance(‘location',listing.point) ).order_by('distance') 1 2 3
  • 34. REQUIREMENTS >Spatial data (already have this!) >A web mapping library >Base maps
  • 36. BASE MAPS >Tile-based imagery >Graphics: Google Maps / Mapbox / OpenStreetMap / ArcGIS … >Satellite imagery: DigitalGlobe / Nearmap / US Gov (NASA etc) >URL formats: >https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png
  • 37. BASE MAP EXAMPLES Apple Maps Google Maps (Satellite) Google Maps HERE Maps Mapbox Maps
  • 38. SIMPLE EXAMPLE <!DOCTYPE html> <html> <head> <link rel="stylesheet” href="https://unpkg.com/leaflet @1.3.3/dist/leaflet.css" /> <script src="https://unpkg.com/leaflet@1.3.3 /dist/leaflet.js"></script> </head> <body> <div id="map" style="width: 600px; height: 400px;"></div> <script> var map = L.map('map').setView([-33.8733, 151.1991], 19); L.tileLayer( 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png’ ,{attribution: 'OpenStreetMap contributors’} ).addTo(map); L.marker([-33.8733, 151.1991]).addTo(map) .bindPopup('You are here.') .openPopup(); </script> </body> </html>
  • 39. SIMPLE EXAMPLE Web maps automatically reproject: >from WGS84 (geographical coordinate system), >to Web Mercator (projected coordinate system)
  • 40. FORMS API DATA TYPE FIELD TYPE Points PointField/MultiPointField Lines LineStringField/ MultiLineStringField Polygons PolygonField/MultiPolygonField Source: https://docs.djangoproject.com/en/2.1/ref/contrib/gis/forms-api/
  • 42. RELATED TECHNOLOGIES Offline analysis: QGIS/ArcGIS Tableau/PowerBI GeoMesa: big data for spatial WebGL Maps Mobile: 3D graphics (Unity) Augmented/Virtual Reality Image source: https://www.mapbox.com/augmented-reality/
  • 43. DATA SOURCES Open data data.gov.au Government data PSMA: psma.com.au Buildings API Commercial data MaxMind/ip2location Check licences!
  • 44. NEW AUSTRALIAN DATUM Currently use GDA94 (EPSG 4939) Geosciences Australian developing GDA2020 (EPSG 7844) Affects Australian government data May need to reproject data Image source: http://www.ga.gov.au/scientific- topics/positioning-navigation/datum- modernisation
  • 45. KEY TAKEAWAY POINTS The official docs are great: don’t forget to use them! Make use of existing libraries/3rd party services: “don’t roll your own crypto”! Be careful of: • coordinate systems • licences • coverage Geospatial analysis is a lot like statistics: easy to do something that looks correct, but has underlying issues. Question assumptions and check metadata