Adding where to your ruby apps lt - (q con)

20
ADDING WHERE” TO YOUR RUBY APPS Roberto Pepato Robson Júnior

description

Lightning Tallk about how to integrate GIS functionalities into Ruby code. Presented at São Paulo QCon 2011.

Transcript of Adding where to your ruby apps lt - (q con)

Page 1: Adding where to your ruby apps   lt -  (q con)

ADDING “WHERE” TO YOUR RUBY APPS

Roberto Pepato

Robson Júnior

Page 2: Adding where to your ruby apps   lt -  (q con)

EM POUCOS SLIDES ...

Entender o que é de fato GIS;

Ir além do entendimento de um simples

geocode e roteirização;

Gems para adicionar “where” na sua

aplicação;

Apresentar um caso de uso de aplicação

massiva de GIS;

Page 3: Adding where to your ruby apps   lt -  (q con)

PRIMEIRO DE TUDO ...

GIS (Geographic Information System) são

sistemas de informação que permitem e

facilitam a análise, gestão ou representação

do espaço e dos fenômenos que nele

ocorrem.

Não existem limites para sua utilização.

O que limita é sua imaginação.

Page 4: Adding where to your ruby apps   lt -  (q con)

POR QUE GIS?

Localização;

Condição;

Tendência;

Rotas;

Modelos.

Page 5: Adding where to your ruby apps   lt -  (q con)

GIS NO SEU DIA A DIA

Geocodificação ( Google Maps );

Geocodificação Reversa ( FourSquare );

Roteirização ( Google Maps );

Mapas temáticos;

E muitas outras aplicações .

Page 6: Adding where to your ruby apps   lt -  (q con)

UM PEQUENO EXEMPLO

Page 7: Adding where to your ruby apps   lt -  (q con)

POR QUE EM RUBY ?

Linguagem dinâmica, clara e concisa;

Fácil implementação de dsl‟s;

Comunidade ativa;

Várias implementações base: geokit-gem; geocoder; geokit-rails; graticule; act_as_geocodable; ym4r-gm; postgis_adapter; google_static_maps_helper; etc;

Um longo caminho a ser explorado: análise espacial, operações topológicas, análise de redes, etc.

Page 8: Adding where to your ruby apps   lt -  (q con)

POR QUE MONGODB ?

Código aberto;

Armazenamento de informações

desestruturadas;

Comunidade ativa;

Capacidade de armazenamento de dados

geográficos (geometrias);

Performance em consultas espaciais.

Page 9: Adding where to your ruby apps   lt -  (q con)

CONFIGURANDO MONGOID

No Gemfile

Gem „mongoid‟, „~> 2.2‟

Gem „bson_ext‟, „~> 1.3‟

bundle install

rails g mongoid:config

No Model

include Mongoid::Document

field :name, :type => String

field :address, :type => String

field :coordinates, :type => Array

Page 10: Adding where to your ruby apps   lt -  (q con)

CONFIGURANDO GEOCODER

gem “geocoder”

bundle install

No ModelInclude Geocoder::Model::Mongoid

geocoded_by :address (address or IP)

after_validation :geocode # get the coordinates

Or Reverse Geocoding

include Geocoder::Model::Mongoid

reverse_geocoded_by :coordinates

after_validation :reverse_geocode #get the addresss

rake geocode:all CLASS=YourModel # Geocodificação em Lote

Page 11: Adding where to your ruby apps   lt -  (q con)

SEU MODEL GEOLOCALIZADO

Page 12: Adding where to your ruby apps   lt -  (q con)

SEU MODEL GEOLOCALIZADO

Page 13: Adding where to your ruby apps   lt -  (q con)

VALIDAÇÃO DA GEOLOCALIZAÇÃO

Page 14: Adding where to your ruby apps   lt -  (q con)

DSL’S (EXEMPLOS GEOCODER)

# venues within 20 miles of Omaha

Venue.near('Omaha, NE, US', 20)

# venues within 20 miles of a point

Venue.near([40.71, 100.23], 20)

# venues with coordinates

Venue.geocoded

# venues without coordinates

Venue.not_geocoded

Page 15: Adding where to your ruby apps   lt -  (q con)

# other objects within 30 miles

obj.nearbys(30)

# distance from arbitrary point to object

obj.distance_from([40.714,-100.234])

# direction from object to arbitrary point

obj.bearing_to("Paris, France")

# look up coordinates of some location (like searching Google Maps)

Geocoder.coordinates("25 Main St, Cooperstown, NY") => [42.700149, -74.922767]

# distance (in miles) between Eiffel Tower and Empire State Building

Geocoder::Calculations.distance_between([47.858205,2.294359], [40.748433,-

73.985655]) => 3619.77359999382

# find the geographic center (aka center of gravity) of objects or points

Geocoder::Calculations.geographic_center([city1, city2, [40.22,-73.99], city4]) =>

[35.14968, -90.048929]

Page 16: Adding where to your ruby apps   lt -  (q con)

COMO VOCÊ SAIRIA DESSA ?

Eu preciso construir um hospital na zona sul

de SP:

Considerando que tenho de atender uma

comunidade ainda não atendida por outros

hospitais;

Considerando que as ambulâncias que se

deslocarem pela área de atendimento devem

trafegar num limite máximo de 25 minutos em

condições de trânsito normal;

Page 17: Adding where to your ruby apps   lt -  (q con)

CONTINUANDO ...

Considerando a infraestrutura viária disponível;

Considerando a infraestrutura de transporte

público disponível;

Considerando que as famílias atendidas por este

hospital devem ter renda máxima de 3 salários

mínimos;

Page 18: Adding where to your ruby apps   lt -  (q con)

DETERMINE O LOCAL ÓTIMO PARA

CONSTRUÇÃO DESSE HOSPITAL?

Page 19: Adding where to your ruby apps   lt -  (q con)

BUFFER, ROTA, GEOCODE, ANALISE ESPACIAL,

OPERAÇÃO TOPOLÓGICA, ETC...

Page 20: Adding where to your ruby apps   lt -  (q con)

@bsao - robson

@rpepato - pepato

OBRIGADO :)