ruby_mapscript 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.rst +64 -0
- data/Rakefile +11 -0
- data/lib/mapscript/mapscript_extensions.rb +252 -0
- data/lib/ruby_mapscript.rb +2 -0
- data/lib/ruby_mapscript/mapserver.rb +37 -0
- data/lib/ruby_mapscript/version.rb +3 -0
- data/ruby_mapscript.gemspec +20 -0
- data/test/data/world_testpoly.dbf +0 -0
- data/test/data/world_testpoly.shp +0 -0
- data/test/data/world_testpoly.shx +0 -0
- data/test/empty.map +17 -0
- data/test/test.map +69 -0
- data/test/test_mapscript_extensions.rb +166 -0
- metadata +80 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.rst
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
Ruby MapScript API extensions
|
2
|
+
=============================
|
3
|
+
|
4
|
+
This gem extends the `SWIG MapScript API <http://mapserver.org/mapscript/mapscript.html>`_
|
5
|
+
of `UMN MapServer <http://mapserver.org/>`_ with Ruby-like iterators and other API methods.
|
6
|
+
|
7
|
+
Installation
|
8
|
+
------------
|
9
|
+
|
10
|
+
ruby_mapscript requires the MapScript API library to be installed.
|
11
|
+
On Debian/Ubuntu systems::
|
12
|
+
|
13
|
+
sudo apt-get install libmapscript-ruby
|
14
|
+
|
15
|
+
A Mapserver binary (CGI) is not required for executing ruby_mapscript code.
|
16
|
+
|
17
|
+
To use the gem, add it to your Gemfile or install it manually::
|
18
|
+
|
19
|
+
gem install ruby_mapscript
|
20
|
+
|
21
|
+
|
22
|
+
Usage
|
23
|
+
-----
|
24
|
+
|
25
|
+
To use ruby_mapscript, require the gem and include Mapscript in your class/module or globally::
|
26
|
+
|
27
|
+
require "rubygems"
|
28
|
+
require "ruby_mapscript"
|
29
|
+
include Mapscript
|
30
|
+
|
31
|
+
ruby_mapscript provides a Ruby-like iterator interface to MapScript collections::
|
32
|
+
|
33
|
+
map.layers.each do |layer|
|
34
|
+
puts layer.name
|
35
|
+
end
|
36
|
+
|
37
|
+
With the native SWIG API this would be something like::
|
38
|
+
|
39
|
+
0.upto(map.numlayers-1) do |i|
|
40
|
+
layer = map.getLayer(i)
|
41
|
+
puts layer.name
|
42
|
+
end
|
43
|
+
|
44
|
+
ruby_mapscript iterators include Enumerable which gives you the same methods as Ruby Arrays and Hashes have::
|
45
|
+
|
46
|
+
wms_layers = map.layers.select { |layer| layer.connectiontype == MS_WMS }
|
47
|
+
|
48
|
+
|
49
|
+
To run a MapScript based WMS server as a Rack application create config.ru::
|
50
|
+
|
51
|
+
require "ruby_mapscript/mapserver"
|
52
|
+
|
53
|
+
run RubyMapscript::Mapserver.new('test.map')
|
54
|
+
|
55
|
+
and call::
|
56
|
+
|
57
|
+
rackup config.ru
|
58
|
+
|
59
|
+
To include a WMS server in a Rails application, require "ruby_mapscript/mapserver" and add a line to your routes.rb::
|
60
|
+
|
61
|
+
match "/wms" => RubyMapscript::Mapserver.new('test.map')
|
62
|
+
|
63
|
+
|
64
|
+
*Copyright (c) 2012 Pirmin Kalberer, Sourcepole AG*
|
data/Rakefile
ADDED
@@ -0,0 +1,252 @@
|
|
1
|
+
# Ruby Mapscript API extensions
|
2
|
+
|
3
|
+
require "mapscript"
|
4
|
+
|
5
|
+
module Mapscript
|
6
|
+
|
7
|
+
# Generic iterator for Mapscript collections
|
8
|
+
class MapscriptEnumerable
|
9
|
+
include Enumerable
|
10
|
+
|
11
|
+
def initialize(parent, size_method, getter)
|
12
|
+
@parent, @size_method, @getter = parent, size_method, getter
|
13
|
+
end
|
14
|
+
|
15
|
+
def size
|
16
|
+
@parent.send(@size_method)
|
17
|
+
end
|
18
|
+
|
19
|
+
def each
|
20
|
+
0.upto(size-1) do |idx|
|
21
|
+
yield @parent.send(@getter, idx)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def [](idx)
|
26
|
+
case idx
|
27
|
+
when Fixnum
|
28
|
+
if idx >= 0
|
29
|
+
@parent.send(@getter, idx)
|
30
|
+
else
|
31
|
+
@parent.send(@getter, size+idx)
|
32
|
+
end
|
33
|
+
when Range
|
34
|
+
to_a[idx]
|
35
|
+
else
|
36
|
+
raise TypeError, "Unsupported type for index"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
# LayerObj iterator
|
43
|
+
class MapLayers < MapscriptEnumerable
|
44
|
+
|
45
|
+
def initialize(map)
|
46
|
+
super(map, :numlayers, :getLayer)
|
47
|
+
@map = map
|
48
|
+
end
|
49
|
+
|
50
|
+
def [](idx)
|
51
|
+
case idx
|
52
|
+
when Fixnum
|
53
|
+
if idx >= 0
|
54
|
+
@map.getLayer(idx)
|
55
|
+
else
|
56
|
+
@map.getLayer(@map.numlayers+idx)
|
57
|
+
end
|
58
|
+
when Range
|
59
|
+
to_a[idx]
|
60
|
+
when String
|
61
|
+
@map.getLayerByName(idx)
|
62
|
+
else
|
63
|
+
raise TypeError, "Unsupported type for index"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def <<(layer)
|
68
|
+
@map.insertLayer(layer, @map.numlayers-1)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
# ClassObj iterator
|
73
|
+
class LayerClasses < MapscriptEnumerable
|
74
|
+
|
75
|
+
def initialize(layer)
|
76
|
+
super(layer, :numclasses, :getClass)
|
77
|
+
@layer = layer
|
78
|
+
end
|
79
|
+
|
80
|
+
def [](idx)
|
81
|
+
case idx
|
82
|
+
when Fixnum
|
83
|
+
if idx >= 0
|
84
|
+
@layer.getClass(idx)
|
85
|
+
else
|
86
|
+
@layer.getClass(@layer.numclasses+idx)
|
87
|
+
end
|
88
|
+
when Range
|
89
|
+
to_a[idx]
|
90
|
+
when String
|
91
|
+
find { |cls| cls.name == idx }
|
92
|
+
else
|
93
|
+
raise TypeError, "Unsupported type for index"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def <<(newclass)
|
98
|
+
@layer.insertClass(newclass, @layer.numclasses-1)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
|
103
|
+
# ClassObj extensions
|
104
|
+
class ClassObj
|
105
|
+
# Return StyleObj iterator
|
106
|
+
def styles
|
107
|
+
@styles ||= MapscriptEnumerable.new(self, :numstyles, :getStyle)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
# HashTableObj extensions
|
112
|
+
class HashTableObj
|
113
|
+
include Enumerable
|
114
|
+
|
115
|
+
def [](key)
|
116
|
+
get(key)
|
117
|
+
end
|
118
|
+
|
119
|
+
def []=(key, value)
|
120
|
+
set(key, value)
|
121
|
+
end
|
122
|
+
|
123
|
+
def each_key
|
124
|
+
key = nextKey(nil)
|
125
|
+
while key
|
126
|
+
yield key
|
127
|
+
key = nextKey(key)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def has_key?(key)
|
132
|
+
!get(key).nil?
|
133
|
+
end
|
134
|
+
|
135
|
+
alias :key? :has_key?
|
136
|
+
alias :include? :has_key?
|
137
|
+
|
138
|
+
def keys
|
139
|
+
ary = []
|
140
|
+
each_key { |key| ary << key }
|
141
|
+
ary
|
142
|
+
end
|
143
|
+
|
144
|
+
alias :length :numitems
|
145
|
+
alias :size :numitems
|
146
|
+
|
147
|
+
def empty?
|
148
|
+
numitems == 0
|
149
|
+
end
|
150
|
+
|
151
|
+
alias :delete :remove
|
152
|
+
|
153
|
+
def each_pair
|
154
|
+
key = nextKey(nil)
|
155
|
+
while key
|
156
|
+
yield key, get(key)
|
157
|
+
key = nextKey(key)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
alias :each :each_pair
|
162
|
+
|
163
|
+
def to_hash
|
164
|
+
h = {}
|
165
|
+
each_pair { |key, value| h[key] = value }
|
166
|
+
h
|
167
|
+
end
|
168
|
+
|
169
|
+
def inspect
|
170
|
+
to_hash.inspect
|
171
|
+
end
|
172
|
+
|
173
|
+
end
|
174
|
+
|
175
|
+
# LabelObj extensions
|
176
|
+
class LabelObj
|
177
|
+
# Return styleObj iterator
|
178
|
+
def styles
|
179
|
+
@styles ||= MapscriptEnumerable.new(self, :numstyles, :getStyle)
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
# LayerObj extensions
|
184
|
+
class LayerObj
|
185
|
+
# Return ClassObj iterator
|
186
|
+
def classes
|
187
|
+
@classes ||= LayerClasses.new(self)
|
188
|
+
end
|
189
|
+
|
190
|
+
# Return string iterator
|
191
|
+
def processings
|
192
|
+
@processings ||= MapscriptEnumerable.new(self, :numprocessing, :getProcessing)
|
193
|
+
end
|
194
|
+
|
195
|
+
def visible?
|
196
|
+
isVisible == MS_TRUE
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
# LineObj extensions
|
201
|
+
class LineObj
|
202
|
+
# Return pointObj iterator
|
203
|
+
def points
|
204
|
+
@points ||= MapscriptEnumerable.new(self, :numpoints, :get)
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
# MapObj extensions
|
209
|
+
class MapObj
|
210
|
+
# Return LayerObj iterator
|
211
|
+
def layers
|
212
|
+
@map_layers ||= MapLayers.new(self)
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
# ResultCacheObj extensions
|
217
|
+
class ResultCacheObj
|
218
|
+
# Return resultCacheObj iterator
|
219
|
+
def results
|
220
|
+
@results ||= MapscriptEnumerable.new(self, :numresults, :getResult)
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
# ShapefileObj extensions
|
225
|
+
class ShapefileObj
|
226
|
+
# Return shapeObj iterator
|
227
|
+
def shapes
|
228
|
+
@shapes ||= MapscriptEnumerable.new(self, :numshapes, :getShape)
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
# ShapeObj extensions
|
233
|
+
class ShapeObj
|
234
|
+
# Return lineObj iterator
|
235
|
+
def lines
|
236
|
+
@lines ||= MapscriptEnumerable.new(self, :numlines, :get)
|
237
|
+
end
|
238
|
+
|
239
|
+
# Return shape attribute (string) iterator
|
240
|
+
def values
|
241
|
+
@values ||= MapscriptEnumerable.new(self, :numvalues, :getValue)
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
# SymbolSetObj extensions
|
246
|
+
class SymbolSetObj
|
247
|
+
# Return symbolObj iterator
|
248
|
+
def symbols
|
249
|
+
@symbols ||= MapscriptEnumerable.new(self, :numsymbols, :getSymbol) #:getSymbolByName
|
250
|
+
end
|
251
|
+
end
|
252
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# OGC compliant map server Rack Application
|
2
|
+
# OWS requests include WMS, WFS, WCS and SOS requests supported by MapServer
|
3
|
+
|
4
|
+
require "mapscript"
|
5
|
+
|
6
|
+
module RubyMapscript
|
7
|
+
|
8
|
+
class Mapserver
|
9
|
+
|
10
|
+
def initialize(mapfile)
|
11
|
+
@wms = Mapscript::MapObj.new(mapfile)
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(env)
|
15
|
+
req = Mapscript::OWSRequest.new
|
16
|
+
%w(REQUEST_METHOD QUERY_STRING HTTP_COOKIE).each do |var|
|
17
|
+
ENV[var] = env[var]
|
18
|
+
end
|
19
|
+
req.loadParams
|
20
|
+
#Returns the number of name/value pairs collected.
|
21
|
+
#Warning: most errors will result in a process exit!
|
22
|
+
|
23
|
+
# redirect stdout & handle request
|
24
|
+
Mapscript::msIO_installStdoutToBuffer()
|
25
|
+
retval = @wms.OWSDispatch(req)
|
26
|
+
#Returns MS_DONE (2) if there is no valid OWS request in the req object,
|
27
|
+
# MS_SUCCESS (0) if an OWS request was successfully processed and
|
28
|
+
# MS_FAILURE (1) if an OWS request was not successfully processed.
|
29
|
+
content_type = Mapscript::msIO_stripStdoutBufferContentType()
|
30
|
+
map_image = Mapscript::msIO_getStdoutBufferBytes()
|
31
|
+
Mapscript::msIO_resetHandlers()
|
32
|
+
|
33
|
+
[200, {'Content-Type' => content_type}, map_image]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "ruby_mapscript/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "ruby_mapscript"
|
7
|
+
s.version = RubyMapscript::VERSION
|
8
|
+
s.authors = ["Pirmin Kalberer"]
|
9
|
+
s.email = ["pka@sourcepole.ch"]
|
10
|
+
s.homepage = "https://github.com/sourcepole/ruby_mapscript"
|
11
|
+
s.summary = %q{Ruby Mapscript API extensions}
|
12
|
+
s.description = %q{Ruby Mapscript API extensions}
|
13
|
+
|
14
|
+
s.rubyforge_project = "ruby_mapscript"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
end
|
Binary file
|
Binary file
|
Binary file
|
data/test/empty.map
ADDED
data/test/test.map
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
MAP
|
2
|
+
NAME "Test Map"
|
3
|
+
SIZE 600 600
|
4
|
+
EXTENT -180 -90 180 90
|
5
|
+
IMAGECOLOR 180 180 250
|
6
|
+
IMAGETYPE PNG
|
7
|
+
|
8
|
+
#CONFIG "MS_ERRORFILE" "stderr" # http://mapserver.org/optimization/debugging.html#step-1-set-the-ms-errorfile-variable
|
9
|
+
#DEBUG 5 # http://mapserver.org/optimization/debugging.html#step-2-set-the-debug-level
|
10
|
+
#CONFIG "CPL_DEBUG" "ON" # http://mapserver.org/optimization/debugging.html#step-3-turn-on-cpl-debug-optional
|
11
|
+
#CONFIG "PROJ_DEBUG" "ON" # http://mapserver.org/optimization/debugging.html#step-4-turn-on-proj-debug-optional
|
12
|
+
|
13
|
+
UNITS DD
|
14
|
+
PROJECTION
|
15
|
+
"init=epsg:4326"
|
16
|
+
END
|
17
|
+
|
18
|
+
WEB
|
19
|
+
IMAGEPATH "/tmp/"
|
20
|
+
IMAGEURL "/tmp/"
|
21
|
+
METADATA
|
22
|
+
"wms_srs" "EPSG:4326"
|
23
|
+
"wms_onlineresource" "http://localhost:9292/"
|
24
|
+
"ows_enable_request" "*"
|
25
|
+
"wms_feature_info_mime_type" "text/html"
|
26
|
+
"wms_title" "Rackup Test WMS"
|
27
|
+
END # METADATA
|
28
|
+
END # WEB
|
29
|
+
|
30
|
+
LAYER
|
31
|
+
NAME "wms_layer"
|
32
|
+
TYPE RASTER
|
33
|
+
STATUS OFF
|
34
|
+
CONNECTIONTYPE WMS
|
35
|
+
CONNECTION "http://iceds.ge.ucl.ac.uk/cgi-bin/icedswms?"
|
36
|
+
METADATA
|
37
|
+
"wms_title" "WMS Layer"
|
38
|
+
"wms_extent" "-180 -90 180 90"
|
39
|
+
"wms_srs" "EPSG:4326"
|
40
|
+
"wms_name" "landsat5,landsat,GRID"
|
41
|
+
"wms_server_version" "1.1.1"
|
42
|
+
"wms_format" "image/jpeg"
|
43
|
+
END
|
44
|
+
END
|
45
|
+
|
46
|
+
LAYER
|
47
|
+
NAME shppoly
|
48
|
+
TYPE line
|
49
|
+
DATA "data/world_testpoly.shp"
|
50
|
+
STATUS ON
|
51
|
+
CLASSITEM "FID"
|
52
|
+
CLASS
|
53
|
+
NAME "test1"
|
54
|
+
STYLE
|
55
|
+
COLOR 20 20 20
|
56
|
+
WIDTH 5
|
57
|
+
END
|
58
|
+
STYLE
|
59
|
+
COLOR 50 50 255
|
60
|
+
WIDTH 3
|
61
|
+
END
|
62
|
+
STYLE
|
63
|
+
COLOR 255 255 0
|
64
|
+
WIDTH 1
|
65
|
+
PATTERN 4 4 END
|
66
|
+
END
|
67
|
+
END
|
68
|
+
END
|
69
|
+
END
|
@@ -0,0 +1,166 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require "ruby_mapscript"
|
3
|
+
include Mapscript
|
4
|
+
|
5
|
+
class TestMapscriptExtension < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
mapfile = File.join(File.dirname(__FILE__), 'test.map')
|
8
|
+
@map = MapObj.new(mapfile)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_arrays
|
12
|
+
assert_equal 0, @map.getLayersDrawingOrder[0]
|
13
|
+
style = @map.layers['shppoly'].classes.first.styles[-1]
|
14
|
+
assert_equal SWIG::TYPE_p_double, style.pattern.class
|
15
|
+
if defined?(Doublearray)
|
16
|
+
pattern = Doublearray.frompointer(style.pattern)
|
17
|
+
assert_equal 4.0, pattern[0]
|
18
|
+
assert_equal 4.0, pattern[style.patternlength-1]
|
19
|
+
else
|
20
|
+
puts "Warning: Mapscript library does not support Doublearray"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_hashtable
|
25
|
+
layer = @map.layers['wms_layer']
|
26
|
+
metadata = layer.metadata
|
27
|
+
|
28
|
+
assert metadata.has_key?("wms_title")
|
29
|
+
assert metadata.key?("wms_title")
|
30
|
+
assert metadata.include?("wms_title")
|
31
|
+
assert !metadata.key?("XXX")
|
32
|
+
|
33
|
+
assert_equal 6, metadata.numitems
|
34
|
+
assert_equal metadata.numitems, metadata.length
|
35
|
+
assert_equal metadata.numitems, metadata.keys.size
|
36
|
+
|
37
|
+
assert metadata.keys.include?("wms_title")
|
38
|
+
assert_equal "WMS Layer", metadata["wms_title"]
|
39
|
+
|
40
|
+
metadata.each do |k, v|
|
41
|
+
assert_equal metadata[k], v
|
42
|
+
end
|
43
|
+
|
44
|
+
#Update entry
|
45
|
+
metadata["wms_title"] = "New Title"
|
46
|
+
assert_equal "New Title", metadata["wms_title"]
|
47
|
+
|
48
|
+
#Add new entry
|
49
|
+
metadata["new_key"] = "New Value"
|
50
|
+
assert_equal 7, metadata.numitems
|
51
|
+
|
52
|
+
metadata.delete("new_key")
|
53
|
+
assert_equal 6, metadata.numitems
|
54
|
+
|
55
|
+
assert_equal "EPSG:4326", metadata.to_hash["wms_srs"]
|
56
|
+
|
57
|
+
#Enumerable
|
58
|
+
assert_equal metadata.keys, metadata.collect { |k, v| k }
|
59
|
+
assert_equal ["wms_srs", "EPSG:4326"], metadata.to_a.first
|
60
|
+
|
61
|
+
#Test Empty Hash
|
62
|
+
metadata = @map.web.metadata
|
63
|
+
assert !metadata.key?("wms_title")
|
64
|
+
assert_equal 0, metadata.numitems
|
65
|
+
assert_equal metadata.numitems, metadata.length
|
66
|
+
assert_equal metadata.numitems, metadata.keys.size
|
67
|
+
assert metadata.keys.empty?
|
68
|
+
assert_nil metadata["wms_title"]
|
69
|
+
metadata.each {}
|
70
|
+
metadata["new_key"] = "New Value"
|
71
|
+
assert_equal 1, metadata.numitems
|
72
|
+
metadata.delete("new_key")
|
73
|
+
assert_equal 0, metadata.numitems
|
74
|
+
assert_equal({}, metadata.to_hash)
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_layer_access
|
78
|
+
assert_equal @map.numlayers, @map.layers.size
|
79
|
+
assert_equal @map.numlayers, @map.layers.count #From Enumerable
|
80
|
+
assert_equal @map.numlayers, @map.layers.to_a.size #to_a from Enumerable
|
81
|
+
assert_equal @map.numlayers, @map.layers[0..-1].size
|
82
|
+
assert_equal 0, @map.layers.first.index
|
83
|
+
@map.layers.each_with_index do |l, i|
|
84
|
+
assert_equal i, @map.layers[i].index
|
85
|
+
end
|
86
|
+
assert_equal 'wms_layer', @map.layers[0].name
|
87
|
+
assert_equal 'wms_layer', @map.layers[-@map.numlayers].name
|
88
|
+
assert_nil @map.layers[99]
|
89
|
+
assert_equal 'wms_layer', @map.layers['wms_layer'].name
|
90
|
+
assert_nil @map.layers['xxx']
|
91
|
+
oldcnt = @map.numlayers
|
92
|
+
@map.layers << @map.layers.first
|
93
|
+
assert_equal oldcnt+1, @map.numlayers
|
94
|
+
assert_equal @map.numlayers, @map.layers.to_a.size
|
95
|
+
assert_equal @map.numlayers, @map.layers[0..-1].size
|
96
|
+
|
97
|
+
assert !@map.layers.first.visible?
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_class_access
|
101
|
+
layer = @map.layers['shppoly']
|
102
|
+
assert_equal layer.numclasses, layer.classes.to_a.size
|
103
|
+
assert_equal layer.numclasses, layer.classes[0..-1].size
|
104
|
+
assert_equal 'test1', layer.classes[0].name
|
105
|
+
assert_equal 'test1', layer.classes[-layer.numclasses].name
|
106
|
+
assert_nil layer.classes[99]
|
107
|
+
assert_equal 'test1', layer.classes['test1'].name
|
108
|
+
assert_nil layer.classes['xxx']
|
109
|
+
oldcnt = layer.numclasses
|
110
|
+
layer.classes << layer.classes.first
|
111
|
+
assert_equal oldcnt+1, layer.numclasses
|
112
|
+
assert_equal layer.numclasses, layer.classes.to_a.size
|
113
|
+
assert_equal layer.numclasses, layer.classes[0..-1].size
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_iterators
|
117
|
+
assert_equal 0, LabelObj.new.styles.size
|
118
|
+
|
119
|
+
assert_equal 0, ResultCacheObj.new.results.size
|
120
|
+
|
121
|
+
shapefile = File.join(File.dirname(__FILE__), 'data', 'world_testpoly.shp')
|
122
|
+
shapefile_obj = ShapefileObj.new(shapefile)
|
123
|
+
assert_equal 4, shapefile_obj.shapes.size
|
124
|
+
shape = shapefile_obj.shapes[0]
|
125
|
+
assert_equal 0, shape.index
|
126
|
+
assert_equal 1, shape.lines.size
|
127
|
+
lines = shape.lines[0]
|
128
|
+
assert_equal 0, shape.values.size
|
129
|
+
assert_equal 5, lines.points.size
|
130
|
+
point = lines.points[0]
|
131
|
+
assert_not_nil point
|
132
|
+
|
133
|
+
symbol_set = SymbolSetObj.new
|
134
|
+
assert_equal 1, symbol_set.symbols.size
|
135
|
+
assert_not_nil symbol_set.symbols[0]
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_empty_map
|
139
|
+
mapfile = File.join(File.dirname(__FILE__), 'empty.map')
|
140
|
+
@map = MapObj.new(mapfile)
|
141
|
+
assert_equal 0, @map.layers.to_a.size
|
142
|
+
assert_nil @map.layers[0]
|
143
|
+
assert_nil @map.layers[-1]
|
144
|
+
assert_nil @map.layers['wms_layer']
|
145
|
+
@map.layers.each { }
|
146
|
+
end
|
147
|
+
|
148
|
+
def test_draw
|
149
|
+
mapimage = @map.draw
|
150
|
+
assert mapimage.getSize >= 2338
|
151
|
+
end
|
152
|
+
|
153
|
+
def test_examples
|
154
|
+
map = @map
|
155
|
+
map.layers.each do |layer|
|
156
|
+
#puts layer.name
|
157
|
+
end
|
158
|
+
0.upto(map.numlayers-1) do |i|
|
159
|
+
layer = map.getLayer(i)
|
160
|
+
#puts layer.name
|
161
|
+
end
|
162
|
+
wms_layers = map.layers.select { |layer| layer.connectiontype == MS_WMS }
|
163
|
+
assert_equal 1, wms_layers.size
|
164
|
+
end
|
165
|
+
|
166
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby_mapscript
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 19
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 3
|
9
|
+
- 0
|
10
|
+
version: 0.3.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Pirmin Kalberer
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-02-24 00:00:00 Z
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: Ruby Mapscript API extensions
|
22
|
+
email:
|
23
|
+
- pka@sourcepole.ch
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files: []
|
29
|
+
|
30
|
+
files:
|
31
|
+
- .gitignore
|
32
|
+
- Gemfile
|
33
|
+
- README.rst
|
34
|
+
- Rakefile
|
35
|
+
- lib/mapscript/mapscript_extensions.rb
|
36
|
+
- lib/ruby_mapscript.rb
|
37
|
+
- lib/ruby_mapscript/mapserver.rb
|
38
|
+
- lib/ruby_mapscript/version.rb
|
39
|
+
- ruby_mapscript.gemspec
|
40
|
+
- test/data/world_testpoly.dbf
|
41
|
+
- test/data/world_testpoly.shp
|
42
|
+
- test/data/world_testpoly.shx
|
43
|
+
- test/empty.map
|
44
|
+
- test/test.map
|
45
|
+
- test/test_mapscript_extensions.rb
|
46
|
+
homepage: https://github.com/sourcepole/ruby_mapscript
|
47
|
+
licenses: []
|
48
|
+
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 3
|
60
|
+
segments:
|
61
|
+
- 0
|
62
|
+
version: "0"
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
hash: 3
|
69
|
+
segments:
|
70
|
+
- 0
|
71
|
+
version: "0"
|
72
|
+
requirements: []
|
73
|
+
|
74
|
+
rubyforge_project: ruby_mapscript
|
75
|
+
rubygems_version: 1.7.2
|
76
|
+
signing_key:
|
77
|
+
specification_version: 3
|
78
|
+
summary: Ruby Mapscript API extensions
|
79
|
+
test_files: []
|
80
|
+
|