openstreetmap and geospatial ruby tim waters sheffield ruby user group july 2015
TRANSCRIPT
- 1. OpenStreetMap (+ other Geo/Ruby things) Sheffield Ruby User Group July 2015 Tim Waters [email protected] @tim_waters
- 2. Live OSM http://live.openstreetmap.fr/ https://osmlab.github.io/show-me-the-way/
- 3. What is OpenStreetMap? A web project to create a free and open map of the entire world
- 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. Open Data
- 6. http://www.ted.com/talks/view/lang/en//id/788
- 7. Haiti http://vimeo.com/9182869 ito_haiti_berners_lee.mp4
- 8. Dude, we just use Google.
- 9. The reasons not to... Terms of Use Copyright Derived Works No Data OSM better in many areas
- 10. Dude, you can't trust it
- 11. Wikipedia Fix the data Objectiveness Quality Control
- 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. How do people map?
- 14. YOU CAN GET THE DATA
- 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. Overpass API
- 17. TagInfo http://taginfo.openstreetmap.org/
- 18. Slide taginfo for a tag
- 19. Literally More data than appears
- 20. More data than appears
- 21. Literally more data than appears Cartography
- 22. Stamen - Watercolor http://maps.stamen.com/watercolor/#15/53.80 25/-1.5469
- 23. Stamen Toner
- 24. Literally more data than appears Custom Maps
- 25. OpenStreetMap Schema Folksonomy: collaboratively created created system of tagging things. (The community creates the OpenStreetMap tagging scheming over time)
- 26. Nodes, Ways and Areas
- 27. OSM Stack Website API Editor Map Rendering Exports
- 28. OSM Website Ruby on Rails Github openstreetmap/openstreetmap-website All volunteers
- 29. Suitable tasks Changeset reverter, history diffs History bounding box improvements Groups of users Area type
- 30. Rosemary Ruby library 4 OSM https://github.com/sozialhelden/rosemary require 'rosemary' api = Rosemary::Api.new node = api.find_way(174111099) #"pub", "building"=>"yes", "food"=>"yes", "name"=>"The Red Deer", "real_ale"=>"yes"}>
- 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. OSM Stack OpenHistoricalMap OpenGeoFiction
- 33. OpenHistoricalMap
- 34. Saeby Denmark 18C
- 35. Saeby Denmark Now
- 36. OpenGeoFiction
- 37. Other ruby geo (GIS) Geos Gdal Rgeo Mapnik
- 38. GEOS defbuffer(feature,radius,min_radius=0.0) wkb_writer=Geos::WkbWriter.new wkb_reader=Geos::WkbReader.new geom=wkb_reader.read_hexfeature.geometry buffer_geom=geom.buffer(radius) ifmin_radius!=0.0 hole_geom=geom.buffer(min_radius) buffer_geom=buffer_geom.difference(hole_geom) end feature.geometry=wkb_writer.write_hexbuffer_geom feature end https://github.com/dark-panda/ffi-geos Apt-Get install libgeos-ruby
- 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. 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. PostGIS / postgres https://github.com/rgeo/activerecord-postgis-adapter create_table:my_spatial_tabledo|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. PostGIS / postgres record=MySpatialTable.find(1) p=record.lonlat#ReturnsanRGeo::Feature::Point putsp.x#displaysthexcoordinate putsp.geometry_type.type_name#displays"Point"
- 43. PostGIS / postgres bbox_polygon=Polygon.from_coordinates([bbox_coords], 4326).as_ewkt Model.where(ST_Within(bbox_geom, ST_GeomFromText('#{bbox_polygon}'))")
- 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. map=Mapnik::Map.newdo|m| m.background=Mapnik::Color.new('#777')#Agreybackground #UsetheGooglemercatorprojection m.srs=Mapnik::Tile::DEFAULT_OUTPUT_PROJECTION #Addalayertothemap m.layer'countries'do|l| l.styledo|s| #Addaruletothestyle(thisoneisadefaultrule) s.ruledo|default| default.fill=Mapnik::Color.new('#880000') end end l.srs="+proj=latlong+datum=WGS84"#setthesrsofthelayer 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. Thanks! @tim_waters Leeds Ruby Thing last Thursday every month