26. GEOS
# new point
p4 = @reader.read(‘POINT(2.5, 3.5)’)
# create a buffer on p4
buffer = p4.buffer(2)
# now test against the buffer
buffer.contains?(p1) # false
buffer.contains?(p2) # true
buffer.touches?(p3.buffer(1)) # true
p2
p4
p1 p3
buffer
27. GEORUBY
http://rubyforge.org/projects/georuby/
A Library for working with geometric data types in Ruby
follows the OGC’s Simple Features Spec
Think: Point, Lines, and Polygons
Also data formatters / parsers
(KML to Well Known Text)
28. SPATIAL ADAPTER
https://github.com/fragility/spatial_adapterxt
Adapter for ActiveRecord
Handles spatial datatypes coming from:
PostGreSQL (via PostGIS)
&
MySQL (via its spatial ext.)
29. RGEO
http://virtuoso.rubyforge.org/rgeo/
Geospatial datatypes in Ruby
Standard Spatial analysis operations:
(buffers, intersections, distances, etc)
Data format conversions
Flexible - gem and active-record adapter
30. RUBY GEOCODER
http://www.rubygeocoder.com/
Full featured geocoder for Ruby
Gem and Rails Plugin
Converts addresses and IPs in lat/lon coordinates
configurable to work with any service
Also checkout geokit: http://geokit.rubyforge.org/
31. RUBY GEOCODER
http://www.rubygeocoder.com/
require ‘geocoder’
# look up coordinates of some location
Geocoder.coordinates("25 Main St, Cooperstown, NY")
=> [42.700149, -74.922767]
# distance between Eiffel Tower and Empire State Building
Geocoder::Calculations.distance_between([47.858205,2.294359],
[40.748433,-73.985655])
=> 3619.77359999382
# find the geographic coordinates for an IP address
Geocoder.coordinates("71.166.236.36")
=> [38.6485, -77.3108]
32. DATABASES
PostgreSQL / Postgis
MySQL
MongoDB
Couch...DB....base (via GeoCouch)
39. TWEETSTREAM
https://github.com/intridea/tweetstream
Simple wrapper to the Twitter Streaming API
Can search via tags or locations (via bboxes)
Good way to generate geospatial data/content
40. TWEETSTREAM
require 'rubygems'
require 'tweetstream'
# Use 'track' to track a list of single-word keywords
TweetStream::Client.new('username','password').track('term1',
'term2') do |status|
puts "#{status.text}"
end
# track tweets within a bbox
TweetStream::Client.new('username','password').locations(‘-122.75,
36.8,-121.75,37.8’) do |status|
puts "#{status.text}"
end
41. INSTAGRAM
https://github.com/Instagram/instagram-ruby-gem
Wrapper to the Instragram’s photo sharing API
Allows for spatial searching via lat/lon
very similar to the Flick’r API
43. INSTAGRAM
require "instagram"
# All methods require authentication
Instagram.configure do |config|
config.client_id = YOUR_CLIENT_KEY
config.access_token = YOUR_ACCESS_TOKEN
end
# Get a list of media at a given location
puts Instagram.location_recent_media(514276)
# Get a list of media close to a given latitude and longitude
puts Instagram.media_search("37.7808851,-122.3948632")
44. YELP!
http://github.com/shaper/yelp
Location based lookup for business reviews
Highly local listing accessed in variety of geospatial ways
another way to create some geospatial data/content
49. SIMPLEGEO
https://github.com/simplegeo/simplegeo-ruby
API for adding geospatial capabilities to apps
Access POIs, Locational Context, and personal data
Emphasis on speed, simplicity, and flexibility
50. SIMPLEGEO
Context API
# grab the context of a lat/lon
SimpleGeo::Client.get_context(37.772445,-122.405913)
# context
SimpleGeo::Client.get_context_by_address("41 Decatur St, San
Francisco, CA 94103")
SimpleGeo::Client.get_context_ip("184.84.228.110")
52. FUSION TABLES
https://github.com/tokumine/fusion_tables
Direct access to Google’s Fusion Tables API
Full SQL interface or OO query interface
Easy integration to other Google services
(maps, earth, viz.)
Easy storage/retrieve of geospatial data
53. FUSION TABLES
require 'fusion_tables'
# Connect to service
@ft = GData::Client::FusionTables.new
@ft.clientlogin(username, password)
# 1. SQL interface
@ft.execute "SHOW TABLES"
@ft.execute "INSERT INTO #{my_table_id} (name, geo) VALUES
('tokyo', '35.6894 139.6917');"
@ft.execute "SELECT count() FROM #{my_table_id};"
54. GEOCOMMONS
http://geocommons.com
Open Data Storage, Analysis, and Visualization
Strong emphasis on usability
Build complex geospatial workflows
Share data visualizations on the web
56. GEOCOMMONS GEM
API
GeoCommons
Mgmt Analysis
Visualization
geoiq-
ruby
57. GEOCOMMONS GEM
finding data...
# create a client
@geoiq = Geoiq.client("http://geocommons.com", "user", "password")
# search for tags
@geoiq.search("tag:economics")
# Search for data in a location
@geoiq.search("points",{:bbox => ‘-87.2,33.4,-75.9,38.4', :limit=>
10})
58. GEOCOMMONS GEM
getting data...
# get dataset and features
dataset = geoiq.dataset.find(1348)
features = dataset.features
# get features with a custom filter
filtered_features = @dataset.features({"filter[PERIMETER][][max]"
=> 0.3})
bbox_filtered_features = @dataset.features({:bbox =>
'-87.2,33.4,-75.9,38.4'})
60. GEOCOMMONS
create new datasets...
# Create a new overlay
data = {‘title’ => ‘My Overlay’, ‘attributes’ => {‘attr1’ => ...}}
overlay = @geoiq.dataset.create(data)
# add features to the overlay
features = {features => [{‘type’ => ‘Point’, ‘coordinates’ =>
[0,0]},{...}]}
@geoiq.dataset.update(id, features)
61. GEOCOMMONS
create new visualizations...
# Create a new map
map = @geoiq.map(:title => "my empty map")
@geoiq_map = map.create
# get a map and it's layers
@map = @geoiq.map.find(239)
layer_titles = @map.layers.map{ |l| l['title']}
# add a dataset to a map as a new layer
@map.add_layer(1466)
#deleting map or dataset
@map.delete
@dataset.delete