If you can't read please download the document
Upload
chippy
View
190
Download
1
Embed Size (px)
Citation preview
Some Ruby Geospatial Libraries
Rosemary
require 'rosemary'client = Rosemary::BasicAuthClient.new ('osm_user_name', 'password')api = Rosemary::Api.new(client)
changeset = api.create_changeset("Add postbox")node = Rosemary::Node.new(lat, lon)node.add_tags({"amenity"=>"postbox"})api.save(node, changeset)api.close_changeset(changeset)
Overpass API
require 'overpass_api_ruby'pub_query = ""
Options ={:bbox => {:s =>-34.7,:n => -34.2,:w => -58.53, :e => -58.33}, :timeout => 900, :element_limit => 1073741824, :json => true}
overpass = OverpassAPI.new(options)result_hash = overpass.query(pub_query)
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 featureend
GDAL / OGR
https://github.com/zhm/gdal-ruby
Gdal::Ogr.create_geometry_from_wkt('POINT (30 10)')
raster = Gdal::Gdal.open(filename)dx = raster.RasterXSizedy = raster.RasterYSizex0, x_res, x_skew, y0, y_skew, y_res = raster.get_geo_transform
RGeo
https://github.com/rgeo/rgeo
factory = Rgeo::Cartesian.factorypoint1 = factory.point(1, 0)point2 = factory.point(1, 4)point3 = factory.point(-2, 0)point2.distance(point3) # => 5.0line_string1 = factory.line_string([point1, point2, point3])line_string1.num_points # => 3line_string1.point_n(0) == point1 # => trueline_string1.end_point == point3 # => true
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: trueend
PostGIS / postgres
bbox_polygon = Polygon.from_coordinates([bbox_coords], 4326).as_ewkt
Model.where(ST_Within(bbox_geom, ST_GeomFromText('#{bbox_polygon}'))")
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')
Ruby Mapnik