Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
OpenStreetMap
(+ other Geo/Ruby things)
Sheffield Ruby User Group
July 2015
Tim Waters
tim@geothings.net
@tim_waters
Live OSM
http://live.openstreetmap.fr/ https://osmlab.github.io/show-me-the-way/
What is OpenStreetMap?
A web project to create a free and open
map of the entire world
History
* Founded in the United Kingdom in 2004 by
Steve Coast
* Ordnance Survey Data was Expensive to
Use
* July 2005 the...
Open Data
http://www.ted.com/talks/view/lang/en//id/788
Haiti
http://vimeo.com/9182869
ito_haiti_berners_lee.mp4
Dude, we just use
Google.
The reasons not to...
Terms of Use
Copyright
Derived Works
No Data
OSM better in many areas
Dude, you can't trust it
“Wikipedia”
Fix the data
Objectiveness
Quality Control
Statistics
Number of users 1,045,770
Number of GPS points 3,295,708,898
Number of nodes 1,788,120,111
Number of ways 171,1...
How do people map?
YOU CAN GET THE DATA
YOU CAN GET THE DATA
1) direct dump – planet (26G Compressed)
whole, day, hour, minute
2) API
i.e. OverPass
3) Extracts
Sh...
Overpass API
TagInfo
● http://taginfo.openstreetmap.org/
Slide taginfo for a tag
Literally
More data than appears
More data than appears
Literally more data than appears
Cartography
Stamen - Watercolor
● http://maps.stamen.com/watercolor/#15/53.80
25/-1.5469
Stamen – Toner
Literally more data than appears
Custom Maps
OpenStreetMap Schema
Folksonomy: collaboratively created
created system of tagging things.
(The community creates the
Open...
Nodes, Ways and Areas
OSM Stack
● Website
● API
● Editor
● Map Rendering
● Exports
OSM Website
Ruby on Rails
Github
openstreetmap/openstreetmap-website
All volunteers
Suitable tasks
● Changeset reverter, history diffs
● History bounding box improvements
● Groups of users
● Area type
Rosemary
● Ruby library 4 OSM
● https://github.com/sozialhelden/rosemary
require 'rosemary'
api = Rosemary::Api.new
node =...
Rosemary
client = Rosemary::BasicAuthClient.new
('osm_user_name', 'password')
api = Rosemary::Api.new(client)
changeset = ...
OSM Stack
● OpenHistoricalMap
● OpenGeoFiction
OpenHistoricalMap
Saeby – Denmark 18C
Saeby – Denmark Now
OpenGeoFiction
Other ruby geo
(GIS)
● Geos
● Gdal
● Rgeo
● Mapnik
GEOS
def buffer(feature, radius, min_radius=0.0)
   wkb_writer = Geos::WkbWriter.new
   wkb_reader = Geos::WkbReader.new
 ...
GDAL / OGR
● https://github.com/zhm/gdal-ruby
Gdal::Ogr.create_geometry_from_wkt('POINT (30 10)')
raster = Gdal::Gdal.open...
RGeo
https://github.com/rgeo/rgeo
factory = Rgeo::Cartesian.factory
point1 = factory.point(1, 0)
point2 = factory.point(1,...
PostGIS / postgres
https://github.com/rgeo/activerecord-postgis-adapter
create_table :my_spatial_table do |t|
  t.column :...
PostGIS / postgres
record = MySpatialTable.find(1)
p = record.lonlat                  # Returns an RGeo::Feature::Point
pu...
PostGIS / postgres
 bbox_polygon = Polygon.from_coordinates([bbox_coords], 
4326).as_ewkt
Model.where(ST_Within(bbox_geom,...
Ruby Mapnik :-(
https://github.com/mapnik/Ruby-Mapnik
Gem maintainer gone?
Code = old & broken
But
Mapnik = how maps are r...
map = Mapnik::Map.new do |m|
  m.background = Mapnik::Color.new('#777')  # A grey background
  # Use the Google mercator p...
Thanks!
@tim_waters
Leeds Ruby Thing
– last Thursday every month
OpenStreetMap and Geospatial Ruby Tim Waters sheffield ruby user group july 2015
OpenStreetMap and Geospatial Ruby Tim Waters sheffield ruby user group july 2015
OpenStreetMap and Geospatial Ruby Tim Waters sheffield ruby user group july 2015
OpenStreetMap and Geospatial Ruby Tim Waters sheffield ruby user group july 2015
OpenStreetMap and Geospatial Ruby Tim Waters sheffield ruby user group july 2015
OpenStreetMap and Geospatial Ruby Tim Waters sheffield ruby user group july 2015
OpenStreetMap and Geospatial Ruby Tim Waters sheffield ruby user group july 2015
OpenStreetMap and Geospatial Ruby Tim Waters sheffield ruby user group july 2015
OpenStreetMap and Geospatial Ruby Tim Waters sheffield ruby user group july 2015
Upcoming SlideShare
Loading in …5
×

OpenStreetMap and Geospatial Ruby Tim Waters sheffield ruby user group july 2015

1,086 views

Published on

OpenStreetMap and Geospatial Ruby Tim Waters sheffield ruby user group july 2015

Published in: Internet
  • Be the first to comment

OpenStreetMap and Geospatial Ruby Tim Waters sheffield ruby user group july 2015

  1. 1. OpenStreetMap (+ other Geo/Ruby things) Sheffield Ruby User Group July 2015 Tim Waters tim@geothings.net @tim_waters
  2. 2. Live OSM http://live.openstreetmap.fr/ https://osmlab.github.io/show-me-the-way/
  3. 3. What is OpenStreetMap? A web project to create a free and open map of the entire world
  4. 4. History * Founded in the United Kingdom in 2004 by Steve Coast * Ordnance Survey Data was Expensive to Use * July 2005 the First Mapping Party Takes Place
  5. 5. Open Data
  6. 6. http://www.ted.com/talks/view/lang/en//id/788
  7. 7. Haiti http://vimeo.com/9182869 ito_haiti_berners_lee.mp4
  8. 8. Dude, we just use Google.
  9. 9. The reasons not to... Terms of Use Copyright Derived Works No Data OSM better in many areas
  10. 10. Dude, you can't trust it
  11. 11. “Wikipedia” Fix the data Objectiveness Quality Control
  12. 12. Statistics Number of users 1,045,770 Number of GPS points 3,295,708,898 Number of nodes 1,788,120,111 Number of ways 171,187,609 Active users / month 17,478 Wikipedia: Number of pages: 29,551,074 Number of articles: 4,173,959 Active users / month 135,706
  13. 13. How do people map?
  14. 14. YOU CAN GET THE DATA
  15. 15. YOU CAN GET THE DATA 1) direct dump – planet (26G Compressed) whole, day, hour, minute 2) API i.e. OverPass 3) Extracts Shapefile format (buildings, natural, place, rail, roads, water, points, landuse)
  16. 16. Overpass API
  17. 17. TagInfo ● http://taginfo.openstreetmap.org/
  18. 18. Slide taginfo for a tag
  19. 19. Literally More data than appears
  20. 20. More data than appears
  21. 21. Literally more data than appears Cartography
  22. 22. Stamen - Watercolor ● http://maps.stamen.com/watercolor/#15/53.80 25/-1.5469
  23. 23. Stamen – Toner
  24. 24. Literally more data than appears Custom Maps
  25. 25. OpenStreetMap Schema Folksonomy: collaboratively created created system of tagging things. (The community creates the OpenStreetMap tagging scheming over time)
  26. 26. Nodes, Ways and Areas
  27. 27. OSM Stack ● Website ● API ● Editor ● Map Rendering ● Exports
  28. 28. OSM Website Ruby on Rails Github openstreetmap/openstreetmap-website All volunteers
  29. 29. Suitable tasks ● Changeset reverter, history diffs ● History bounding box improvements ● Groups of users ● Area type
  30. 30. Rosemary ● Ruby library 4 OSM ● https://github.com/sozialhelden/rosemary require 'rosemary' api = Rosemary::Api.new node = api.find_way(174111099) #<Rosemary::Way:0x000000032bab08 @nodes=[1848409287, 1848409219.... 1848409287], @id=174111099, @version=3, @user="Paul Berry", @timestamp=2014-03-14 14:53:49 UTC, @changeset=21100786, @tags= {"amenity"=>"pub", "building"=>"yes", "food"=>"yes", "name"=>"The Red Deer", "real_ale"=>"yes"}>
  31. 31. Rosemary client = Rosemary::BasicAuthClient.new ('osm_user_name', 'password') api = Rosemary::Api.new(client) changeset = api.create_changeset("Postbox on Timothy Leary Street") node = Rosemary::Node.new(:lat => 52.0, :lon => 13.4) node.add_tags({"amenity"=>"postbox"}) api.save(node, changeset) api.close_changeset(changeset)
  32. 32. OSM Stack ● OpenHistoricalMap ● OpenGeoFiction
  33. 33. OpenHistoricalMap
  34. 34. Saeby – Denmark 18C
  35. 35. Saeby – Denmark Now
  36. 36. OpenGeoFiction
  37. 37. Other ruby geo (GIS) ● Geos ● Gdal ● Rgeo ● Mapnik
  38. 38. GEOS def buffer(feature, radius, min_radius=0.0)    wkb_writer = Geos::WkbWriter.new    wkb_reader = Geos::WkbReader.new    geom =  wkb_reader.read_hex feature.geometry    buffer_geom = geom.buffer(radius)    if min_radius != 0.0       hole_geom = geom.buffer(min_radius)       buffer_geom = buffer_geom.difference(hole_geom)    end    feature.geometry = wkb_writer.write_hex buffer_geom    feature end https://github.com/dark-panda/ffi-geos Apt-Get install libgeos-ruby
  39. 39. GDAL / OGR ● https://github.com/zhm/gdal-ruby Gdal::Ogr.create_geometry_from_wkt('POINT (30 10)') raster = Gdal::Gdal.open(filename) dx = raster.RasterXSize dy = raster.RasterYSize x0, x_res, x_skew, y0, y_skew, y_res = raster.get_geo_transform
  40. 40. RGeo https://github.com/rgeo/rgeo factory = Rgeo::Cartesian.factory point1 = factory.point(1, 0) point2 = factory.point(1, 4) point3 = factory.point(­2, 0) point4 = factory.point(­2, 4) point2.distance(point3) # => 5.0 line_string1 = factory.line_string([point1, point2, point3]) line_string1.num_points # => 3 line_string1.point_n(0) == point1 # => true line_string1.end_point == point3 # => true
  41. 41. PostGIS / postgres https://github.com/rgeo/activerecord-postgis-adapter create_table :my_spatial_table do |t|   t.column :shape1, :geometry   t.geometry :shape2   t.line_string :path, srid: 3785   t.st_point :lonlat, geographic: true   t.st_point :lonlatheight, geographic: true, has_z: true end
  42. 42. PostGIS / postgres record = MySpatialTable.find(1) p = record.lonlat                  # Returns an RGeo::Feature::Point puts p.x                               # displays the x coordinate puts p.geometry_type.type_name     # displays "Point"
  43. 43. PostGIS / postgres  bbox_polygon = Polygon.from_coordinates([bbox_coords],  4326).as_ewkt Model.where(ST_Within(bbox_geom,                       ST_GeomFromText('#{bbox_polygon}'))")
  44. 44. Ruby Mapnik :-( https://github.com/mapnik/Ruby-Mapnik Gem maintainer gone? Code = old & broken But Mapnik = how maps are rendered from postgis from OSM Everyone uses it C++ (rice)
  45. 45. map = Mapnik::Map.new do |m|   m.background = Mapnik::Color.new('#777')  # A grey background   # Use the Google mercator projection   m.srs =  Mapnik::Tile::DEFAULT_OUTPUT_PROJECTION   # Add a layer to the map   m.layer 'countries' do |l|     l.style do |s|       # Add a rule to the style (this one is a default rule)       s.rule do |default|         default.fill = Mapnik::Color.new('#880000')       end     end     l.srs = "+proj=latlong +datum=WGS84" # set the srs of the layer     l.datasource = Mapnik::Datasource.create :type => 'shape',   :file => "myshapefile.shp"   end end map.zoom_to_box(map.layers.first.envelope)  map.render_to_file('my_map.png')
  46. 46. Thanks! @tim_waters Leeds Ruby Thing – last Thursday every month

×