SlideShare a Scribd company logo
Intro to PostGIS in
Ruby
What is PostGIS
A set of geo-spatial extensions for the PostgreSQL
database
And for those who don’t know, PostgreSQL is an SQL
database similar to MySQL & MS SQL Server
What do I need to know about
geo-spatial ‘stuff’ to get going?
It depends entirely on what you’re doing :)
The Building Blocks:
Point
LineString
Polygon
With these Blocks, 

we can ask:
Does this LineString intersect any Polygons?
Which Polygons does a Point exist within?
How much do these Polygons overlap?
What are the closest alternative Points to this Point?
much, much more
SRID?
Spatial Reference ID
Need to understand that when displaying a 3D world on
a 2D screen, decisions on how to need to be made
SRID?
Much like a graph needs labeled axis to mean anything,
SRIDs provide context to correctly interpret spatial
coordinates
There’s a collation of industry standard SRID’s that get
setup on your db - look at your shiny new
spatial_ref_sys table
Rule of thumb - unless you know better, just use 4326 :)
Spatial Indexes
Greatly improves the speed of querying complex spatial
datasets
Pulling this all into 

Ruby Land!
RGeo provides the spatial ‘building blocks’ for Ruby
ActiveRecord PostGIS Adapter provides the migration
support & RGeo type casting layer to ActiveRecord/Rails
RGeo
https://github.com/rgeo/rgeo
‘An implementation of the industry standard OGC Simple
Features Specification, which provides data
representations of geometric objects such as points,
lines and polygons, along with a set of geometric
analysis operations.’
What’s missing?
A nice abstraction layer allowing scoped spatial queries

i.e.

Hotel.near(location).with_wifi

Region.within(country)

country.outside?(region)
Common Spatial Commands
ST_Intersects

Does a line or polygon intersect with another line or polygon?

Useful for ‘areas travelled through’ or ‘area union’ kind of questions
ST_DWithin

Lets us ask whether a geographic object is within a certain distance of
another geographic object
ST_Contains

Do all given points lie within a given polygon?
ST_Overlaps

Do 2 different geometries share space?
Common Spatial Commands
Plenty more, check out the API!
So, what is this good for?
Criminally underused in the web dev world
Incredibly powerful for providing context to applications
that utilise location related data

(in the Rails world, think mobile APIs…)
Great for data analysis & strategically targeting markets
- think growth hacking!
So, what is this good for?
Working with existing spatial datasets
ESRI Shapefile
A popular format for storing geometric location
information & associated metadata
Used heavily by the Australian Government

- e.g. municipal boundaries, ABS data & census data
Most of our friendly geo-spatial software will happily
find a way to work with this data format
Some Gotchas
Make sure your schema includes the postgis extension
Don’t delete the spatial_ref_sys table!
Pay close attention to your SRIDs, and unless you’re
sure, stick to using 4326 on your db
When importing data, convert it to 4326 if a data source
is in a different SRID
Some Gotchas
Rails likes to use SELECT table.* - beware that this can
be painful to performance if your table contains lots of
intricate spatial data. Consider using a join to store
complex data in a separate table & only call when
necessary.
Even with spatial indexing, large datasets can become a
burden on the database. Consider using traditional id
based relationships as a cache for complex geospatial
result sets.
Alternatives
MySQL Spatial Extensions
Not as mature as PostGIS
Only MyISAM supports spatial indexes - ok if you’re not
into data retention :)
SQL Server
More mature than MySQL & not a bad choice if you’re a
MS Shop
Alternatives
Oracle Spatial
I’ve heard it’s pretty good if you have the wallet for it!
I’ve also been informed that there’s a free version that may cut it
for many people :)
MongoDB
Great for basic geospatial functionality
Not as fully featured as PostGIS, may leave you wanting in certain
areas
Getting Started in Rails
First step: Get a copy of PostgreSQL & PostGIS
Easiest way on OS/X is to grab Postgres.app from
http://postgresapp.com/
Grab a copy of QGIS while you’re at it - 

http://www.kyngchaos.com/software/qgis for Mac
users
Getting Started in Rails
rails new spatial_project -d postgresql!
gem ‘activerecord-postgis-adapter’

Gemfile!
adapter: postgis

config/database.yml!
rake db:create!
rake db:gis:setup
Getting Started in Rails
You can now run migrations like these:



create_table :spatials, do |t|

t.string :name,

t.multi_polygon, :area, srid: 4326,

t.point, :position, srid: 4326,

t.line_string, :path, srid: 4326

end
Getting Started in Rails
And create spatial indexes like this:



add_index :spatials, :area, spatial: true
Resources
http://gis.stackexchange.com/
http://postgis.net/documentation/
http://daniel-azuma.com/articles/georails
https://www.qgis.org/

More Related Content

Similar to Adelaide Ruby Meetup PostGIS Notes

Introduction To Geocoding: Linda Achieng
Introduction To Geocoding: Linda AchiengIntroduction To Geocoding: Linda Achieng
Introduction To Geocoding: Linda Achieng
Redis Labs
 
Gis Xke
Gis XkeGis Xke
Gis and Ruby 101 at Ruby Conf Kenya 2017 by Kamal Ogudah
Gis and Ruby 101 at Ruby Conf Kenya 2017 by Kamal OgudahGis and Ruby 101 at Ruby Conf Kenya 2017 by Kamal Ogudah
Gis and Ruby 101 at Ruby Conf Kenya 2017 by Kamal Ogudah
Michael Kimathi
 
No(Geo)SQL
No(Geo)SQLNo(Geo)SQL
Beginner's guide to Mongodb and NoSQL
Beginner's guide to Mongodb and NoSQL  Beginner's guide to Mongodb and NoSQL
Beginner's guide to Mongodb and NoSQL
Maulin Shah
 
Open Source Databases And Gis
Open Source Databases And GisOpen Source Databases And Gis
Open Source Databases And Gis
Kudos S.A.S
 
Au09 Presentation Ut118 1
Au09 Presentation Ut118 1Au09 Presentation Ut118 1
Au09 Presentation Ut118 1
Richard Chappell, GISP
 
Open Source GIS
Open Source GISOpen Source GIS
Open Source GIS
Joe Larson
 
What is spatial sql
What is spatial sqlWhat is spatial sql
What is spatial sql
shawty_ds
 
Magellan FOSS4G Talk, Boston 2017
Magellan FOSS4G Talk, Boston 2017Magellan FOSS4G Talk, Boston 2017
Magellan FOSS4G Talk, Boston 2017
Ram Sriharsha
 
Big Data Analytics 2014
Big Data Analytics 2014Big Data Analytics 2014
Big Data Analytics 2014
Stratebi
 
MongoDB eBook a complete guide to beginners
MongoDB eBook a complete guide to beginnersMongoDB eBook a complete guide to beginners
MongoDB eBook a complete guide to beginners
MeiyappanRm
 
Big Data SSD Architecture: Digging Deep to Discover Where SSD Performance Pay...
Big Data SSD Architecture: Digging Deep to Discover Where SSD Performance Pay...Big Data SSD Architecture: Digging Deep to Discover Where SSD Performance Pay...
Big Data SSD Architecture: Digging Deep to Discover Where SSD Performance Pay...
Samsung Business USA
 
GIS Data Types
GIS Data TypesGIS Data Types
GIS Data Types
John Reiser
 
How to empower community by using GIS lecture 1
How to empower community by using GIS lecture 1How to empower community by using GIS lecture 1
How to empower community by using GIS lecture 1wang yaohui
 
Which NoSQL Database to Combine with Spark for Real Time Big Data Analytics?
Which NoSQL Database to Combine with Spark for Real Time Big Data Analytics?Which NoSQL Database to Combine with Spark for Real Time Big Data Analytics?
Which NoSQL Database to Combine with Spark for Real Time Big Data Analytics?
IJCSIS Research Publications
 
CouchBase The Complete NoSql Solution for Big Data
CouchBase The Complete NoSql Solution for Big DataCouchBase The Complete NoSql Solution for Big Data
CouchBase The Complete NoSql Solution for Big Data
Debajani Mohanty
 
Components of gis
Components of gisComponents of gis
Components of gis
Pramoda Raj
 
What is GIS?
What is GIS?What is GIS?
What is GIS?deirdre
 
NO SQL: What, Why, How
NO SQL: What, Why, HowNO SQL: What, Why, How
NO SQL: What, Why, HowIgor Moochnick
 

Similar to Adelaide Ruby Meetup PostGIS Notes (20)

Introduction To Geocoding: Linda Achieng
Introduction To Geocoding: Linda AchiengIntroduction To Geocoding: Linda Achieng
Introduction To Geocoding: Linda Achieng
 
Gis Xke
Gis XkeGis Xke
Gis Xke
 
Gis and Ruby 101 at Ruby Conf Kenya 2017 by Kamal Ogudah
Gis and Ruby 101 at Ruby Conf Kenya 2017 by Kamal OgudahGis and Ruby 101 at Ruby Conf Kenya 2017 by Kamal Ogudah
Gis and Ruby 101 at Ruby Conf Kenya 2017 by Kamal Ogudah
 
No(Geo)SQL
No(Geo)SQLNo(Geo)SQL
No(Geo)SQL
 
Beginner's guide to Mongodb and NoSQL
Beginner's guide to Mongodb and NoSQL  Beginner's guide to Mongodb and NoSQL
Beginner's guide to Mongodb and NoSQL
 
Open Source Databases And Gis
Open Source Databases And GisOpen Source Databases And Gis
Open Source Databases And Gis
 
Au09 Presentation Ut118 1
Au09 Presentation Ut118 1Au09 Presentation Ut118 1
Au09 Presentation Ut118 1
 
Open Source GIS
Open Source GISOpen Source GIS
Open Source GIS
 
What is spatial sql
What is spatial sqlWhat is spatial sql
What is spatial sql
 
Magellan FOSS4G Talk, Boston 2017
Magellan FOSS4G Talk, Boston 2017Magellan FOSS4G Talk, Boston 2017
Magellan FOSS4G Talk, Boston 2017
 
Big Data Analytics 2014
Big Data Analytics 2014Big Data Analytics 2014
Big Data Analytics 2014
 
MongoDB eBook a complete guide to beginners
MongoDB eBook a complete guide to beginnersMongoDB eBook a complete guide to beginners
MongoDB eBook a complete guide to beginners
 
Big Data SSD Architecture: Digging Deep to Discover Where SSD Performance Pay...
Big Data SSD Architecture: Digging Deep to Discover Where SSD Performance Pay...Big Data SSD Architecture: Digging Deep to Discover Where SSD Performance Pay...
Big Data SSD Architecture: Digging Deep to Discover Where SSD Performance Pay...
 
GIS Data Types
GIS Data TypesGIS Data Types
GIS Data Types
 
How to empower community by using GIS lecture 1
How to empower community by using GIS lecture 1How to empower community by using GIS lecture 1
How to empower community by using GIS lecture 1
 
Which NoSQL Database to Combine with Spark for Real Time Big Data Analytics?
Which NoSQL Database to Combine with Spark for Real Time Big Data Analytics?Which NoSQL Database to Combine with Spark for Real Time Big Data Analytics?
Which NoSQL Database to Combine with Spark for Real Time Big Data Analytics?
 
CouchBase The Complete NoSql Solution for Big Data
CouchBase The Complete NoSql Solution for Big DataCouchBase The Complete NoSql Solution for Big Data
CouchBase The Complete NoSql Solution for Big Data
 
Components of gis
Components of gisComponents of gis
Components of gis
 
What is GIS?
What is GIS?What is GIS?
What is GIS?
 
NO SQL: What, Why, How
NO SQL: What, Why, HowNO SQL: What, Why, How
NO SQL: What, Why, How
 

Recently uploaded

International Workshop on Artificial Intelligence in Software Testing
International Workshop on Artificial Intelligence in Software TestingInternational Workshop on Artificial Intelligence in Software Testing
International Workshop on Artificial Intelligence in Software Testing
Sebastiano Panichella
 
María Carolina Martínez - eCommerce Day Colombia 2024
María Carolina Martínez - eCommerce Day Colombia 2024María Carolina Martínez - eCommerce Day Colombia 2024
María Carolina Martínez - eCommerce Day Colombia 2024
eCommerce Institute
 
Eureka, I found it! - Special Libraries Association 2021 Presentation
Eureka, I found it! - Special Libraries Association 2021 PresentationEureka, I found it! - Special Libraries Association 2021 Presentation
Eureka, I found it! - Special Libraries Association 2021 Presentation
Access Innovations, Inc.
 
0x01 - Newton's Third Law: Static vs. Dynamic Abusers
0x01 - Newton's Third Law:  Static vs. Dynamic Abusers0x01 - Newton's Third Law:  Static vs. Dynamic Abusers
0x01 - Newton's Third Law: Static vs. Dynamic Abusers
OWASP Beja
 
Supercharge your AI - SSP Industry Breakout Session 2024-v2_1.pdf
Supercharge your AI - SSP Industry Breakout Session 2024-v2_1.pdfSupercharge your AI - SSP Industry Breakout Session 2024-v2_1.pdf
Supercharge your AI - SSP Industry Breakout Session 2024-v2_1.pdf
Access Innovations, Inc.
 
Media as a Mind Controlling Strategy In Old and Modern Era
Media as a Mind Controlling Strategy In Old and Modern EraMedia as a Mind Controlling Strategy In Old and Modern Era
Media as a Mind Controlling Strategy In Old and Modern Era
faizulhassanfaiz1670
 
Competition and Regulation in Professional Services – KLEINER – June 2024 OEC...
Competition and Regulation in Professional Services – KLEINER – June 2024 OEC...Competition and Regulation in Professional Services – KLEINER – June 2024 OEC...
Competition and Regulation in Professional Services – KLEINER – June 2024 OEC...
OECD Directorate for Financial and Enterprise Affairs
 
Doctoral Symposium at the 17th IEEE International Conference on Software Test...
Doctoral Symposium at the 17th IEEE International Conference on Software Test...Doctoral Symposium at the 17th IEEE International Conference on Software Test...
Doctoral Symposium at the 17th IEEE International Conference on Software Test...
Sebastiano Panichella
 
Sharpen existing tools or get a new toolbox? Contemporary cluster initiatives...
Sharpen existing tools or get a new toolbox? Contemporary cluster initiatives...Sharpen existing tools or get a new toolbox? Contemporary cluster initiatives...
Sharpen existing tools or get a new toolbox? Contemporary cluster initiatives...
Orkestra
 
somanykidsbutsofewfathers-140705000023-phpapp02.pptx
somanykidsbutsofewfathers-140705000023-phpapp02.pptxsomanykidsbutsofewfathers-140705000023-phpapp02.pptx
somanykidsbutsofewfathers-140705000023-phpapp02.pptx
Howard Spence
 
Obesity causes and management and associated medical conditions
Obesity causes and management and associated medical conditionsObesity causes and management and associated medical conditions
Obesity causes and management and associated medical conditions
Faculty of Medicine And Health Sciences
 
Gregory Harris' Civics Presentation.pptx
Gregory Harris' Civics Presentation.pptxGregory Harris' Civics Presentation.pptx
Gregory Harris' Civics Presentation.pptx
gharris9
 
Acorn Recovery: Restore IT infra within minutes
Acorn Recovery: Restore IT infra within minutesAcorn Recovery: Restore IT infra within minutes
Acorn Recovery: Restore IT infra within minutes
IP ServerOne
 
Announcement of 18th IEEE International Conference on Software Testing, Verif...
Announcement of 18th IEEE International Conference on Software Testing, Verif...Announcement of 18th IEEE International Conference on Software Testing, Verif...
Announcement of 18th IEEE International Conference on Software Testing, Verif...
Sebastiano Panichella
 
Bitcoin Lightning wallet and tic-tac-toe game XOXO
Bitcoin Lightning wallet and tic-tac-toe game XOXOBitcoin Lightning wallet and tic-tac-toe game XOXO
Bitcoin Lightning wallet and tic-tac-toe game XOXO
Matjaž Lipuš
 
Bonzo subscription_hjjjjjjjj5hhhhhhh_2024.pdf
Bonzo subscription_hjjjjjjjj5hhhhhhh_2024.pdfBonzo subscription_hjjjjjjjj5hhhhhhh_2024.pdf
Bonzo subscription_hjjjjjjjj5hhhhhhh_2024.pdf
khadija278284
 
Getting started with Amazon Bedrock Studio and Control Tower
Getting started with Amazon Bedrock Studio and Control TowerGetting started with Amazon Bedrock Studio and Control Tower
Getting started with Amazon Bedrock Studio and Control Tower
Vladimir Samoylov
 

Recently uploaded (17)

International Workshop on Artificial Intelligence in Software Testing
International Workshop on Artificial Intelligence in Software TestingInternational Workshop on Artificial Intelligence in Software Testing
International Workshop on Artificial Intelligence in Software Testing
 
María Carolina Martínez - eCommerce Day Colombia 2024
María Carolina Martínez - eCommerce Day Colombia 2024María Carolina Martínez - eCommerce Day Colombia 2024
María Carolina Martínez - eCommerce Day Colombia 2024
 
Eureka, I found it! - Special Libraries Association 2021 Presentation
Eureka, I found it! - Special Libraries Association 2021 PresentationEureka, I found it! - Special Libraries Association 2021 Presentation
Eureka, I found it! - Special Libraries Association 2021 Presentation
 
0x01 - Newton's Third Law: Static vs. Dynamic Abusers
0x01 - Newton's Third Law:  Static vs. Dynamic Abusers0x01 - Newton's Third Law:  Static vs. Dynamic Abusers
0x01 - Newton's Third Law: Static vs. Dynamic Abusers
 
Supercharge your AI - SSP Industry Breakout Session 2024-v2_1.pdf
Supercharge your AI - SSP Industry Breakout Session 2024-v2_1.pdfSupercharge your AI - SSP Industry Breakout Session 2024-v2_1.pdf
Supercharge your AI - SSP Industry Breakout Session 2024-v2_1.pdf
 
Media as a Mind Controlling Strategy In Old and Modern Era
Media as a Mind Controlling Strategy In Old and Modern EraMedia as a Mind Controlling Strategy In Old and Modern Era
Media as a Mind Controlling Strategy In Old and Modern Era
 
Competition and Regulation in Professional Services – KLEINER – June 2024 OEC...
Competition and Regulation in Professional Services – KLEINER – June 2024 OEC...Competition and Regulation in Professional Services – KLEINER – June 2024 OEC...
Competition and Regulation in Professional Services – KLEINER – June 2024 OEC...
 
Doctoral Symposium at the 17th IEEE International Conference on Software Test...
Doctoral Symposium at the 17th IEEE International Conference on Software Test...Doctoral Symposium at the 17th IEEE International Conference on Software Test...
Doctoral Symposium at the 17th IEEE International Conference on Software Test...
 
Sharpen existing tools or get a new toolbox? Contemporary cluster initiatives...
Sharpen existing tools or get a new toolbox? Contemporary cluster initiatives...Sharpen existing tools or get a new toolbox? Contemporary cluster initiatives...
Sharpen existing tools or get a new toolbox? Contemporary cluster initiatives...
 
somanykidsbutsofewfathers-140705000023-phpapp02.pptx
somanykidsbutsofewfathers-140705000023-phpapp02.pptxsomanykidsbutsofewfathers-140705000023-phpapp02.pptx
somanykidsbutsofewfathers-140705000023-phpapp02.pptx
 
Obesity causes and management and associated medical conditions
Obesity causes and management and associated medical conditionsObesity causes and management and associated medical conditions
Obesity causes and management and associated medical conditions
 
Gregory Harris' Civics Presentation.pptx
Gregory Harris' Civics Presentation.pptxGregory Harris' Civics Presentation.pptx
Gregory Harris' Civics Presentation.pptx
 
Acorn Recovery: Restore IT infra within minutes
Acorn Recovery: Restore IT infra within minutesAcorn Recovery: Restore IT infra within minutes
Acorn Recovery: Restore IT infra within minutes
 
Announcement of 18th IEEE International Conference on Software Testing, Verif...
Announcement of 18th IEEE International Conference on Software Testing, Verif...Announcement of 18th IEEE International Conference on Software Testing, Verif...
Announcement of 18th IEEE International Conference on Software Testing, Verif...
 
Bitcoin Lightning wallet and tic-tac-toe game XOXO
Bitcoin Lightning wallet and tic-tac-toe game XOXOBitcoin Lightning wallet and tic-tac-toe game XOXO
Bitcoin Lightning wallet and tic-tac-toe game XOXO
 
Bonzo subscription_hjjjjjjjj5hhhhhhh_2024.pdf
Bonzo subscription_hjjjjjjjj5hhhhhhh_2024.pdfBonzo subscription_hjjjjjjjj5hhhhhhh_2024.pdf
Bonzo subscription_hjjjjjjjj5hhhhhhh_2024.pdf
 
Getting started with Amazon Bedrock Studio and Control Tower
Getting started with Amazon Bedrock Studio and Control TowerGetting started with Amazon Bedrock Studio and Control Tower
Getting started with Amazon Bedrock Studio and Control Tower
 

Adelaide Ruby Meetup PostGIS Notes

  • 2. What is PostGIS A set of geo-spatial extensions for the PostgreSQL database And for those who don’t know, PostgreSQL is an SQL database similar to MySQL & MS SQL Server
  • 3. What do I need to know about geo-spatial ‘stuff’ to get going? It depends entirely on what you’re doing :)
  • 5. With these Blocks, 
 we can ask: Does this LineString intersect any Polygons? Which Polygons does a Point exist within? How much do these Polygons overlap? What are the closest alternative Points to this Point? much, much more
  • 6. SRID? Spatial Reference ID Need to understand that when displaying a 3D world on a 2D screen, decisions on how to need to be made
  • 7. SRID? Much like a graph needs labeled axis to mean anything, SRIDs provide context to correctly interpret spatial coordinates There’s a collation of industry standard SRID’s that get setup on your db - look at your shiny new spatial_ref_sys table Rule of thumb - unless you know better, just use 4326 :)
  • 8. Spatial Indexes Greatly improves the speed of querying complex spatial datasets
  • 9. Pulling this all into 
 Ruby Land! RGeo provides the spatial ‘building blocks’ for Ruby ActiveRecord PostGIS Adapter provides the migration support & RGeo type casting layer to ActiveRecord/Rails
  • 10. RGeo https://github.com/rgeo/rgeo ‘An implementation of the industry standard OGC Simple Features Specification, which provides data representations of geometric objects such as points, lines and polygons, along with a set of geometric analysis operations.’
  • 11. What’s missing? A nice abstraction layer allowing scoped spatial queries
 i.e.
 Hotel.near(location).with_wifi
 Region.within(country)
 country.outside?(region)
  • 12. Common Spatial Commands ST_Intersects
 Does a line or polygon intersect with another line or polygon?
 Useful for ‘areas travelled through’ or ‘area union’ kind of questions ST_DWithin
 Lets us ask whether a geographic object is within a certain distance of another geographic object ST_Contains
 Do all given points lie within a given polygon? ST_Overlaps
 Do 2 different geometries share space?
  • 13. Common Spatial Commands Plenty more, check out the API!
  • 14. So, what is this good for? Criminally underused in the web dev world Incredibly powerful for providing context to applications that utilise location related data
 (in the Rails world, think mobile APIs…) Great for data analysis & strategically targeting markets - think growth hacking!
  • 15. So, what is this good for? Working with existing spatial datasets
  • 16. ESRI Shapefile A popular format for storing geometric location information & associated metadata Used heavily by the Australian Government
 - e.g. municipal boundaries, ABS data & census data Most of our friendly geo-spatial software will happily find a way to work with this data format
  • 17. Some Gotchas Make sure your schema includes the postgis extension Don’t delete the spatial_ref_sys table! Pay close attention to your SRIDs, and unless you’re sure, stick to using 4326 on your db When importing data, convert it to 4326 if a data source is in a different SRID
  • 18. Some Gotchas Rails likes to use SELECT table.* - beware that this can be painful to performance if your table contains lots of intricate spatial data. Consider using a join to store complex data in a separate table & only call when necessary. Even with spatial indexing, large datasets can become a burden on the database. Consider using traditional id based relationships as a cache for complex geospatial result sets.
  • 19. Alternatives MySQL Spatial Extensions Not as mature as PostGIS Only MyISAM supports spatial indexes - ok if you’re not into data retention :) SQL Server More mature than MySQL & not a bad choice if you’re a MS Shop
  • 20. Alternatives Oracle Spatial I’ve heard it’s pretty good if you have the wallet for it! I’ve also been informed that there’s a free version that may cut it for many people :) MongoDB Great for basic geospatial functionality Not as fully featured as PostGIS, may leave you wanting in certain areas
  • 21. Getting Started in Rails First step: Get a copy of PostgreSQL & PostGIS Easiest way on OS/X is to grab Postgres.app from http://postgresapp.com/ Grab a copy of QGIS while you’re at it - 
 http://www.kyngchaos.com/software/qgis for Mac users
  • 22. Getting Started in Rails rails new spatial_project -d postgresql! gem ‘activerecord-postgis-adapter’
 Gemfile! adapter: postgis
 config/database.yml! rake db:create! rake db:gis:setup
  • 23. Getting Started in Rails You can now run migrations like these:
 
 create_table :spatials, do |t|
 t.string :name,
 t.multi_polygon, :area, srid: 4326,
 t.point, :position, srid: 4326,
 t.line_string, :path, srid: 4326
 end
  • 24. Getting Started in Rails And create spatial indexes like this:
 
 add_index :spatials, :area, spatial: true