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

Similar to A travellers guide to mapping technologies in django

Recod @ MediaEval 2014: Diverse Social Images Retrieval
Recod @ MediaEval 2014: Diverse Social Images RetrievalRecod @ MediaEval 2014: Diverse Social Images Retrieval
Recod @ MediaEval 2014: Diverse Social Images Retrieval
multimediaeval
 
A framework for outlier detection in
A framework for outlier detection inA framework for outlier detection in
A framework for outlier detection in
ijfcstjournal
 
Wolfgang | Bikeability Workshop December 2010
Wolfgang | Bikeability Workshop December 2010Wolfgang | Bikeability Workshop December 2010
Wolfgang | Bikeability Workshop December 2010Morten Meyer
 
10. Getting Spatial
10. Getting Spatial10. Getting Spatial
10. Getting Spatial
FAO
 
Kk3517971799
Kk3517971799Kk3517971799
Kk3517971799
IJERA Editor
 
Anton Korsakov - Determination of an unmanned mobile object orientation by na...
Anton Korsakov - Determination of an unmanned mobile object orientation by na...Anton Korsakov - Determination of an unmanned mobile object orientation by na...
Anton Korsakov - Determination of an unmanned mobile object orientation by na...
AIST
 
Mining interesting locations and travel sequences from gps trajectories
Mining interesting locations and travel sequences from gps trajectoriesMining interesting locations and travel sequences from gps trajectories
Mining interesting locations and travel sequences from gps trajectories
HopeBay Technologies, Inc.
 
GeoMeetup kickoff meeting - Overview of Geospatial Landscape
GeoMeetup kickoff meeting - Overview of Geospatial LandscapeGeoMeetup kickoff meeting - Overview of Geospatial Landscape
GeoMeetup kickoff meeting - Overview of Geospatial Landscape
Ragi Burhum Espinoza
 
Survey of indoor tracking systems using augmented reality
Survey of indoor tracking systems using augmented realitySurvey of indoor tracking systems using augmented reality
Survey of indoor tracking systems using augmented reality
IAESIJAI
 
Hotspot Analysis - OGRS2016
Hotspot Analysis - OGRS2016Hotspot Analysis - OGRS2016
Hotspot Analysis - OGRS2016
Daniele Oxoli
 
Presentation for OGRS 2016 at Peruggia, Italy
Presentation for OGRS 2016 at Peruggia, ItalyPresentation for OGRS 2016 at Peruggia, Italy
Presentation for OGRS 2016 at Peruggia, Italy
Mayra Zurbaran
 
Introducing Spatial Coverage in a Semantic Repository Model - Phd defence
Introducing Spatial Coverage in a Semantic Repository Model - Phd defence Introducing Spatial Coverage in a Semantic Repository Model - Phd defence
Introducing Spatial Coverage in a Semantic Repository Model - Phd defence
Camille Tardy
 
Final thesis presentation
Final thesis presentationFinal thesis presentation
Final thesis presentation
Pawan Singh
 
PCA and Classification
PCA and ClassificationPCA and Classification
PCA and ClassificationFatwa Ramdani
 
Open geo data - technical issue
Open geo data  - technical issueOpen geo data  - technical issue
Open geo data - technical issue
Maurizio Napolitano
 
EDBT 2015: Summer School Overview
EDBT 2015: Summer School OverviewEDBT 2015: Summer School Overview
EDBT 2015: Summer School Overview
dgarijo
 
3D Visibility with Vector GIS Data
3D Visibility with Vector GIS Data3D Visibility with Vector GIS Data
3D Visibility with Vector GIS Data
Wassim Suleiman
 
Spatial is Not Special ?
Spatial is Not Special ?Spatial is Not Special ?
Spatial is Not Special ?
Maurizio Napolitano
 

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

Recod @ MediaEval 2014: Diverse Social Images Retrieval
Recod @ MediaEval 2014: Diverse Social Images RetrievalRecod @ MediaEval 2014: Diverse Social Images Retrieval
Recod @ MediaEval 2014: Diverse Social Images Retrieval
 
A framework for outlier detection in
A framework for outlier detection inA framework for outlier detection in
A framework for outlier detection in
 
3 video segmentation
3 video segmentation3 video segmentation
3 video segmentation
 
project report final
project report finalproject report final
project report final
 
Wolfgang | Bikeability Workshop December 2010
Wolfgang | Bikeability Workshop December 2010Wolfgang | Bikeability Workshop December 2010
Wolfgang | Bikeability Workshop December 2010
 
10. Getting Spatial
10. Getting Spatial10. Getting Spatial
10. Getting Spatial
 
Kk3517971799
Kk3517971799Kk3517971799
Kk3517971799
 
Anton Korsakov - Determination of an unmanned mobile object orientation by na...
Anton Korsakov - Determination of an unmanned mobile object orientation by na...Anton Korsakov - Determination of an unmanned mobile object orientation by na...
Anton Korsakov - Determination of an unmanned mobile object orientation by na...
 
Mining interesting locations and travel sequences from gps trajectories
Mining interesting locations and travel sequences from gps trajectoriesMining interesting locations and travel sequences from gps trajectories
Mining interesting locations and travel sequences from gps trajectories
 
GeoMeetup kickoff meeting - Overview of Geospatial Landscape
GeoMeetup kickoff meeting - Overview of Geospatial LandscapeGeoMeetup kickoff meeting - Overview of Geospatial Landscape
GeoMeetup kickoff meeting - Overview of Geospatial Landscape
 
Survey of indoor tracking systems using augmented reality
Survey of indoor tracking systems using augmented realitySurvey of indoor tracking systems using augmented reality
Survey of indoor tracking systems using augmented reality
 
Hotspot Analysis - OGRS2016
Hotspot Analysis - OGRS2016Hotspot Analysis - OGRS2016
Hotspot Analysis - OGRS2016
 
Presentation for OGRS 2016 at Peruggia, Italy
Presentation for OGRS 2016 at Peruggia, ItalyPresentation for OGRS 2016 at Peruggia, Italy
Presentation for OGRS 2016 at Peruggia, Italy
 
Introducing Spatial Coverage in a Semantic Repository Model - Phd defence
Introducing Spatial Coverage in a Semantic Repository Model - Phd defence Introducing Spatial Coverage in a Semantic Repository Model - Phd defence
Introducing Spatial Coverage in a Semantic Repository Model - Phd defence
 
Final thesis presentation
Final thesis presentationFinal thesis presentation
Final thesis presentation
 
PCA and Classification
PCA and ClassificationPCA and Classification
PCA and Classification
 
Open geo data - technical issue
Open geo data  - technical issueOpen geo data  - technical issue
Open geo data - technical issue
 
EDBT 2015: Summer School Overview
EDBT 2015: Summer School OverviewEDBT 2015: Summer School Overview
EDBT 2015: Summer School Overview
 
3D Visibility with Vector GIS Data
3D Visibility with Vector GIS Data3D Visibility with Vector GIS Data
3D Visibility with Vector GIS Data
 
Spatial is Not Special ?
Spatial is Not Special ?Spatial is Not Special ?
Spatial is Not Special ?
 

Recently uploaded

Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Enhancing Performance with Globus and the Science DMZ
Enhancing Performance with Globus and the Science DMZEnhancing Performance with Globus and the Science DMZ
Enhancing Performance with Globus and the Science DMZ
Globus
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
Vlad Stirbu
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..
UiPathCommunity
 

Recently uploaded (20)

Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Enhancing Performance with Globus and the Science DMZ
Enhancing Performance with Globus and the Science DMZEnhancing Performance with Globus and the Science DMZ
Enhancing Performance with Globus and the Science DMZ
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..
 

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