sinatra_wms 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +2 -0
- data/.travis.yml +9 -0
- data/Gemfile +10 -1
- data/README.rdoc +2 -0
- data/lib/sinatra_wms/rmagick_extension.rb +5 -1
- data/lib/sinatra_wms/sinatra_extension.rb +6 -3
- data/lib/sinatra_wms/version.rb +1 -1
- data/lib/sinatra_wms.rb +1 -1
- data/sinatra_wms.gemspec +5 -1
- data/spec/rmagick_extension_spec.rb +75 -0
- data/spec/sinatra_extension_spec.rb +98 -0
- data/spec/sinatra_wms_spec.rb +5 -0
- data/spec/spec_helper.rb +22 -0
- metadata +11 -8
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/Gemfile
CHANGED
@@ -3,5 +3,14 @@ source "http://rubygems.org"
|
|
3
3
|
# Specify your gem's dependencies in sinatra_wms.gemspec
|
4
4
|
gemspec
|
5
5
|
|
6
|
-
|
6
|
+
group :development do
|
7
|
+
gem 'rdoc'
|
8
|
+
end
|
7
9
|
|
10
|
+
group :test, :development do
|
11
|
+
gem 'rake'
|
12
|
+
end
|
13
|
+
|
14
|
+
group :test do
|
15
|
+
gem 'rack-test'
|
16
|
+
end
|
data/README.rdoc
CHANGED
@@ -13,6 +13,8 @@ You could zoom in and out an such - but you'd have to care about getting your da
|
|
13
13
|
The solution for this problem: WMS (Web Map Service).
|
14
14
|
This gem helps you to provide a WMS to be used with OpenLayers. OpenLayers will display a baselayer (OpenStreetMap or Google Maps) at a configurable Opacity and add your data on top of it. Whenever you scroll or zoom around the map, OpenLayers will request images of a part of the visible screen. Your code has to generate them on-the-fly and deliver them back.
|
15
15
|
|
16
|
+
Current test status: {<img src="https://secure.travis-ci.org/fabianonline/sinatra_wms.png?branch=master" alt="Build Status" />}[http://travis-ci.org/fabianonline/sinatra_wms]
|
17
|
+
|
16
18
|
|
17
19
|
== How do I use SinatraWMS?
|
18
20
|
|
@@ -19,7 +19,7 @@ module Magick
|
|
19
19
|
|
20
20
|
|
21
21
|
## Wrapper for +circle+, but with coordinates given in WGS84.
|
22
|
-
def circle_wgs84 (x1, y1, x2, y2, *args); args.unshift(* latlon_to_pixels(x2, y2)).unshift(* latlon_to_pixels(x1, y1));
|
22
|
+
def circle_wgs84 (x1, y1, x2, y2, *args); args.unshift(* latlon_to_pixels(x2, y2)).unshift(* latlon_to_pixels(x1, y1)); circle(*args); end
|
23
23
|
## Wrapper for +line+, but with coordinates given in WGS84.
|
24
24
|
def line_wgs84 (x1, y1, x2, y2, *args); args.unshift(* latlon_to_pixels(x2, y2)).unshift(* latlon_to_pixels(x1, y1)); line(*args); end
|
25
25
|
## Wrapper for +rectangle+, but with coordinates given in WGS84.
|
@@ -38,6 +38,10 @@ module Magick
|
|
38
38
|
@wms_settings = hash
|
39
39
|
end
|
40
40
|
|
41
|
+
##
|
42
|
+
# Getter for wms_settings.
|
43
|
+
def wms_settings; @wms_settings; end
|
44
|
+
|
41
45
|
##
|
42
46
|
# The same as +point+, but draws a "big point" with 3 pixels width and height.
|
43
47
|
def bigpoint(x, y)
|
@@ -16,10 +16,10 @@ module Sinatra
|
|
16
16
|
# After the block has run, we return the image to the requestee.
|
17
17
|
def wms(url, &block)
|
18
18
|
get url do
|
19
|
-
headers "Content-Type" => "image/png"
|
20
19
|
# convert the given parameters to lowercase symbols
|
21
20
|
options = params.inject({}) {|hash, (key, value)| hash[key.to_s.downcase.to_sym] = value; hash }
|
22
|
-
|
21
|
+
error(400, "Parameter(s) missing") unless [:width, :height, :bbox, :srs].all? {|elm| options.include?(elm)}
|
22
|
+
|
23
23
|
# interpret :width and :height as integer
|
24
24
|
[:width, :height].each {|what| options[what] = options[what].to_i}
|
25
25
|
|
@@ -30,7 +30,7 @@ module Sinatra
|
|
30
30
|
options[:bbox][:google] = options[:bbox][:original]
|
31
31
|
options[:bbox][:wgs84] = [*SinatraWMS::merc_to_latlon(bbox[0], bbox[1])], [*SinatraWMS::merc_to_latlon(bbox[2], bbox[3])]
|
32
32
|
else
|
33
|
-
|
33
|
+
error(400, "Unexpected Projection (srs): #{options[:srs]}")
|
34
34
|
end
|
35
35
|
|
36
36
|
# calculate the current zoom level (between 0 and 17, with 0 being the while world)
|
@@ -47,6 +47,9 @@ module Sinatra
|
|
47
47
|
:bbox => options[:bbox][:wgs84],
|
48
48
|
:width => options[:width],
|
49
49
|
:height => options[:height]}
|
50
|
+
|
51
|
+
headers "Content-Type" => "image/png"
|
52
|
+
|
50
53
|
|
51
54
|
# Call the block
|
52
55
|
block.call(gc, options)
|
data/lib/sinatra_wms/version.rb
CHANGED
data/lib/sinatra_wms.rb
CHANGED
@@ -29,7 +29,7 @@ module SinatraWMS
|
|
29
29
|
# * +:google_terrain+
|
30
30
|
def self.get_html_for_map_at(url, options={})
|
31
31
|
options[:title] ||= "Sinatra-WMS"
|
32
|
-
options[:opacity] ||= 1
|
32
|
+
options[:opacity] ||= 1.0
|
33
33
|
options[:datasource_name] ||= "WMS-Data"
|
34
34
|
options[:baselayer] ||= :osm
|
35
35
|
|
data/sinatra_wms.gemspec
CHANGED
@@ -10,8 +10,12 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.homepage = "http://github.com/fabianonline/sinatra_wms"
|
11
11
|
s.summary = "Extends Sinatra to allow the developer to easily build a WMS server"
|
12
12
|
s.description = %q(A WMS (Web Map Service) is a great way to show lots of geolocated data on a map. Instead of generating static images (which will either be huge or don't have enough resolution), a WMS allows you to dynamically zoom in and out of your dataset.
|
13
|
+
|
13
14
|
This gem allows you to very easily represent your data via a WMS. On one hand it extends Sinatra to give it a method called "wms" to process WMS-requests; on the other hand it extends RMagick to allow the developer to use coordinates in the methods used for drawing.
|
14
|
-
|
15
|
+
|
16
|
+
Convenient methods to easily generate HTML code to show your WMS data on top of OpenStreetMaps or Google Maps are also included.
|
17
|
+
|
18
|
+
Current test status: [](http://travis-ci.org/fabianonline/sinatra_wms) )
|
15
19
|
|
16
20
|
s.rubyforge_project = "sinatra_wms"
|
17
21
|
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'RMagick extensions' do
|
4
|
+
before :each do
|
5
|
+
@canvas = Magick::Draw.new()
|
6
|
+
@canvas.wms_settings={:bbox=>[[0, 0], [1, 1]], :width=>256, :height=>256}
|
7
|
+
end
|
8
|
+
|
9
|
+
describe 'WGS84-compatible drawing methods' do
|
10
|
+
before :each do
|
11
|
+
@canvas.stub(:latlon_to_pixels).and_return([23,42])
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "Methods using single coordinates" do
|
15
|
+
before :each do
|
16
|
+
@canvas.should_receive(:latlon_to_pixels).once.with(1, 2)
|
17
|
+
end
|
18
|
+
|
19
|
+
[:point, :bigpoint].each do |what|
|
20
|
+
it "contains #{what.to_s}_wgs84" do
|
21
|
+
@canvas.should_receive(what).with(23, 42)
|
22
|
+
@canvas.send("#{what.to_s}_wgs84".to_sym, 1, 2)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'contains color_wgs84' do
|
27
|
+
@canvas.should_receive(:color).with(23, 42, 1)
|
28
|
+
@canvas.color_wgs84(1, 2, 1)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'contains matte_wgs84' do
|
32
|
+
@canvas.should_receive(:matte).with(23, 42, 1)
|
33
|
+
@canvas.matte_wgs84(1, 2, 1)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'contains text_wgs84' do
|
37
|
+
@canvas.should_receive(:text).with(23, 42, "hallo")
|
38
|
+
@canvas.text_wgs84(1, 2, "hallo")
|
39
|
+
end
|
40
|
+
|
41
|
+
it "contains ellipse_wgs84" do
|
42
|
+
@canvas.should_receive(:ellipse).with(23, 42, 100, 50, 0, 270)
|
43
|
+
@canvas.ellipse_wgs84(1, 2, 100, 50, 0, 270)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "Methods using double coordinates" do
|
48
|
+
before :each do
|
49
|
+
@canvas.should_receive(:latlon_to_pixels).once.with(1, 2).and_return([23,42])
|
50
|
+
@canvas.should_receive(:latlon_to_pixels).once.with(3, 4).and_return([88,99])
|
51
|
+
end
|
52
|
+
|
53
|
+
[:circle, :line, :rectangle, :roundrectangle].each do |what|
|
54
|
+
it "contains #{what.to_s}_wgs84" do
|
55
|
+
@canvas.should_receive(what).with(23, 42, 88, 99)
|
56
|
+
@canvas.send("#{what.to_s}_wgs84".to_sym, 1, 2, 3, 4)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should contain bigpoint" do
|
63
|
+
@canvas.should_receive(:rectangle).with(10, 21, 12, 23)
|
64
|
+
@canvas.bigpoint(11, 22)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should calculate missing values when wms_settings are given" do
|
68
|
+
@canvas = Magick::Draw.new()
|
69
|
+
@canvas.wms_settings={:bbox=>[[-10, -5], [20, 30]], :width=>256, :height=>256}
|
70
|
+
(@canvas.wms_settings[:max_sin_y]*1000000000).round.should == (2273030.92698769*1000000000).round
|
71
|
+
(@canvas.wms_settings[:min_sin_y]*1000000000).round.should == (-1118889.974857959*1000000000).round
|
72
|
+
(@canvas.wms_settings[:diff_y]*1000000000).round.should == (3391920.901845649*1000000000).round
|
73
|
+
@canvas.wms_settings[:factor_x].should == 7
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Sinatra extensions:" do
|
4
|
+
describe "The wms method" do
|
5
|
+
before(:each) do
|
6
|
+
@parameters = {"TRANSPARENT"=>"TRUE",
|
7
|
+
"SERVICE"=>"WMS",
|
8
|
+
"VERSION"=>"1.1.1",
|
9
|
+
"REQUEST"=>"GetMap",
|
10
|
+
"STYLES"=>"",
|
11
|
+
"FORMAT"=>"image/png",
|
12
|
+
"SRS"=>"EPSG:900913",
|
13
|
+
"BBOX"=>"626172.135625,6261721.35625,1252344.27125,6887893.491875",
|
14
|
+
"WIDTH"=>"256",
|
15
|
+
"HEIGHT"=>"256"}
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should be provided" do
|
19
|
+
Sinatra::Application.methods.should include( RUBY_VERSION>="1.9" ? :wms : "wms" )
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "should use the given block" do
|
23
|
+
it "and yield it" do
|
24
|
+
TestApp.should_receive(:test_method)
|
25
|
+
get '/wms', @parameters
|
26
|
+
last_response.status.should == 200
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should return an error if parameters are missing" do
|
30
|
+
get '/wms'
|
31
|
+
last_response.status.should == 400
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should return an error if an unknown SRS value is used" do
|
35
|
+
@parameters["SRS"] = "EPSG:1234567"
|
36
|
+
get '/wms', @parameters
|
37
|
+
last_response.status.should == 400
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should return data marked as image/png" do
|
41
|
+
get '/wms', @parameters
|
42
|
+
last_response.header["Content-Type"].should == "image/png"
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should return a PNG image" do
|
46
|
+
get '/wms', @parameters
|
47
|
+
last_response.body[0..7].should == "\x89PNG\x0d\x0a\x1a\x0a"
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "with options" do
|
51
|
+
before(:each) do
|
52
|
+
TestApp.should_receive(:test_method) do |*args|
|
53
|
+
args.size.should == 2
|
54
|
+
@options = args[1]
|
55
|
+
end
|
56
|
+
get '/wms', @parameters
|
57
|
+
end
|
58
|
+
|
59
|
+
it("being a Hash") { @options.should be_a Hash }
|
60
|
+
it("containing all necessary values") { @options.should include(:zoom, :width, :bbox, :height) }
|
61
|
+
it("with a correct zoom level") { @options[:zoom].should == 5 }
|
62
|
+
|
63
|
+
describe("with bounding boxes") do
|
64
|
+
it("of multiple types") { @options[:bbox].should include(:original, :google, :wgs84) }
|
65
|
+
it("with the original value") { @options[:bbox][:original].should == [[626172.135625,6261721.35625],[1252344.27125,6887893.491875]] }
|
66
|
+
it("with the original one equal to the google one") { @options[:bbox][:google].should == @options[:bbox][:original] }
|
67
|
+
it("with a correctly calculated WGS84 one") do
|
68
|
+
# Comparing floating point numbers isn't easy, so we use this workaround
|
69
|
+
a = @options[:bbox][:wgs84].flatten.collect{|elm| (elm*1000000000000).round}
|
70
|
+
b = [[48.9224992586133, 5.62499999921699], [52.4827802168329, 11.249999998434]].flatten.collect{|elm| (elm*1000000000000).round}
|
71
|
+
a.should == b
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "with a Magick::Draw object" do
|
77
|
+
before(:each) do
|
78
|
+
TestApp.should_receive(:test_method) do |*args|
|
79
|
+
args.size.should == 2
|
80
|
+
@draw = args[0]
|
81
|
+
@options = args[1]
|
82
|
+
end
|
83
|
+
get '/wms', @parameters
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should be a Magick::Draw object" do
|
87
|
+
@draw.should be_a Magick::Draw
|
88
|
+
end
|
89
|
+
|
90
|
+
context "with wms_settings" do
|
91
|
+
it("being a hash") { @draw.wms_settings.should be_a(Hash) }
|
92
|
+
it("having all necessary keys") { @draw.wms_settings.should include(:min_sin_y, :width, :max_sin_y, :diff_y, :bbox, :factor_x, :height)}
|
93
|
+
it("with a correct bbox") { @draw.wms_settings[:bbox].should == @options[:bbox][:wgs84]}
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
data/spec/sinatra_wms_spec.rb
CHANGED
@@ -33,5 +33,10 @@ describe SinatraWMS do
|
|
33
33
|
it 'should raise an error when an unknown baselayer is to be set' do
|
34
34
|
expect {SinatraWMS::get_html_for_map_at('/test', :baselayer=>:foo)}.to raise_error
|
35
35
|
end
|
36
|
+
|
37
|
+
it 'should set opacity correctly' do
|
38
|
+
SinatraWMS::get_html_for_map_at('/test').should =~ /base_layer.setOpacity\(1.0\);/
|
39
|
+
SinatraWMS::get_html_for_map_at('/test', :opacity=>0.3).should =~ /base_layer.setOpacity\(0.3\);/
|
40
|
+
end
|
36
41
|
end
|
37
42
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,28 @@
|
|
1
1
|
require 'rspec'
|
2
|
+
require 'sinatra'
|
3
|
+
require 'rack/test'
|
4
|
+
require 'sinatra_wms'
|
5
|
+
|
6
|
+
set :environment, :test
|
7
|
+
set :run, false
|
8
|
+
set :raise_errors, true
|
9
|
+
set :logging, false
|
2
10
|
|
3
11
|
RSpec.configure do |config|
|
4
12
|
config.color_enabled = true
|
5
13
|
config.formatter = 'documentation'
|
14
|
+
config.include Rack::Test::Methods
|
15
|
+
end
|
16
|
+
|
17
|
+
def app
|
18
|
+
@app ||= TestApp.new
|
19
|
+
end
|
20
|
+
|
21
|
+
class TestApp < Sinatra::Application
|
22
|
+
wms '/wms' do |canvas, options|
|
23
|
+
test_method(canvas, options)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.test_method(canvas, options)
|
27
|
+
end
|
6
28
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra_wms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Fabian Schlenz (@fabianonline)
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-04-
|
18
|
+
date: 2012-04-28 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -63,10 +63,10 @@ dependencies:
|
|
63
63
|
version: "2.9"
|
64
64
|
type: :development
|
65
65
|
version_requirements: *id003
|
66
|
-
description:
|
67
|
-
|
68
|
-
|
69
|
-
|
66
|
+
description: "A WMS (Web Map Service) is a great way to show lots of geolocated data on a map. Instead of generating static images (which will either be huge or don't have enough resolution), a WMS allows you to dynamically zoom in and out of your dataset.\n\n\
|
67
|
+
This gem allows you to very easily represent your data via a WMS. On one hand it extends Sinatra to give it a method called \"wms\" to process WMS-requests; on the other hand it extends RMagick to allow the developer to use coordinates in the methods used for drawing.\n\n\
|
68
|
+
Convenient methods to easily generate HTML code to show your WMS data on top of OpenStreetMaps or Google Maps are also included.\n\n\
|
69
|
+
Current test status: [](http://travis-ci.org/fabianonline/sinatra_wms) "
|
70
70
|
email:
|
71
71
|
- mail@fabianonline.de
|
72
72
|
executables: []
|
@@ -77,6 +77,7 @@ extra_rdoc_files:
|
|
77
77
|
- README.rdoc
|
78
78
|
files:
|
79
79
|
- .gitignore
|
80
|
+
- .travis.yml
|
80
81
|
- Gemfile
|
81
82
|
- README.rdoc
|
82
83
|
- Rakefile
|
@@ -85,6 +86,8 @@ files:
|
|
85
86
|
- lib/sinatra_wms/sinatra_extension.rb
|
86
87
|
- lib/sinatra_wms/version.rb
|
87
88
|
- sinatra_wms.gemspec
|
89
|
+
- spec/rmagick_extension_spec.rb
|
90
|
+
- spec/sinatra_extension_spec.rb
|
88
91
|
- spec/sinatra_wms_spec.rb
|
89
92
|
- spec/spec_helper.rb
|
90
93
|
has_rdoc: true
|