SlideShare a Scribd company logo
Introducing PostGIS
What is Geospatial
β€’ Most common use
– Narrow a search within a distance from a point of
origin
– Sort by that distance
Distance Formulas
β€’ Flat-surface formulae
– Spherical Earth projected to a plane
– Ellipsoidal Earth projected to a plane
– Polar coordinate flat-Earth formula
β€’ Spherical-surface formulae
– Haversine
– Tunnel distance
β€’ Ellipsoidal-surface formulae
– Lambert’s formula for long lines
– Bowring’s method for short lines
Here’s one example
What you usually care about
β€’ Given 2 latitude and longitude points
– Calculate the distance so we can find what’s close
β€’ This is the common capability of databases with
β€œgeospatial” support
A few options…
β€’ Do the math in a query
β€’ Here’s what it looks like in SQL
– (ACOS(least(1,COS(0.607198022186895)*COS(-
1.4410239410591847)*COS(RADIANS(latitude))*COS(RAD
IANS(longitude)) + COS(0.607198022186895)*SIN(-
1.4410239410591847)*COS(RADIANS(latitude))*SIN(RAD
IANS(longitude)) +
SIN(0.607198022186895)*SIN(RADIANS(latitude))))*39
63.19)) <= 25)
– Calculating within 25 miles of a point of origin based on an origin point
– You can do that in any database (it’s just math)
– Very intense query that slows as your dataset grows
– This…is not using an index
Speed that up
β€’ Distance query a subset instead
β€’ Use the lat/lng to create query a box
around the boundary
β€’ Queried with a numerical index
β€’ Then check the distance from center
for the subset
β€’ NOTE: Doing this as part of another
query is a lot easier with multi-index
queries
And here’s what THAT looks like
WHERE (
latitude > 34.42845936786603
AND latitude < 35.15130863213399
AND longitude > -83.00467808012291
AND longitude < -82.12450191987708
)
AND
( (ACOS(least(1,COS(0.607198022186895)*COS(-
1.4410239410591847)*COS(RADIANS(latitude))*COS(RADIANS(longitude))+
COS(0.607198022186895)*SIN(-
1.4410239410591847)*COS(RADIANS(latitude))*SIN(RADIANS(longitude))+
SIN(0.607198022186895)*SIN(RADIANS(latitude))))*3963.19)
) <= 25)
Simple, am I right?
Also, you need to drop that distance formula into the ORDER BY clause too.
There’s a Gem for that!
Geokit
https://github.com/geokit/geokit
β€’ Distance calculations between 2 points
– Multiple formulas and units of measure
β€’ Multiple providers for Geocoding
different data
– Addresses
β€’ Yahoo
β€’ Geocoder.us/.ca
β€’ Geonames
β€’ Bing
β€’ Yandex
β€’ MapQuest
β€’ Geocode.io
β€’ Mapbox
β€’ Google
β€’ FCC
β€’ Open Street Map
– IP Address
β€’ hostip.info
β€’ Geoplugin.net
β€’ RIPE
β€’ MaxMind (HIGHLY RECOMMEND)
β€’ freegeoip.net
Geokit Rails (any database)
https://github.com/geokit/geokit-rails
β€’ Premium Rails Integration
β€’ ActiveRecord distance finders
β€’ IP based location lookup
β€’ Cookie based user location tracking
β€’ Scopes: within, beyond, in_range, in_bounds,
closest, farthest, by_distance
β€’ Generate the SQL
β€’ Auto-Geocoding
β€’ Mixin
class Location < ActiveRecord::Base
acts_as_mappable :default_units => :miles,
:default_formula => :sphere,
:distance_field_name => :distance,
:lat_column_name => :lat,
:lng_column_name => :lng
end
Actually, there’s several…
RGeo
β€’ Adapters for
– MySQL
– SQLite
– PostGIS
β€’ Process GeoJSON
β€’ Read shapefiles
β€’ Uses C++ extensions for
processing
Geocoder
β€’ Object Geocoding
– IP
– Address
β€’ Reverse Geocoding
– Address from lat/lng or IP
β€’ Center of Multiple Locations
β€’ Geographic Queries
– Near / nearby
– Distance
– Direction
β€’ Easier to use
β€’ Seems to be some dispute about
accuracy of data
What about PostgreSQL?
β€’ Provide database functions
to handle this calculations
– Distance in straight line or
great circle
– Convert lat/lng to point
– Get lat/lng from a point
– Calculate containment
within a cube
β€’ Point datatype
– Operator to get distance
between
Earth Distance extension
http://www.postgresql.org/docs/9.2/s
tatic/earthdistance.html
Cube based
Point based
SO WHAT DOES POSTGIS DO THEN?
Funny you should ask…
EVERYTHING
Seriously…it does pretty much
everything
Import and Export Data
β€’ Import CSV
β€’ Import/export with GDAL (Geospatial Abstraction
Library)
– Shapefiles
– OGR
– Geospatial vector data files
– OpenStreetMap data (openstreetmap.org)
– Raster datasets
β€’ Import OGR files
β€’ ETL migration tools
– GeoKettle
GIS Desktop Software
Open Source
β€’ OpenJump
β€’ QuantumGIS
β€’ uDig
β€’ GvSig
β€’ OrbisGIS
β€’ PostGIS Viewer
β€’ pgAdmin plugin
Commercial
β€’ CadCorp SIS
β€’ Manifold.net
β€’ MapInfo Professional
β€’ AutoCAD
β€’ ESRI ArcGIS
Mapping Servers Integration
β€’ Mapserver
β€’ GeoServer
β€’ Deegree
β€’ QGIS Server
β€’ MapGuide
Data: OpenStreetMap
Data: US Census
Data: WorldClim
US Geological Survey
Natural Earth
MaxMind GeoIP
Web Services / API
Constantly Updated Databases
Free and Paid Versions
Check your IP to try it out
https://www.maxmind.com/en/locate
_my_ip
Working with Data
β€’ Datatypes
– Geography
β€’ Ellipsoidal spatial data
– Geometry
β€’ Planar spatial data
β€’ Indexes
β€’ Topology
β€’ Spatial Joins
β€’ 3D
– Mapping (building, etc)
– Image generation
β€’ pgRoute
– Generate driving route
β€’ Generate raster images from SQL
queries
β€’ Spatial Relationship Functions
– ST_Contains
– ST_Covers
– ST_Crosses
– ST_DWithin
– ST_Intersects
– ST_Distance
β€’ Clustered Queries for Huge
Datasets
Fun data tricks
β€’ Use a TRIGGER to populate a geographic data
column for transparent indexing
β€’ Create a Geospatial View
β€’ Use table inheritance to centralize
commonality among different data types
– Geographic Data
– Search Data
AR PostGIS Adapter
Migrations
create_table :locations do |t|
t.column :shape1, :geometry
t.geometry :shape2
t.line_string :path, :srid => 3785
t.point :lonlat, :geographic => true
t.point :lonlatheight, :geographic => true, :has_z => true
t.index :lonlat, :spatial => true
end
Datatypes
:geometry -- Any geometric type
:point -- Point data
:line_string -- LineString data
:polygon -- Polygon data
:geometry_collection -- Any collection type
:multi_point -- A collection of Points
:multi_line_string -- A collection of LineStrings
:multi_polygon -- A collection of Polygons
ActiveRecord
Location.where(:lonlat => 'POINT(-122 47)').first
Location.where("ST_Distance(latlon,
'POINT(-122.330779 47.604828)') < 10000")
scope :distance_from, ->(lat, lon, dist) do
where(β€œST_Distance(latlon, β€˜POINT(? ?)’) < ?, lat, lon, dist)
end
Location.where("ST_Intersects(latlon,
'POLYGON((
-122.19 47.68,
-122.2 47.675,
-122.19 47.67,
-122.19 47.68))')")
https://github.com/rgeo/active
record-postgis-adapter
Features
β€’ Uses Rgeo gem
β€’ Spatial Migrations
β€’ Spatial Datatype
β€’ Spatial Queries
β€’ Create / Update PostGIS DB
β€’ Support central schema
Assignment 2
β€’ Refine and improve your application
β€’ Add authentication
β€’ Add authors (or some type of user) to created data
β€’ Display author info on your data
β€’ Implement simple_form somewhere
β€’ Add a new validation rule to a model
β€’ Add a page to show related data for an author
β€’ Use slim (or haml) to create one of your views
β€’ Add a BASIC geographic capability (optional)
– Use your own discretion for how deep you go
– Suggestions / Ideas
β€’ Geocode user IP addresses to get city/state/zip info
β€’ Add address fields to your data type to make it geographically relevant
β€’ Use a distance filter in search

More Related Content

ODP
Introduction To PostGIS
ODP
Intro To PostGIS
PPT
Using PostGIS To Add Some Spatial Flavor To Your Application
PPTX
Why is postgis awesome?
PPTX
GeoMesa: Scalable Geospatial Analytics
PPTX
PostGIS and Spatial SQL
PPTX
MySQL 5.7 GIS
PDF
Spatial functions in MySQL 5.6, MariaDB 5.5, PostGIS 2.0 and others
Introduction To PostGIS
Intro To PostGIS
Using PostGIS To Add Some Spatial Flavor To Your Application
Why is postgis awesome?
GeoMesa: Scalable Geospatial Analytics
PostGIS and Spatial SQL
MySQL 5.7 GIS
Spatial functions in MySQL 5.6, MariaDB 5.5, PostGIS 2.0 and others

What's hot (20)

PDF
Scaling PostreSQL with Stado
KEY
Handling Real-time Geostreams
ODP
MySQL and GIS Programming
PPTX
Spatiotemporal Raster Improvements in GeoServer
PPTX
LocationTech Projects
PDF
OSM data in MariaDB / MySQL - All the world in a few large tables
PDF
Don't optimize my queries, organize my data!
PPT
Overview of MassGIS Web Mapping Services
PPT
Wms Performance Tests Map Server Vs Geo Server
Β 
PDF
Spark Dataframe - Mr. Jyotiska
PDF
SparkR - Play Spark Using R (20160909 HadoopCon)
Β 
PDF
Writing MapReduce Programs using Java | Big Data Hadoop Spark Tutorial | Clou...
PPT
Askayworkshop
PDF
Prashant de-ny-project-s1
PDF
ClickHouse tips and tricks. Webinar slides. By Robert Hodges, Altinity CEO
PDF
All you need to know about CREATE STATISTICS
Β 
PPSX
Where the %$#^ Is Everybody? Geospatial Solutions For Oracle APEX
PPTX
scalable machine learning
ODP
WMS Performance Shootout 2009
ODP
Scaling PostgreSQL With GridSQL
Scaling PostreSQL with Stado
Handling Real-time Geostreams
MySQL and GIS Programming
Spatiotemporal Raster Improvements in GeoServer
LocationTech Projects
OSM data in MariaDB / MySQL - All the world in a few large tables
Don't optimize my queries, organize my data!
Overview of MassGIS Web Mapping Services
Wms Performance Tests Map Server Vs Geo Server
Β 
Spark Dataframe - Mr. Jyotiska
SparkR - Play Spark Using R (20160909 HadoopCon)
Β 
Writing MapReduce Programs using Java | Big Data Hadoop Spark Tutorial | Clou...
Askayworkshop
Prashant de-ny-project-s1
ClickHouse tips and tricks. Webinar slides. By Robert Hodges, Altinity CEO
All you need to know about CREATE STATISTICS
Β 
Where the %$#^ Is Everybody? Geospatial Solutions For Oracle APEX
scalable machine learning
WMS Performance Shootout 2009
Scaling PostgreSQL With GridSQL
Ad

Viewers also liked (7)

PPTX
Day 9 - PostgreSQL Application Architecture
PPTX
Day 1 - Intro to Ruby
PPTX
Day 2 - Intro to Rails
PPTX
PostgreSQL - It's kind've a nifty database
PPTX
Day 4 - Models
PPTX
Day 8 - jRuby
PPTX
Day 7 - Make it Fast
Day 9 - PostgreSQL Application Architecture
Day 1 - Intro to Ruby
Day 2 - Intro to Rails
PostgreSQL - It's kind've a nifty database
Day 4 - Models
Day 8 - jRuby
Day 7 - Make it Fast
Ad

Similar to Day 6 - PostGIS (20)

PPT
NAPSG 2010 Fire/EMS Conference - Data Sharing Basics
PPTX
Mobile LBS
PPT
Efficient Query Processing in Geographic Web Search Engines
PDF
Cloud conf-varna-2014-mihail mateev-spatial-data-and-microsoft-azure-sql-data...
PDF
Graph Algorithms - Map-Reduce Graph Processing
PDF
Managing GeoData with PostGIS @ KhmelnytskyiPy #1
PPTX
Geek Sync | Having Fun with Spatial Data
PDF
Geographical Data Management for Web Applications
PPTX
NGSI: Geoqueries & Carto integration
Β 
PPT
GIS Introduction.ppt
PDF
A Lightweight Infrastructure for Graph Analytics
PPTX
R spatial presentation
PDF
Building Location Aware Apps - Get Started with PostGIS, PART II
PDF
Demolitions and Dali : Web Dev and Data in a Graph Database
PPTX
Get mapping with leaflet js
PDF
Pycon2011
PDF
Pgrouting_foss4guk_ross_mcdonald
PDF
The state of geo in ElasticSearch
PDF
[2015/2016] Geolocation and mapping
PDF
Post gispguk
NAPSG 2010 Fire/EMS Conference - Data Sharing Basics
Mobile LBS
Efficient Query Processing in Geographic Web Search Engines
Cloud conf-varna-2014-mihail mateev-spatial-data-and-microsoft-azure-sql-data...
Graph Algorithms - Map-Reduce Graph Processing
Managing GeoData with PostGIS @ KhmelnytskyiPy #1
Geek Sync | Having Fun with Spatial Data
Geographical Data Management for Web Applications
NGSI: Geoqueries & Carto integration
Β 
GIS Introduction.ppt
A Lightweight Infrastructure for Graph Analytics
R spatial presentation
Building Location Aware Apps - Get Started with PostGIS, PART II
Demolitions and Dali : Web Dev and Data in a Graph Database
Get mapping with leaflet js
Pycon2011
Pgrouting_foss4guk_ross_mcdonald
The state of geo in ElasticSearch
[2015/2016] Geolocation and mapping
Post gispguk

More from Barry Jones (7)

PPTX
Repeating History...On Purpose...with Elixir
PPTX
Go from a PHP Perspective
PPT
Protecting Users from Fraud
PPTX
AWS re:Invent 2013 Recap
PPTX
Pair Programming - the lightning talk
PPTX
What's the "right" PHP Framework?
PPTX
Exploring Ruby on Rails and PostgreSQL
Repeating History...On Purpose...with Elixir
Go from a PHP Perspective
Protecting Users from Fraud
AWS re:Invent 2013 Recap
Pair Programming - the lightning talk
What's the "right" PHP Framework?
Exploring Ruby on Rails and PostgreSQL

Recently uploaded (20)

PPTX
CHE NAA, , b,mn,mblblblbljb jb jlb ,j , ,C PPT.pptx
PDF
Behind the Smile Unmasking Ken Childs and the Quiet Trail of Deceit Left in H...
PDF
The Internet -By the Numbers, Sri Lanka Edition
Β 
PDF
Decoding a Decade: 10 Years of Applied CTI Discipline
PDF
Tenda Login Guide: Access Your Router in 5 Easy Steps
PPTX
Introduction about ICD -10 and ICD11 on 5.8.25.pptx
PPTX
innovation process that make everything different.pptx
PDF
Testing WebRTC applications at scale.pdf
PDF
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
PDF
πŸ’° π”πŠπ“πˆ πŠπ„πŒπ„ππ€ππ†π€π πŠπˆππ„π‘πŸ’πƒ π‡π€π‘πˆ 𝐈𝐍𝐈 πŸπŸŽπŸπŸ“ πŸ’°
Β 
PPTX
presentation_pfe-universite-molay-seltan.pptx
PPTX
Introuction about WHO-FIC in ICD-10.pptx
PPTX
Introuction about ICD -10 and ICD-11 PPT.pptx
PPTX
Digital Literacy And Online Safety on internet
PDF
Unit-1 introduction to cyber security discuss about how to secure a system
PPTX
QR Codes Qr codecodecodecodecocodedecodecode
PPTX
cyber security Workshop awareness ppt.pptx
PDF
LABUAN4D EXCLUSIVE SERVER STAR GAMING ASIA NO.1
PDF
LABUAN4D EXCLUSIVE SERVER STAR GAMING ASIA NO.1
PDF
Sims 4 Historia para lo sims 4 para jugar
CHE NAA, , b,mn,mblblblbljb jb jlb ,j , ,C PPT.pptx
Behind the Smile Unmasking Ken Childs and the Quiet Trail of Deceit Left in H...
The Internet -By the Numbers, Sri Lanka Edition
Β 
Decoding a Decade: 10 Years of Applied CTI Discipline
Tenda Login Guide: Access Your Router in 5 Easy Steps
Introduction about ICD -10 and ICD11 on 5.8.25.pptx
innovation process that make everything different.pptx
Testing WebRTC applications at scale.pdf
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
πŸ’° π”πŠπ“πˆ πŠπ„πŒπ„ππ€ππ†π€π πŠπˆππ„π‘πŸ’πƒ π‡π€π‘πˆ 𝐈𝐍𝐈 πŸπŸŽπŸπŸ“ πŸ’°
Β 
presentation_pfe-universite-molay-seltan.pptx
Introuction about WHO-FIC in ICD-10.pptx
Introuction about ICD -10 and ICD-11 PPT.pptx
Digital Literacy And Online Safety on internet
Unit-1 introduction to cyber security discuss about how to secure a system
QR Codes Qr codecodecodecodecocodedecodecode
cyber security Workshop awareness ppt.pptx
LABUAN4D EXCLUSIVE SERVER STAR GAMING ASIA NO.1
LABUAN4D EXCLUSIVE SERVER STAR GAMING ASIA NO.1
Sims 4 Historia para lo sims 4 para jugar

Day 6 - PostGIS

  • 2. What is Geospatial β€’ Most common use – Narrow a search within a distance from a point of origin – Sort by that distance
  • 3. Distance Formulas β€’ Flat-surface formulae – Spherical Earth projected to a plane – Ellipsoidal Earth projected to a plane – Polar coordinate flat-Earth formula β€’ Spherical-surface formulae – Haversine – Tunnel distance β€’ Ellipsoidal-surface formulae – Lambert’s formula for long lines – Bowring’s method for short lines
  • 5. What you usually care about β€’ Given 2 latitude and longitude points – Calculate the distance so we can find what’s close β€’ This is the common capability of databases with β€œgeospatial” support
  • 6. A few options… β€’ Do the math in a query β€’ Here’s what it looks like in SQL – (ACOS(least(1,COS(0.607198022186895)*COS(- 1.4410239410591847)*COS(RADIANS(latitude))*COS(RAD IANS(longitude)) + COS(0.607198022186895)*SIN(- 1.4410239410591847)*COS(RADIANS(latitude))*SIN(RAD IANS(longitude)) + SIN(0.607198022186895)*SIN(RADIANS(latitude))))*39 63.19)) <= 25) – Calculating within 25 miles of a point of origin based on an origin point – You can do that in any database (it’s just math) – Very intense query that slows as your dataset grows – This…is not using an index
  • 7. Speed that up β€’ Distance query a subset instead β€’ Use the lat/lng to create query a box around the boundary β€’ Queried with a numerical index β€’ Then check the distance from center for the subset β€’ NOTE: Doing this as part of another query is a lot easier with multi-index queries
  • 8. And here’s what THAT looks like WHERE ( latitude > 34.42845936786603 AND latitude < 35.15130863213399 AND longitude > -83.00467808012291 AND longitude < -82.12450191987708 ) AND ( (ACOS(least(1,COS(0.607198022186895)*COS(- 1.4410239410591847)*COS(RADIANS(latitude))*COS(RADIANS(longitude))+ COS(0.607198022186895)*SIN(- 1.4410239410591847)*COS(RADIANS(latitude))*SIN(RADIANS(longitude))+ SIN(0.607198022186895)*SIN(RADIANS(latitude))))*3963.19) ) <= 25) Simple, am I right? Also, you need to drop that distance formula into the ORDER BY clause too.
  • 9. There’s a Gem for that! Geokit https://github.com/geokit/geokit β€’ Distance calculations between 2 points – Multiple formulas and units of measure β€’ Multiple providers for Geocoding different data – Addresses β€’ Yahoo β€’ Geocoder.us/.ca β€’ Geonames β€’ Bing β€’ Yandex β€’ MapQuest β€’ Geocode.io β€’ Mapbox β€’ Google β€’ FCC β€’ Open Street Map – IP Address β€’ hostip.info β€’ Geoplugin.net β€’ RIPE β€’ MaxMind (HIGHLY RECOMMEND) β€’ freegeoip.net Geokit Rails (any database) https://github.com/geokit/geokit-rails β€’ Premium Rails Integration β€’ ActiveRecord distance finders β€’ IP based location lookup β€’ Cookie based user location tracking β€’ Scopes: within, beyond, in_range, in_bounds, closest, farthest, by_distance β€’ Generate the SQL β€’ Auto-Geocoding β€’ Mixin class Location < ActiveRecord::Base acts_as_mappable :default_units => :miles, :default_formula => :sphere, :distance_field_name => :distance, :lat_column_name => :lat, :lng_column_name => :lng end
  • 10. Actually, there’s several… RGeo β€’ Adapters for – MySQL – SQLite – PostGIS β€’ Process GeoJSON β€’ Read shapefiles β€’ Uses C++ extensions for processing Geocoder β€’ Object Geocoding – IP – Address β€’ Reverse Geocoding – Address from lat/lng or IP β€’ Center of Multiple Locations β€’ Geographic Queries – Near / nearby – Distance – Direction β€’ Easier to use β€’ Seems to be some dispute about accuracy of data
  • 11. What about PostgreSQL? β€’ Provide database functions to handle this calculations – Distance in straight line or great circle – Convert lat/lng to point – Get lat/lng from a point – Calculate containment within a cube β€’ Point datatype – Operator to get distance between Earth Distance extension http://www.postgresql.org/docs/9.2/s tatic/earthdistance.html Cube based Point based
  • 12. SO WHAT DOES POSTGIS DO THEN? Funny you should ask…
  • 14. Import and Export Data β€’ Import CSV β€’ Import/export with GDAL (Geospatial Abstraction Library) – Shapefiles – OGR – Geospatial vector data files – OpenStreetMap data (openstreetmap.org) – Raster datasets β€’ Import OGR files β€’ ETL migration tools – GeoKettle
  • 15. GIS Desktop Software Open Source β€’ OpenJump β€’ QuantumGIS β€’ uDig β€’ GvSig β€’ OrbisGIS β€’ PostGIS Viewer β€’ pgAdmin plugin Commercial β€’ CadCorp SIS β€’ Manifold.net β€’ MapInfo Professional β€’ AutoCAD β€’ ESRI ArcGIS
  • 16. Mapping Servers Integration β€’ Mapserver β€’ GeoServer β€’ Deegree β€’ QGIS Server β€’ MapGuide
  • 22. MaxMind GeoIP Web Services / API Constantly Updated Databases Free and Paid Versions Check your IP to try it out https://www.maxmind.com/en/locate _my_ip
  • 23. Working with Data β€’ Datatypes – Geography β€’ Ellipsoidal spatial data – Geometry β€’ Planar spatial data β€’ Indexes β€’ Topology β€’ Spatial Joins β€’ 3D – Mapping (building, etc) – Image generation β€’ pgRoute – Generate driving route β€’ Generate raster images from SQL queries β€’ Spatial Relationship Functions – ST_Contains – ST_Covers – ST_Crosses – ST_DWithin – ST_Intersects – ST_Distance β€’ Clustered Queries for Huge Datasets
  • 24. Fun data tricks β€’ Use a TRIGGER to populate a geographic data column for transparent indexing β€’ Create a Geospatial View β€’ Use table inheritance to centralize commonality among different data types – Geographic Data – Search Data
  • 25. AR PostGIS Adapter Migrations create_table :locations do |t| t.column :shape1, :geometry t.geometry :shape2 t.line_string :path, :srid => 3785 t.point :lonlat, :geographic => true t.point :lonlatheight, :geographic => true, :has_z => true t.index :lonlat, :spatial => true end Datatypes :geometry -- Any geometric type :point -- Point data :line_string -- LineString data :polygon -- Polygon data :geometry_collection -- Any collection type :multi_point -- A collection of Points :multi_line_string -- A collection of LineStrings :multi_polygon -- A collection of Polygons ActiveRecord Location.where(:lonlat => 'POINT(-122 47)').first Location.where("ST_Distance(latlon, 'POINT(-122.330779 47.604828)') < 10000") scope :distance_from, ->(lat, lon, dist) do where(β€œST_Distance(latlon, β€˜POINT(? ?)’) < ?, lat, lon, dist) end Location.where("ST_Intersects(latlon, 'POLYGON(( -122.19 47.68, -122.2 47.675, -122.19 47.67, -122.19 47.68))')") https://github.com/rgeo/active record-postgis-adapter Features β€’ Uses Rgeo gem β€’ Spatial Migrations β€’ Spatial Datatype β€’ Spatial Queries β€’ Create / Update PostGIS DB β€’ Support central schema
  • 26. Assignment 2 β€’ Refine and improve your application β€’ Add authentication β€’ Add authors (or some type of user) to created data β€’ Display author info on your data β€’ Implement simple_form somewhere β€’ Add a new validation rule to a model β€’ Add a page to show related data for an author β€’ Use slim (or haml) to create one of your views β€’ Add a BASIC geographic capability (optional) – Use your own discretion for how deep you go – Suggestions / Ideas β€’ Geocode user IP addresses to get city/state/zip info β€’ Add address fields to your data type to make it geographically relevant β€’ Use a distance filter in search