SlideShare une entreprise Scribd logo
1  sur  31
Télécharger pour lire hors ligne
GIS on Rails
Сергій Тятін Full-stack web developer
GIS
1. Трохи теорії
2. Інструменти
3. PostGiS SQL
Geoid
Datum WGS 84
Датум (лат. Datum) — набір параметрів, які
використовуються для зміщення і
трансформації референц-еліпсоїду в
локальні географічні координати.
Mercator projection
SRID
Spatial Reference System Identifier
SRID=4326;POINT(24.0267731
49.8386644)
SRID=3785;POINT(2674648.14689752
6418382.09688131)
Інструменти
• PostGIS (http://postgis.net/)
• gem ‘rgeo’
• gem 'activerecord-postgis-adapter’
PostGIS
• Geometry, Geography functions
• Data types: POINT, LINESTRING, POLYGON, CURVE ..
gem ‘rgeo’
• репрезентація данних
• базові функції
gem ‘activerecord-postgis-
adapter’
The activerecord-postgis-adapter provides access to
features of the PostGIS geospatial database from
ActiveRecord
Історія створення стартапа для
car-pooling
Як працює
Дошка оголошень
Маршрути водіів
Запити пасажирів
Матчінг
Запис маршрута водія
GPS locations
geometry ST_MakeLine(geometry
set geoms)
Алгоритм Рамера —
Дугласа — Пекера
geometry ST_Simplify(geometry
geomA, float tolerance);
Порівняння маршрутів
• Мають починатися і закінчуватись поряд
• Мають проходити поряд
boolean ST_DWithin(geography gg1,
geography gg2, double precision
distance_meters);
Мають починатися і
закінчуватись поряд
SELECT
FROM routes WHERE
ST_DWithin( ?, routes.start, 500)
AND
ST_DWithin( ?, routes.end, 500)
Мають проходити поряд
Відстань Гаусдорфа
float ST_HausdorffDistance(geometry
g1, geometry g2);
SELECT * FROM (
SELECT ST_HausdorffDistance(routes.route, ? )
as distance, …
FROM routes WHERE
ST_DWithin( ?, routes.start, 500)
AND
ST_DWithin( ?, routes.end, 500)
) ORDER BY distance ASC LIMIT 1
Знайти маршрути для
пассажира
start
finish
• Місце зустрічі/виходу близько
• Де найкраще зустрітись/вийти
• Напрямок має значення
Місце зустрічі/виходу
близько
SELECT
FROM routes
WHERE
ST_DWithin(routes.route, ?, 500 )
AND

ST_DWithin(routes.route, ?, 500 )
Де найкраще зустрітись/вийти
Найближча точка
geometry ST_ClosestPoint(geometry g1, geometry g2);
Де найкраще зустрітись/
вийти
SELECT
ST_ClosestPoint(route, ?) as pickup_location,

ST_ClosestPoint(route, ?) as drop_location,
FROM routes
WHERE
ST_DWithin(routes.route, ?, 500 )
AND

ST_DWithin(routes.route, ?, 500 )
Напрямок має значення
Маємо вибрати тільки ті маршрути які йдуть від
точки старт до точки фініш
float ST_LineLocatePoint(geometry a_linestring,
geometry a_point);
Повертає значення між 0 та 1 яке визначає
положення найближчої точки на лінії до заданої
точки
Напрямок має значення
SELECT
ST_LineLocatePoint(route, ?) as pickup_float,

ST_LineLocatePoint(route, ?) as drop_float,
ST_ClosestPoint(route, ?) as pickup_location,

ST_ClosestPoint(route, ?) as drop_location,
FROM routes
WHERE
ST_DWithin(routes.route, ?, 500 )
AND

ST_DWithin(routes.route, ?, 500 )
Дякую за увагу
Сергій Тятін
700@2rba.com
skype: tyatin
DRIDER.IO

Contenu connexe

En vedette

Trailblazer Introduction by Nick Sutterer
Trailblazer Introduction by Nick SuttererTrailblazer Introduction by Nick Sutterer
Trailblazer Introduction by Nick SuttererPivorak MeetUp
 
Building Component Based Rails Applications. Part 2.
Building Component Based Rails Applications. Part 2.Building Component Based Rails Applications. Part 2.
Building Component Based Rails Applications. Part 2.Pivorak MeetUp
 
Functional Immutable CSS
Functional Immutable CSS Functional Immutable CSS
Functional Immutable CSS Pivorak MeetUp
 
The Silver Bullet Syndrome by Alexey Vasiliev
The Silver Bullet Syndrome by Alexey VasilievThe Silver Bullet Syndrome by Alexey Vasiliev
The Silver Bullet Syndrome by Alexey VasilievPivorak MeetUp
 
Digital Nomading on Rails
Digital Nomading on RailsDigital Nomading on Rails
Digital Nomading on RailsPivorak MeetUp
 
"5 skills to master" by Alexander Skakunov
"5 skills to master" by Alexander Skakunov"5 skills to master" by Alexander Skakunov
"5 skills to master" by Alexander SkakunovPivorak MeetUp
 
Building component based rails applications. part 1.
Building component based rails applications. part 1.Building component based rails applications. part 1.
Building component based rails applications. part 1.Pivorak MeetUp
 
Права інтелектуальної власності в IT сфері.
Права інтелектуальної власності  в IT сфері.Права інтелектуальної власності  в IT сфері.
Права інтелектуальної власності в IT сфері.Pivorak MeetUp
 
Pivorak Clojure by Dmytro Bignyak
Pivorak Clojure by Dmytro BignyakPivorak Clojure by Dmytro Bignyak
Pivorak Clojure by Dmytro BignyakPivorak MeetUp
 
Andriy Vandakurov about "Frontend. Global domination"
Andriy Vandakurov about  "Frontend. Global domination" Andriy Vandakurov about  "Frontend. Global domination"
Andriy Vandakurov about "Frontend. Global domination" Pivorak MeetUp
 
“Object Oriented Ruby” by Michał Papis.
“Object Oriented Ruby” by Michał Papis.“Object Oriented Ruby” by Michał Papis.
“Object Oriented Ruby” by Michał Papis.Pivorak MeetUp
 
"Meet rom_rb & dry_rb" by Piotr Solnica
"Meet rom_rb & dry_rb" by Piotr Solnica"Meet rom_rb & dry_rb" by Piotr Solnica
"Meet rom_rb & dry_rb" by Piotr SolnicaPivorak MeetUp
 
Pivorak How to write better sentences in English
Pivorak How to write better sentences in EnglishPivorak How to write better sentences in English
Pivorak How to write better sentences in EnglishPivorak MeetUp
 
HTML Canvas tips & tricks - Lightning Talk by Roman Rodych
 HTML Canvas tips & tricks - Lightning Talk by Roman Rodych HTML Canvas tips & tricks - Lightning Talk by Roman Rodych
HTML Canvas tips & tricks - Lightning Talk by Roman RodychPivorak MeetUp
 
Broker: adventure through architecture pattern
Broker: adventure through architecture patternBroker: adventure through architecture pattern
Broker: adventure through architecture patternPivorak MeetUp
 
Ramda lets write declarative js
Ramda   lets write declarative jsRamda   lets write declarative js
Ramda lets write declarative jsPivorak MeetUp
 
Flowex - Railway Flow-Based Programming with Elixir GenStage.
Flowex - Railway Flow-Based Programming with Elixir GenStage.Flowex - Railway Flow-Based Programming with Elixir GenStage.
Flowex - Railway Flow-Based Programming with Elixir GenStage.Anton Mishchuk
 
Linux Tracing Superpowers by Eugene Pirogov
Linux Tracing Superpowers by Eugene PirogovLinux Tracing Superpowers by Eugene Pirogov
Linux Tracing Superpowers by Eugene PirogovPivorak MeetUp
 

En vedette (20)

Trailblazer Introduction by Nick Sutterer
Trailblazer Introduction by Nick SuttererTrailblazer Introduction by Nick Sutterer
Trailblazer Introduction by Nick Sutterer
 
Building Component Based Rails Applications. Part 2.
Building Component Based Rails Applications. Part 2.Building Component Based Rails Applications. Part 2.
Building Component Based Rails Applications. Part 2.
 
Functional Immutable CSS
Functional Immutable CSS Functional Immutable CSS
Functional Immutable CSS
 
The Silver Bullet Syndrome by Alexey Vasiliev
The Silver Bullet Syndrome by Alexey VasilievThe Silver Bullet Syndrome by Alexey Vasiliev
The Silver Bullet Syndrome by Alexey Vasiliev
 
Espec |> Elixir BDD
Espec |> Elixir BDDEspec |> Elixir BDD
Espec |> Elixir BDD
 
Digital Nomading on Rails
Digital Nomading on RailsDigital Nomading on Rails
Digital Nomading on Rails
 
"5 skills to master" by Alexander Skakunov
"5 skills to master" by Alexander Skakunov"5 skills to master" by Alexander Skakunov
"5 skills to master" by Alexander Skakunov
 
Building component based rails applications. part 1.
Building component based rails applications. part 1.Building component based rails applications. part 1.
Building component based rails applications. part 1.
 
Права інтелектуальної власності в IT сфері.
Права інтелектуальної власності  в IT сфері.Права інтелектуальної власності  в IT сфері.
Права інтелектуальної власності в IT сфері.
 
Pivorak Clojure by Dmytro Bignyak
Pivorak Clojure by Dmytro BignyakPivorak Clojure by Dmytro Bignyak
Pivorak Clojure by Dmytro Bignyak
 
Andriy Vandakurov about "Frontend. Global domination"
Andriy Vandakurov about  "Frontend. Global domination" Andriy Vandakurov about  "Frontend. Global domination"
Andriy Vandakurov about "Frontend. Global domination"
 
“Object Oriented Ruby” by Michał Papis.
“Object Oriented Ruby” by Michał Papis.“Object Oriented Ruby” by Michał Papis.
“Object Oriented Ruby” by Michał Papis.
 
"Meet rom_rb & dry_rb" by Piotr Solnica
"Meet rom_rb & dry_rb" by Piotr Solnica"Meet rom_rb & dry_rb" by Piotr Solnica
"Meet rom_rb & dry_rb" by Piotr Solnica
 
Pivorak How to write better sentences in English
Pivorak How to write better sentences in EnglishPivorak How to write better sentences in English
Pivorak How to write better sentences in English
 
Elastic pivorak
Elastic pivorakElastic pivorak
Elastic pivorak
 
HTML Canvas tips & tricks - Lightning Talk by Roman Rodych
 HTML Canvas tips & tricks - Lightning Talk by Roman Rodych HTML Canvas tips & tricks - Lightning Talk by Roman Rodych
HTML Canvas tips & tricks - Lightning Talk by Roman Rodych
 
Broker: adventure through architecture pattern
Broker: adventure through architecture patternBroker: adventure through architecture pattern
Broker: adventure through architecture pattern
 
Ramda lets write declarative js
Ramda   lets write declarative jsRamda   lets write declarative js
Ramda lets write declarative js
 
Flowex - Railway Flow-Based Programming with Elixir GenStage.
Flowex - Railway Flow-Based Programming with Elixir GenStage.Flowex - Railway Flow-Based Programming with Elixir GenStage.
Flowex - Railway Flow-Based Programming with Elixir GenStage.
 
Linux Tracing Superpowers by Eugene Pirogov
Linux Tracing Superpowers by Eugene PirogovLinux Tracing Superpowers by Eugene Pirogov
Linux Tracing Superpowers by Eugene Pirogov
 

Plus de Pivorak MeetUp

Lisp(Lots of Irritating Superfluous Parentheses)
Lisp(Lots of Irritating Superfluous Parentheses)Lisp(Lots of Irritating Superfluous Parentheses)
Lisp(Lots of Irritating Superfluous Parentheses)Pivorak MeetUp
 
Some strange stories about mocks.
Some strange stories about mocks.Some strange stories about mocks.
Some strange stories about mocks.Pivorak MeetUp
 
Business-friendly library for inter-service communication
Business-friendly library for inter-service communicationBusiness-friendly library for inter-service communication
Business-friendly library for inter-service communicationPivorak MeetUp
 
How i was a team leader once
How i was a team leader onceHow i was a team leader once
How i was a team leader oncePivorak MeetUp
 
Rails MVC by Sergiy Koshovyi
Rails MVC by Sergiy KoshovyiRails MVC by Sergiy Koshovyi
Rails MVC by Sergiy KoshovyiPivorak MeetUp
 
Introduction to Rails by Evgeniy Hinyuk
Introduction to Rails by Evgeniy HinyukIntroduction to Rails by Evgeniy Hinyuk
Introduction to Rails by Evgeniy HinyukPivorak MeetUp
 
Ruby OOP (in Ukrainian)
Ruby OOP (in Ukrainian)Ruby OOP (in Ukrainian)
Ruby OOP (in Ukrainian)Pivorak MeetUp
 
Ruby Summer Course by #pivorak & OnApp - OOP Basics in Ruby
Ruby Summer Course by #pivorak & OnApp - OOP Basics in RubyRuby Summer Course by #pivorak & OnApp - OOP Basics in Ruby
Ruby Summer Course by #pivorak & OnApp - OOP Basics in RubyPivorak MeetUp
 
The Saga Pattern: 2 years later by Robert Pankowecki
The Saga Pattern: 2 years later by Robert PankoweckiThe Saga Pattern: 2 years later by Robert Pankowecki
The Saga Pattern: 2 years later by Robert PankoweckiPivorak MeetUp
 
Data and Bounded Contexts by Volodymyr Byno
Data and Bounded Contexts by Volodymyr BynoData and Bounded Contexts by Volodymyr Byno
Data and Bounded Contexts by Volodymyr BynoPivorak MeetUp
 
Successful Remote Development by Alex Rozumii
Successful Remote Development by Alex RozumiiSuccessful Remote Development by Alex Rozumii
Successful Remote Development by Alex RozumiiPivorak MeetUp
 
Origins of Elixir programming language
Origins of Elixir programming languageOrigins of Elixir programming language
Origins of Elixir programming languagePivorak MeetUp
 
Multi language FBP with Flowex by Anton Mishchuk
Multi language FBP with Flowex by Anton Mishchuk Multi language FBP with Flowex by Anton Mishchuk
Multi language FBP with Flowex by Anton Mishchuk Pivorak MeetUp
 
CryptoParty: Introduction by Olexii Markovets
CryptoParty: Introduction by Olexii MarkovetsCryptoParty: Introduction by Olexii Markovets
CryptoParty: Introduction by Olexii MarkovetsPivorak MeetUp
 
How to make first million by 30 (or not, but tryin') - by Marek Piasecki
How to make first million by 30 (or not, but tryin') - by Marek PiaseckiHow to make first million by 30 (or not, but tryin') - by Marek Piasecki
How to make first million by 30 (or not, but tryin') - by Marek PiaseckiPivorak MeetUp
 
GIS on Rails by Oleksandr Kychun
GIS on Rails by Oleksandr Kychun GIS on Rails by Oleksandr Kychun
GIS on Rails by Oleksandr Kychun Pivorak MeetUp
 
Unikernels - Keep It Simple to the Bare Metal
Unikernels - Keep It Simple to the Bare MetalUnikernels - Keep It Simple to the Bare Metal
Unikernels - Keep It Simple to the Bare MetalPivorak MeetUp
 

Plus de Pivorak MeetUp (18)

Lisp(Lots of Irritating Superfluous Parentheses)
Lisp(Lots of Irritating Superfluous Parentheses)Lisp(Lots of Irritating Superfluous Parentheses)
Lisp(Lots of Irritating Superfluous Parentheses)
 
Some strange stories about mocks.
Some strange stories about mocks.Some strange stories about mocks.
Some strange stories about mocks.
 
Business-friendly library for inter-service communication
Business-friendly library for inter-service communicationBusiness-friendly library for inter-service communication
Business-friendly library for inter-service communication
 
How i was a team leader once
How i was a team leader onceHow i was a team leader once
How i was a team leader once
 
Rails MVC by Sergiy Koshovyi
Rails MVC by Sergiy KoshovyiRails MVC by Sergiy Koshovyi
Rails MVC by Sergiy Koshovyi
 
Introduction to Rails by Evgeniy Hinyuk
Introduction to Rails by Evgeniy HinyukIntroduction to Rails by Evgeniy Hinyuk
Introduction to Rails by Evgeniy Hinyuk
 
Ruby OOP (in Ukrainian)
Ruby OOP (in Ukrainian)Ruby OOP (in Ukrainian)
Ruby OOP (in Ukrainian)
 
Testing in Ruby
Testing in RubyTesting in Ruby
Testing in Ruby
 
Ruby Summer Course by #pivorak & OnApp - OOP Basics in Ruby
Ruby Summer Course by #pivorak & OnApp - OOP Basics in RubyRuby Summer Course by #pivorak & OnApp - OOP Basics in Ruby
Ruby Summer Course by #pivorak & OnApp - OOP Basics in Ruby
 
The Saga Pattern: 2 years later by Robert Pankowecki
The Saga Pattern: 2 years later by Robert PankoweckiThe Saga Pattern: 2 years later by Robert Pankowecki
The Saga Pattern: 2 years later by Robert Pankowecki
 
Data and Bounded Contexts by Volodymyr Byno
Data and Bounded Contexts by Volodymyr BynoData and Bounded Contexts by Volodymyr Byno
Data and Bounded Contexts by Volodymyr Byno
 
Successful Remote Development by Alex Rozumii
Successful Remote Development by Alex RozumiiSuccessful Remote Development by Alex Rozumii
Successful Remote Development by Alex Rozumii
 
Origins of Elixir programming language
Origins of Elixir programming languageOrigins of Elixir programming language
Origins of Elixir programming language
 
Multi language FBP with Flowex by Anton Mishchuk
Multi language FBP with Flowex by Anton Mishchuk Multi language FBP with Flowex by Anton Mishchuk
Multi language FBP with Flowex by Anton Mishchuk
 
CryptoParty: Introduction by Olexii Markovets
CryptoParty: Introduction by Olexii MarkovetsCryptoParty: Introduction by Olexii Markovets
CryptoParty: Introduction by Olexii Markovets
 
How to make first million by 30 (or not, but tryin') - by Marek Piasecki
How to make first million by 30 (or not, but tryin') - by Marek PiaseckiHow to make first million by 30 (or not, but tryin') - by Marek Piasecki
How to make first million by 30 (or not, but tryin') - by Marek Piasecki
 
GIS on Rails by Oleksandr Kychun
GIS on Rails by Oleksandr Kychun GIS on Rails by Oleksandr Kychun
GIS on Rails by Oleksandr Kychun
 
Unikernels - Keep It Simple to the Bare Metal
Unikernels - Keep It Simple to the Bare MetalUnikernels - Keep It Simple to the Bare Metal
Unikernels - Keep It Simple to the Bare Metal
 

GIS on Rails