Permalink
Browse files

Initial README

  • Loading branch information...
1 parent 8ffb820 commit d6a53bc718e8d36e59aaf673148dd37e5e646222 @pka pka committed Jan 4, 2012
Showing with 70 additions and 0 deletions.
  1. +50 −0 README.rst
  2. +4 −0 lib/mapscript/mapscript_extensions.rb
  3. +16 −0 test/test_mapscript_extensions.rb
View
@@ -0,0 +1,50 @@
+Ruby MapScript API extensions
+=============================
+
+This gem extends the `SWIG MapScript API <http://mapserver.org/mapscript/mapscript.html>`_
+of `UMN MapServer <http://mapserver.org/>` with Ruby-like iterators and other API methods.
+
+Installation
+------------
+
+ruby_mapscript requires the MapScript API library to be installed.
+On Debian/Ubuntu systems::
+
+ sudo apt-get install libmapscript-ruby
+
+A Mapserver binary (CGI) is not required for executing ruby_mapscript code.
+
+To use the Gem, add it to your Gemfile or install it manually::
+
+ gem install ruby_mapscript
+
+
+Usage
+-----
+
+To use ruby_mapscript require the gem and include Mapscript in your class/module or globally::
+
+ require "rubygems"
+ require "ruby_mapscript"
+ include Mapscript
+
+ruby_mapscript provides a Ruby-like iterator interface to MapScript collections::
+
+ map.layers.each do |layer|
+ puts layer.name
+ end
+
+With the native SWIG API this would be something like::
+
+ 0.upto(map.numlayers-1) do |i|
+ layer = map.getLayer(i)
+ puts layer.name
+ end
+
+ruby_mapscript iterators include Enumerable which gives you the same methods as Ruby Arrays and Hashes have::
+
+ wms_layers = map.layers.select { |layer| layer.connectiontype == MS_WMS }
+
+
+
+*Copyright (c) 2012 Pirmin Kalberer, Sourcepole AG*
@@ -191,6 +191,10 @@ def classes
def processings
@processings ||= MapscriptEnumerable.new(self, :numprocessing, :getProcessing)
end
+
+ def visible?
+ isVisible == MS_TRUE
+ end
end
# LineObj extensions
@@ -93,6 +93,8 @@ def test_layer_access
assert_equal oldcnt+1, @map.numlayers
assert_equal @map.numlayers, @map.layers.to_a.size
assert_equal @map.numlayers, @map.layers[0..-1].size
+
+ assert !@map.layers.first.visible?
end
def test_class_access
@@ -147,4 +149,18 @@ def test_draw
mapimage = @map.draw
assert mapimage.getSize >= 2338
end
+
+ def test_examples
+ map = @map
+ map.layers.each do |layer|
+ #puts layer.name
+ end
+ 0.upto(map.numlayers-1) do |i|
+ layer = map.getLayer(i)
+ #puts layer.name
+ end
+ wms_layers = map.layers.select { |layer| layer.connectiontype == MS_WMS }
+ assert_equal 1, wms_layers.size
+ end
+
end

0 comments on commit d6a53bc

Please sign in to comment.