GithubHelp home page GithubHelp logo

ruby_mapscript's Introduction

Ruby MapScript API extensions

This gem extends the SWIG MapScript API of UMN MapServer 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 = MapObj.new('test.map')
map.layers.each do |layer|
  puts layer.name
end
mapimage = map.draw
mapimage.save('test.png')

With the generic SWIG API iterating would look 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:

wms_layers = map.layers.select { |layer| layer.connectiontype == MS_WMS }

To run a MapScript based WMS server as a Rack application create config.ru:

require "ruby_mapscript/mapserver"

run RubyMapscript::Mapserver.new('test.map')

and call:

rackup config.ru

To include a WMS server in a Rails application, require "ruby_mapscript/mapserver" and add a line to your routes.rb:

match "/wms" => RubyMapscript::Mapserver.new('test.map')

Copyright (c) 2012 Pirmin Kalberer, Sourcepole AG

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.