Location Location Location

2,068 views

Published on

Slides from my ACCU2013 talk on location, GPS, GIS and PostGIS.

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
2,068
On SlideShare
0
From Embeds
0
Number of Embeds
396
Actions
Shares
0
Downloads
23
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Location Location Location

  1. 1. Location Location Location Gavin Heavyside - ACCU 2013 - 12 April 2012 gavin@heavyside.co.uk @gavinheavysideFriday, 12 April 13
  2. 2. Friday, 12 April 13
  3. 3. GPS, Location, GIS, and Spatial Relationships • GPS Technology • GIS and Mapping Concepts • Spatial DBs and SQL • Practical ExampleFriday, 12 April 13
  4. 4. Friday, 12 April 13
  5. 5. • www.mydrivesolutions.com • Insurance telematics • Linux,Ruby, Rails, Postgres, PostGIS, NoSQL, Chef, AWS, C++Friday, 12 April 13
  6. 6. Friday, 12 April 13
  7. 7. • I have no idea what I’m doingFriday, 12 April 13
  8. 8. GPS • Currently 32 satellitesFriday, 12 April 13
  9. 9. GPSFriday, 12 April 13
  10. 10. Basic GPS Concepts • 24+ Satellites orbit the earth • Atomic clocks • Each constantly transmits its time and locationFriday, 12 April 13
  11. 11. Basic GPS Concepts • Normally 4 or more sats used by receiver • Distance to each satellite calculated using speed of light • Triangulate position • Derived attributes - speed, bearingFriday, 12 April 13
  12. 12. http://www.ausairpower.net/TE-GPS-Guided-Weps.htmlFriday, 12 April 13
  13. 13. Almanac and Ephemeris • Almanac: GPS constellation info, orbits • Ephemeris: orbital and clock correction • With both in memory, lock is faster • A-GPS gets ephemeris from internetFriday, 12 April 13
  14. 14. NMEA 0183 • Serial ASCII data format • CSV ‘sentences’ for different types of dataFriday, 12 April 13
  15. 15. NMEA Sentences • GGA - Fix information • GSA - DOP and active satellites • GSV - Satellites in view • RMC - Time, date and positionFriday, 12 April 13
  16. 16. Friday, 12 April 13
  17. 17. Problems with GPS • Noise • Urban Canyons • Multipath signals • Solar flares and atmospherics • Mounting of receiverFriday, 12 April 13
  18. 18. Others • GLONASS • BEIDOU/COMPASS • GALILEO • IRNSSFriday, 12 April 13
  19. 19. Smartphone Support • All major smartphones have GPS sensors • Balance accuracy, frequency, battery life • Usually subscribe to service and get called back with location updates • Alerts: Geofencing, Significant ChangeFriday, 12 April 13
  20. 20. HTML5 GeoLocationFriday, 12 April 13
  21. 21. Friday, 12 April 13
  22. 22. Digital Maps • Commercial • NAVTEQ, Tele Atlas • Free • OSM • Online • Google, Bing, etcFriday, 12 April 13
  23. 23. Display • Usually map tiles at different zoom levels • Server will return tiled images for a bounding box • Plenty of libraries commercial or free to embed in apps or web pages • Add your own overlay markers and layersFriday, 12 April 13
  24. 24. Leaflet • JS plugin • Uses OSM or other tile servers • HW accelerated, touch-compatible • Markers, Polygons, Layers, GeoJSON • http://leafletjs.comFriday, 12 April 13
  25. 25. Friday, 12 April 13
  26. 26. Digital maps for GIS • Vector representation of your map • Commercial or OSM • Use the road or feature geometry, in conjunction with attributes of the featuresFriday, 12 April 13
  27. 27. OpenStreetMap • http://www.openstreetmap.org/ • Community generated and curated • XML geometry and metadata composed of nodes, ways, and relations • Can be downloaded in regions, updated incrementallyFriday, 12 April 13
  28. 28. Friday, 12 April 13
  29. 29. Friday, 12 April 13
  30. 30. • Some people when faced with a problem think “I know, I’ll use XML”. Now they haveFriday, 12 April 13
  31. 31. Data FormatsFriday, 12 April 13
  32. 32. Geometry Types • Points • Linestrings • Polygons • Compound: MultiPoint etc • 3D: all above with elevation, PolyhedralsFriday, 12 April 13
  33. 33. Well-Known Text (WKT) • markup language for vector geometry • ISO standard, originally by OGC • Always uses X Y, so watch out when using lat and lon: needs to be (lon lat) • Also an equivalent Well Known Binary used by databases to store spatial data • Can embed SRID (see later)Friday, 12 April 13
  34. 34. WKT Examples • Point(30 10) • LINESTRING (30 10, 10 30, 40 40) • POLYGON ((30 10, 10 20, 20 40, 40 40, 30 10)) • POLYGON ((35 10, 10 20, 15 40, 45 45, 35 10),(20 30, 35 35, 30 20, 20 30))Friday, 12 April 13
  35. 35. KML • XML data format used by Google Earth • Supports points, lines, markers, polygons, overlays, and much much more • Zip up with assets (e.g. Collada 3D models) into a .kmz fileFriday, 12 April 13
  36. 36. KMLFriday, 12 April 13
  37. 37. Friday, 12 April 13
  38. 38. GeoJSONFriday, 12 April 13
  39. 39. ShapeFiles • Created by ESRI • Widely used and understood • Points, Lines, Polygons • Collection of files: .shp, .shx, .dbf, others • Can be imported straight into PostGIS with shp2pgsqlFriday, 12 April 13
  40. 40. Friday, 12 April 13
  41. 41. Spatial Reference Systems • The Earth is not flat • Neither is it a spheroid • nor even an ellipsoid • Spatial Reference Systems approximate the geoid of the earth to an ellipsoidFriday, 12 April 13
  42. 42. GeoidFriday, 12 April 13
  43. 43. WGS84 • The most common (and most useful) spatial reference system • best fitting ellipsoid model to the reference points on the 1996 Earth Gravitational Model geoid • Used by GPSFriday, 12 April 13
  44. 44. Friday, 12 April 13
  45. 45. Projections • Projections • Orientation • Cylindrical • Oblique • Conic • Equatorial • Azimuthal • TransverseFriday, 12 April 13
  46. 46. Transverse Mercator • Some projections look good over most of the globe • Some are only useful locally (e.g. UTM)Friday, 12 April 13
  47. 47. Geospatial Databases • Ordinary RDBs with support for spatial data types • NoSQL DBs • MongoDB • https://github.com/neo4j/spatialFriday, 12 April 13
  48. 48. PostGIS • http://postgis.org/ • Geospatial Extensions for PostgreSQL • Excellent support for spatial data, operations, indexes • Actively developedFriday, 12 April 13
  49. 49. Creating a PostGIS DBFriday, 12 April 13
  50. 50. Spatial Relationships • Many ways to compare geometries • Some can compare different types • Some only valid for same type • CONTAINS, CROSSES, DISJOINT, DISTANCE, DWITHIN, EQUALS, INTERSECTS, OVERLAPS, TOUCHES, WITHINFriday, 12 April 13
  51. 51. ST_EqualsFriday, 12 April 13
  52. 52. ST_IntersectsFriday, 12 April 13
  53. 53. ST_DWithinFriday, 12 April 13
  54. 54. ST_TransformFriday, 12 April 13
  55. 55. Geography Data Type • Usually measurements are in the units of the spatial reference system • Radians for SRID 4326 (WGS84) • The geography data type can helpFriday, 12 April 13
  56. 56. Geospatial Indexes • Indexes on geo columns are necessary • Covers bounding boxes • Reduces search space • Geos used for calculationsFriday, 12 April 13
  57. 57. EXPLAIN • Use EXPLAIN to check the planner is using spatial indexes, just like other SQL queriesFriday, 12 April 13
  58. 58. Ordnance Survey OpenData • http://www.ordnancesurvey.co.uk/ oswebsite/products/os-opendata.html • Vector & Raster data • Maps, Roads, Boundaries, PostcodesFriday, 12 April 13
  59. 59. Friday, 12 April 13
  60. 60. Code-Point Open • CSV "Database" of UK postcode • (Not Northern Ireland) • 1.6m+ postcodes • Eastings and Northings for each entry • Also county/district & NHS infoFriday, 12 April 13
  61. 61. Data Format • Postcode in field 1Friday, 12 April 13
  62. 62. Data Format • Eastings, Northings in fields 3,4Friday, 12 April 13
  63. 63. OS National GridFriday, 12 April 13
  64. 64. Geocoding • Find the geographic location of a feature, e.g. address, business, POI • Reverse: Find a feature from a geographic location (e.g. lat/lng)Friday, 12 April 13
  65. 65. Example App • Put it all together: • Open Data • PostGIS • CRS transformations • Geospatial DB queriesFriday, 12 April 13
  66. 66. Friday, 12 April 13
  67. 67. GeoPostCoder • https://github.com/gavinheavyside/ geopostcoder • Bash and SQL to load postcode geo data • Simple Ruby web app to query DBFriday, 12 April 13
  68. 68. Loading Data • Filter Code-Point Open just to the columns we want • Load into a temporary table • Transform National Grid coordinates to WGS Geography data typeFriday, 12 April 13
  69. 69. Friday, 12 April 13
  70. 70. Friday, 12 April 13
  71. 71. Friday, 12 April 13
  72. 72. Friday, 12 April 13
  73. 73. Friday, 12 April 13
  74. 74. Recap • Lots of sources of location data • You probably have a GPS receiver with you • Lots of data available for free • Plenty of free and open-source tools querying and manipulating spatial data • Go do something interesting with it :)Friday, 12 April 13
  75. 75. @gavinheavyside gavin@heavyside.co.ukFriday, 12 April 13

×