SlideShare une entreprise Scribd logo
1  sur  43
Geospatial applications
on Rails
Sergey Nartimov
Brainspec
https://github.com/lest
twitter: @just_lest
About
• Rails, Rubinius, Elixir contributor
• Software engineer at Brainspec
Sergey Nartimov
Brainspec
https://github.com/lest
twitter: @just_lest
Geospatial data
Geospatial data types
• Point
• Linestring
• Polygon
• Multi...
• Geometry collection
Geospatial analysis
• Coverage
• Intersection
• Distance
• etc.
Geographic coordinate
system
Geographic distance
Map projection
Mercator projection
Mercator projection
Mercator projection
Geospatial support
Geospatial support
• MySQL
• http://dev.mysql.com/doc/refman/5.5/en/
spatial-extensions.html
Geospatial support
• MongoDB
• http://www.mongodb.org/display/DOCS/
Geospatial+Indexing
Geospatial support
• SpatiaLite
• http://www.gaia-gis.it/gaia-sins/splite-
doxy-4.0.0/index.html
Geospatial support
• PostGIS
• http://postgis.org/docs/
Rails & PostGIS
• https://github.com/dazuma/activerecord-
postgis-adapter
• https://github.com/dazuma/rgeo
# config/database.yml
adapter: postgis
# When postgresql >= 9.1 and postgis >= 2.0
postgis_extension: true
# When postgresql < 9.1 or postgis < 2.0
# e.g. for postgresql 9.1 and postgis 1.5 on ubuntu
script_dir: "/usr/share/postgresql/9.1/contrib/postgis-1.5"
schema_search_path: public,postgis
create_table :locations do |t|
t.point :coords, geographic: true
end
create_table :locations do |t|
t.string :text
t.point :coords, srid: 3785
end
add_index :locations, :coords, spatial: true
class Location < ActiveRecord::Base
GEOFACTORY =
RGeo::Geographic.spherical_factory(srid: 4326)
set_rgeo_factory_for_column :coords, GEOFACTORY
end
Points in radius
point = Location::GEOFACTORY.point(27, 53)
radius = 50_000 # 50 km
Location.where('st_dwithin(coords, ?, ?)', point, radius)
.order('st_distance(coords, ?)', point)
Squeel
• https://github.com/ernie/squeel
point = Location::GEOFACTORY.point(27, 53)
radius = 50_000 # 50 km
Location.where { st_dwithin(coords, point, radius) }
.order { st_distance(coords, point) }
class Location < ActiveRecord::Base
GEOFACTORY = RGeo::Geographic.simple_mercator_factory
set_rgeo_factory_for_column :coords,
GEOFACTORY.projection_factory
end
point = Location::GEOFACTORY.point(27, 53)
radius = 50_000 / Math.cos(lat * Math::PI / 180.0)
Location.where { st_dwithin(coords, point, radius) }
.order { st_distance(coords, point) }
Points in bounding box
sw = Location::GEOFACTORY.point(48.389537, 54.306922)
ne = Location::GEOFACTORY.point(48.399643, 54.311216)
bbox =
RGeo::Cartesian::BoundingBox.create_from_points(sw, ne)
Location.where('coords && ?', bbox)
Clustering
• http://pgxn.org/dist/kmeans/
• http://postgis.refractions.net/docs/
ST_SnapToGrid.html
Time zones example
• http://efele.net/maps/tz/world/
• https://github.com/dazuma/rgeo-shapefile
class CreateTimeZonePolygons < ActiveRecord::Migration
def change
create_table :time_zone_polygons do |t|
t.string :tzid
t.geometry :geometry, geographic: true
t.timestamps
end
add_index :time_zone_polygons, :geometry, spatial: true
end
end
class TimeZonePolygon < ActiveRecord::Base
set_rgeo_factory_for_column :geometry,
RGeo::Geographic.spherical_factory(srid: 4326)
end
RGeo::Shapefile::Reader.open('tz_world.shp') do |file|
file.each do |record|
polygon = TimeZonePolygon.new
polygon.tzid = record.attributes['TZID']
polygon.geometry = record.geometry
polygon.save!
end
end
point = TimeZonePolygon::GEOFACTORY.point(27, 53)
time_zone = TimeZonePolygon
.where { st_covers(geometry, point) }.first
time_zone.tzid # => "Europe/Minsk"
• Further improvements
Thanks <3
Sergey Nartimov
Brainspec
https://github.com/lest
twitter: @just_lest

Contenu connexe

Similaire à Geospatial Rails applications

DATABASE & WEBGIS - GIS BOOTCAMP
DATABASE & WEBGIS - GIS BOOTCAMPDATABASE & WEBGIS - GIS BOOTCAMP
DATABASE & WEBGIS - GIS BOOTCAMP
Kevin Ng'eno
 
Map4rdf - Faceted Browser for Geospatial Datasets
Map4rdf - Faceted Browser for Geospatial DatasetsMap4rdf - Faceted Browser for Geospatial Datasets
Map4rdf - Faceted Browser for Geospatial Datasets
Boris Villazón-Terrazas
 
WORLDMAP: A SPATIAL INFRASTRUCTURE TO SUPPORT TEACHING AND RESEARCH (BROWN BA...
WORLDMAP: A SPATIAL INFRASTRUCTURE TO SUPPORT TEACHING AND RESEARCH (BROWN BA...WORLDMAP: A SPATIAL INFRASTRUCTURE TO SUPPORT TEACHING AND RESEARCH (BROWN BA...
WORLDMAP: A SPATIAL INFRASTRUCTURE TO SUPPORT TEACHING AND RESEARCH (BROWN BA...
Micah Altman
 
“Webmapping Solutions: Technology & Tips” -- November 13, 2013
“Webmapping Solutions: Technology & Tips” -- November 13, 2013“Webmapping Solutions: Technology & Tips” -- November 13, 2013
“Webmapping Solutions: Technology & Tips” -- November 13, 2013
Aerial Services
 

Similaire à Geospatial Rails applications (20)

rubykaigi2011_spatial.key
rubykaigi2011_spatial.keyrubykaigi2011_spatial.key
rubykaigi2011_spatial.key
 
Integrating PostGIS in Web Applications
Integrating PostGIS in Web ApplicationsIntegrating PostGIS in Web Applications
Integrating PostGIS in Web Applications
 
Coding Dojo - Surrey Rubyists #2 - 26 April 2011
Coding Dojo - Surrey Rubyists #2 - 26 April 2011Coding Dojo - Surrey Rubyists #2 - 26 April 2011
Coding Dojo - Surrey Rubyists #2 - 26 April 2011
 
DATABASE & WEBGIS - GIS BOOTCAMP
DATABASE & WEBGIS - GIS BOOTCAMPDATABASE & WEBGIS - GIS BOOTCAMP
DATABASE & WEBGIS - GIS BOOTCAMP
 
5 Popular Choices for NoSQL on a Microsoft Platform - Tulsa - July 2018
5 Popular Choices for NoSQL on a Microsoft Platform - Tulsa - July 20185 Popular Choices for NoSQL on a Microsoft Platform - Tulsa - July 2018
5 Popular Choices for NoSQL on a Microsoft Platform - Tulsa - July 2018
 
Multidimensional Scientific Data in ArcGIS
Multidimensional Scientific Data in ArcGISMultidimensional Scientific Data in ArcGIS
Multidimensional Scientific Data in ArcGIS
 
5 NoSQL Options - Toronto - May 2018
5 NoSQL Options - Toronto - May 20185 NoSQL Options - Toronto - May 2018
5 NoSQL Options - Toronto - May 2018
 
5 Popular Choices for NoSQL on a Microsoft Platform
5 Popular Choices for NoSQL on a Microsoft Platform5 Popular Choices for NoSQL on a Microsoft Platform
5 Popular Choices for NoSQL on a Microsoft Platform
 
5 Popular Choices for NoSQL on a Microsoft Platform - All Things Open - Octob...
5 Popular Choices for NoSQL on a Microsoft Platform - All Things Open - Octob...5 Popular Choices for NoSQL on a Microsoft Platform - All Things Open - Octob...
5 Popular Choices for NoSQL on a Microsoft Platform - All Things Open - Octob...
 
SDI: A prespective from a UK archaeological unit
SDI: A prespective from a UK archaeological unitSDI: A prespective from a UK archaeological unit
SDI: A prespective from a UK archaeological unit
 
Day 6 - PostGIS
Day 6 - PostGISDay 6 - PostGIS
Day 6 - PostGIS
 
Saving Money with Open Source GIS
Saving Money with Open Source GISSaving Money with Open Source GIS
Saving Money with Open Source GIS
 
Map4rdf - Faceted Browser for Geospatial Datasets
Map4rdf - Faceted Browser for Geospatial DatasetsMap4rdf - Faceted Browser for Geospatial Datasets
Map4rdf - Faceted Browser for Geospatial Datasets
 
Be faster then rabbits
Be faster then rabbitsBe faster then rabbits
Be faster then rabbits
 
WORLDMAP: A SPATIAL INFRASTRUCTURE TO SUPPORT TEACHING AND RESEARCH (BROWN BA...
WORLDMAP: A SPATIAL INFRASTRUCTURE TO SUPPORT TEACHING AND RESEARCH (BROWN BA...WORLDMAP: A SPATIAL INFRASTRUCTURE TO SUPPORT TEACHING AND RESEARCH (BROWN BA...
WORLDMAP: A SPATIAL INFRASTRUCTURE TO SUPPORT TEACHING AND RESEARCH (BROWN BA...
 
“Webmapping Solutions: Technology & Tips” -- November 13, 2013
“Webmapping Solutions: Technology & Tips” -- November 13, 2013“Webmapping Solutions: Technology & Tips” -- November 13, 2013
“Webmapping Solutions: Technology & Tips” -- November 13, 2013
 
MongoDB Basics
MongoDB BasicsMongoDB Basics
MongoDB Basics
 
2013 Vendor, MapQuest Plugins for Leaflet by Jonathan Harahush
2013 Vendor, MapQuest Plugins for Leaflet by Jonathan Harahush2013 Vendor, MapQuest Plugins for Leaflet by Jonathan Harahush
2013 Vendor, MapQuest Plugins for Leaflet by Jonathan Harahush
 
2017 GIS in Education Track: Sharing Historical Maps and Atlases in Web Apps
2017 GIS in Education Track: Sharing Historical Maps and Atlases in Web Apps2017 GIS in Education Track: Sharing Historical Maps and Atlases in Web Apps
2017 GIS in Education Track: Sharing Historical Maps and Atlases in Web Apps
 
ArcGIS and Multi-D: Tools & Roadmap
ArcGIS and Multi-D: Tools & RoadmapArcGIS and Multi-D: Tools & Roadmap
ArcGIS and Multi-D: Tools & Roadmap
 

Plus de Olga Lavrentieva

«Обзор возможностей Open cv»
«Обзор возможностей Open cv»«Обзор возможностей Open cv»
«Обзор возможностей Open cv»
Olga Lavrentieva
 

Plus de Olga Lavrentieva (20)

15 10-22 altoros-fact_sheet_st_v4
15 10-22 altoros-fact_sheet_st_v415 10-22 altoros-fact_sheet_st_v4
15 10-22 altoros-fact_sheet_st_v4
 
Сергей Ковалёв (Altoros): Practical Steps to Improve Apache Hive Performance
Сергей Ковалёв (Altoros): Practical Steps to Improve Apache Hive PerformanceСергей Ковалёв (Altoros): Practical Steps to Improve Apache Hive Performance
Сергей Ковалёв (Altoros): Practical Steps to Improve Apache Hive Performance
 
Андрей Козлов (Altoros): Оптимизация производительности Cassandra
Андрей Козлов (Altoros): Оптимизация производительности CassandraАндрей Козлов (Altoros): Оптимизация производительности Cassandra
Андрей Козлов (Altoros): Оптимизация производительности Cassandra
 
Владимир Иванов (Oracle): Java: прошлое и будущее
Владимир Иванов (Oracle): Java: прошлое и будущееВладимир Иванов (Oracle): Java: прошлое и будущее
Владимир Иванов (Oracle): Java: прошлое и будущее
 
Brug - Web push notification
Brug  - Web push notificationBrug  - Web push notification
Brug - Web push notification
 
Александр Ломов: "Reactjs + Haskell + Cloud Foundry = Love"
Александр Ломов: "Reactjs + Haskell + Cloud Foundry = Love"Александр Ломов: "Reactjs + Haskell + Cloud Foundry = Love"
Александр Ломов: "Reactjs + Haskell + Cloud Foundry = Love"
 
Максим Жилинский: "Контейнеры: под капотом"
Максим Жилинский: "Контейнеры: под капотом"Максим Жилинский: "Контейнеры: под капотом"
Максим Жилинский: "Контейнеры: под капотом"
 
Александр Протасеня: "PayPal. Различные способы интеграции"
Александр Протасеня: "PayPal. Различные способы интеграции"Александр Протасеня: "PayPal. Различные способы интеграции"
Александр Протасеня: "PayPal. Различные способы интеграции"
 
Сергей Черничков: "Интеграция платежных систем в .Net приложения"
Сергей Черничков: "Интеграция платежных систем в .Net приложения"Сергей Черничков: "Интеграция платежных систем в .Net приложения"
Сергей Черничков: "Интеграция платежных систем в .Net приложения"
 
Антон Шемерей «Single responsibility principle в руби или почему instanceclas...
Антон Шемерей «Single responsibility principle в руби или почему instanceclas...Антон Шемерей «Single responsibility principle в руби или почему instanceclas...
Антон Шемерей «Single responsibility principle в руби или почему instanceclas...
 
Егор Воробьёв: «Ruby internals»
Егор Воробьёв: «Ruby internals»Егор Воробьёв: «Ruby internals»
Егор Воробьёв: «Ruby internals»
 
Андрей Колешко «Что не так с Rails»
Андрей Колешко «Что не так с Rails»Андрей Колешко «Что не так с Rails»
Андрей Колешко «Что не так с Rails»
 
Дмитрий Савицкий «Ruby Anti Magic Shield»
Дмитрий Савицкий «Ruby Anti Magic Shield»Дмитрий Савицкий «Ruby Anti Magic Shield»
Дмитрий Савицкий «Ruby Anti Magic Shield»
 
Сергей Алексеев «Парное программирование. Удаленно»
Сергей Алексеев «Парное программирование. Удаленно»Сергей Алексеев «Парное программирование. Удаленно»
Сергей Алексеев «Парное программирование. Удаленно»
 
«Почему Spark отнюдь не так хорош»
«Почему Spark отнюдь не так хорош»«Почему Spark отнюдь не так хорош»
«Почему Spark отнюдь не так хорош»
 
«Cassandra data modeling – моделирование данных для NoSQL СУБД Cassandra»
«Cassandra data modeling – моделирование данных для NoSQL СУБД Cassandra»«Cassandra data modeling – моделирование данных для NoSQL СУБД Cassandra»
«Cassandra data modeling – моделирование данных для NoSQL СУБД Cassandra»
 
«Практика построения высокодоступного решения на базе Cloud Foundry Paas»
«Практика построения высокодоступного решения на базе Cloud Foundry Paas»«Практика построения высокодоступного решения на базе Cloud Foundry Paas»
«Практика построения высокодоступного решения на базе Cloud Foundry Paas»
 
«Дизайн продвинутых нереляционных схем для Big Data»
«Дизайн продвинутых нереляционных схем для Big Data»«Дизайн продвинутых нереляционных схем для Big Data»
«Дизайн продвинутых нереляционных схем для Big Data»
 
«Обзор возможностей Open cv»
«Обзор возможностей Open cv»«Обзор возможностей Open cv»
«Обзор возможностей Open cv»
 
«Нужно больше шин! Eventbus based framework vertx.io»
«Нужно больше шин! Eventbus based framework vertx.io»«Нужно больше шин! Eventbus based framework vertx.io»
«Нужно больше шин! Eventbus based framework vertx.io»
 

Dernier

Dernier (20)

What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 

Geospatial Rails applications