Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Let's Talk Geo: Adding the "Where" to Your Djan...

Let's Talk Geo: Adding the "Where" to Your Django Project

Corryn

April 01, 2016
Tweet

Other Decks in How-to & DIY

Transcript

  1. LET’S TALK GEO: ADDING THE “WHERE” TO YOUR DJANGO PROJECT

    CORRYN SMITH @HOLACORRYN DJANGOCON EUROPE SPRING 2016 @HolaCorryn
  2. ABOUT ME •Graduate Student at NAU studying Geography, Planning, and

    Recreation •I work with GIS •I analyze data on maps @HolaCorryn
  3. WHAT IS GIS •Geographic Information Systems •Create, Store, Manipulate, Analyze

    and Display Spatial Data •Data that represents a place on Earth •Latitude, Longitude, UTM, State Plane, etc. @HolaCorryn
  4. GIS/GEOSPATIAL TECHNOLOGIES •All Around You! •Google Maps •Hotel to Conference

    •Public Transit Map •Package Tracking Maps @HolaCorryn
  5. ANALYZING AND GIS •Where to put the next business •Starbucks

    •Where to build a park •Mapping trails •Land Use Change over Time
  6. GIS DISPLAYS DATA • Visual way to display your data

    • Map = Picture • A Picture is Worth 1000 words!
  7. GIS DISPLAYS DATA • Visual way to display your data

    • Map = Picture • A Picture is Worth 1000 words!
  8. MAPS ARE IMPORTANT •Displays a route to a destination •Informs

    about elevation and physical features (lakes, mountains, etc.) •Reveals points of interest •Shows Spatial Patterns •Find Problems and make Solutions @HolaCorryn
  9. HOW PROGRAMMERS CAN USE MAPS •Display Service Areas •Babysitter/Lawn Mower

    can only a service an area 20 miles from home •Points of Interest on a Blog •DjangoGirl adds map on her blog of her favorite restaurants •Run a Fan-Fiction Blog of NekoAtsume @HolaCorryn
  10. HOW PROGRAMMERS CAN USE MAPS •Display Service Areas •Babysitter/Lawn Mower

    can only a service an area 20 miles from home •Points of Interest on a Blog •DjangoGirl adds map on her blog of her favorite restaurants •Run a Fan-Fiction Blog of NekoAtsume •Thematic Map or Density Map •Display the attendees who came to DjangoCon Europe
  11. GIS & PYTHON •ArcMap – ESRI Suite •ArcMap installs Python

    •Automate tasks with ArcPy @HolaCorryn
  12. GIS & PYTHON •ArcMap – ESRI Suite •ArcMap installs Python

    •Automate tasks with ArcPy @HolaCorryn
  13. GIS & DJANGO = GEODJANGO •Web framework to create geographic

    web applications •How to Add Maps to your Django Project!  •GeoDjango Tutorial is great! CCCCCC •https://docs.djangoproject.com/en/dev/ref/c ontrib/gis/tutorial/ @HolaCorryn
  14. BEGINNING YOUR GEODJANGO PROJECT CHECKLIST Spatial Database Geographic Data Geographic

    Model Importing your Geographic Data (Optional) Spatial Queries Geographic Friendly Admin Geo-Friendly API Mapbox Leaflet @HolaCorryn
  15. SPATIAL DATABASE •Database needs to be able to hold geometry

    •Geometry= Spatial Data! •Postgresql •CREATE EXTENSION postgis; @HolaCorryn
  16. BEGINNING YOUR GEODJANGO PROJECT CHECKLIST Spatial Database Geographic Data Geographic

    Model Importing your Geographic Data (Optional) Spatial Queries Geographic Friendly Admin Geo-Friendly API Mapbox Leaflet @HolaCorryn
  17. GEOGRAPHIC DATA • Shapefile- geospatial vector file • Points •

    Lines • Polygons • Often zipped/compressed • .shx (shape index format) • .shp (shape format/geometry) • .dbf (attribute data) • .prj (projection) • .sbn (spatial index for queries) @HolaCorryn
  18. GEOGRAPHIC DATA • Download Shapefiles • National Historical GIS (https://www.nhgis.org/)

    • Boundary Files • Historical Data • Diva GIS (http://www.diva-gis.org/gdata) • By Country & Subject • National Land Cover Database (http://www.mrlc.gov/) • Land Use Change Over Time • TIGER (https://www.census.gov/geo/maps-data/data/tiger.html) • Roads • Your Local or State Government @HolaCorryn
  19. GEOGRAPHIC DATA •Make Your Own •GPS •Collect Data with a

    Unit • Import GPX •GIS Software @HolaCorryn
  20. GEOGRAPHIC DATA Making a Shapefile in QGIS 1. Download QGIS

    (It’s Free!) 2. Open QGIS 3. Select “Plugins” from the toolbar 4. Select “Manage and Install Plugins” 5. Search for “QuickMapServices” and Install! @HolaCorryn
  21. CREATING A SHAPEFILE IN QGIS •Once you have it installed

    •Select a Basemap •(OSM = Open Street Map) @HolaCorryn
  22. CREATING A SHAPEFILE IN QGIS •Zoom to desired location •Select

    “Layer” •Select “New Shapefile Layer” •Create Shapefile with name and save @HolaCorryn
  23. CREATING A SHAPEFILE IN QGIS •Click on Shapefile in the

    Table of Content •Select the Yellow Pencil •Select Point/Line/Polygon •Click on Map
  24. CREATING A SHAPEFILE IN QGIS •Make sure you save! •Close

    of out QGIS •Select “Layer” •Select “Add Layer” •Select “Add Vector Layer” and select you new shapefile! @HolaCorryn
  25. GEOGRAPHIC DATA •Create a data folder under your application •Add

    all of your geographic data and all of its extensions! @HolaCorryn
  26. BEGINNING YOUR GEODJANGO PROJECT CHECKLIST Spatial Database Geographic Data Geographic

    Model Importing your Geographic Data (Optional) Spatial Queries Geographic Friendly Admin Geo-Friendly API Mapbox Leaflet @HolaCorryn
  27. GEOGRAPHIC MODEL • Your model should duplicate the fields in

    your shapefile • (GeoDjango Tutorial covers this more in depth) @HolaCorryn
  28. BEGINNING YOUR GEODJANGO PROJECT CHECKLIST Spatial Database Geographic Data Geographic

    Model Importing your Geographic Data (Optional) Spatial Queries Geographic Friendly Admin Geo-Friendly API Mapbox Leaflet @HolaCorryn
  29. BEGINNING YOUR GEODJANGO PROJECT CHECKLIST Spatial Database Geographic Data Geographic

    Model Importing your Geographic Data (Optional) Spatial Queries – See GeoDjango Tutorial Geographic Friendly Admin Geo-Friendly API Mapbox Leaflet @HolaCorryn
  30. GEOGRAPHIC FRIENDLY ADMIN from django.contrib.gis import admin from APPNAME import

    models admin.site.register(models.Georgia, admin.GeoModelAdmin) GeoDjango tutorial is also great for this step @HolaCorryn
  31. ADDING DATA THROUGH THE ADMIN •Do this for emergencies •If

    you destroy your database, you’ll lose the data •Always want a backup of your data @HolaCorryn
  32. BEGINNING YOUR GEODJANGO PROJECT CHECKLIST Spatial Database Geographic Data Geographic

    Model Importing your Geographic Data (Optional) Spatial Queries – See GeoDjango Tutorial Geographic Friendly Admin Geo-Friendly API Mapbox Leaflet @HolaCorryn
  33. GEO-FRIENDLY API • Add a serializer (translates the data and

    formats it to be stored and reconstructed later) from apps.berlin import models from rest_framework import serializers from rest_framework_gis import serializers as geoserializers class GeorgiaSerializer(geoserializers.GeoFeatureModelSerializer): class Meta: model = models.Georgia geo_field = 'mpoly' fields = ('name','num_studen') https://docs.djangoproject.com/en/1.9/ref/contrib/gis/serializers/ @HolaCorryn
  34. GEO-FRIENDLY API json_views.py from apps.APPNAME import models, serializers from rest_framework

    import generics import django_filters http://django-generic-json-views.readthedocs.org/en/latest/
  35. BEGINNING YOUR GEODJANGO PROJECT CHECKLIST Spatial Database Geographic Data Geographic

    Model Importing your Geographic Data (Optional) Spatial Queries – See GeoDjango Tutorial Geographic Friendly Admin Geo-Friendly API Mapbox Leaflet @HolaCorryn
  36. MAPBOX • https://www.mapbox.com/ • Adds the map to your project

    • Call in your data through the API • Free to create an account @HolaCorryn
  37. MAPBOX • http://hatamyar.com/mapping-with-geodjango-django-leaflet-and- mapbox.html • Code examples on how to

    add the mapbox tile to your html • http://imgur.com/JwhmTi0 • https://www.mapbox.com/mapbox.js/example/v1.0.0/geolocation/
  38. BEGINNING YOUR GEODJANGO PROJECT CHECKLIST Spatial Database Geographic Data Geographic

    Model Importing your Geographic Data (Optional) Spatial Queries – See GeoDjango Tutorial Geographic Friendly Admin Geo-Friendly API Mapbox Leaflet @HolaCorryn
  39. GEODJANGO EXAMPLES • http://ungmap.com (Campus > Gainesville) • Thanks Will

    Cox and Crystal Lyliston • http://theyburied.us/ • Professor Zac Miller’s and IESA student’s project @HolaCorryn
  40. WHY GEODJANGO?! • Add maps to your project • Give

    clients a “Where” • Answer questions • Display data in a unique way @HolaCorryn
  41. THANK YOU DjangoCon Europe Scholarship Professor J. Zac Miller, University

    of North Georgia Crystal Lyliston Will Cox Brandon Rumiser @HolaCorryn