Library for accessing ESRI ArcServer REST APIs.
Switch branches/tags
Nothing to show
Pull request Compare This branch is 66 commits ahead of colincasey:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Arcserver.rb is an interface for interacting with ESRI ArcGIS Server REST APIs from Ruby.

ArcGIS rest specification

Build Status Code Climate Coverage Status


From command line

[sudo] gem install arcserver.rb

If you want to use it in with Bundler add to your Gemfile

gem 'arcserver.rb', '~> 0.1.5'

Quick Example

Require the gem

require 'arcserver'

Connect to a map server instance using either its REST url

map_server ='')

and export an image

puts map_server.export

Query for retreive some features, the result will be a FeatureSet, which is a wrapper for the layer information and the features found

query ={ where: "district='4'", outFields: "*" })
feature_set = query.execute('0', "")

puts feature_set.features

Or directly within a MapServer or FeatureServer and his Layer number

feature_server ="")
feature_set = feature_server.query('0', { where: "district='Lugano'", outFields: "*" })

Query is possible in different ways, like through geometry

feature_server ="")
feature_set = feature_server.query('0', { geometryType: 'esriGeometryEnvelope', geometry: '{"xmin":997878.8354556253,"ymin":5783588.635939264,"xmax":998147.5593831083,"ymax":5783767.785224252,"spatialReference":{"wkid":102100}}', outFields: "*", inSR: 102100, outSR: 102100 })

puts feature_set.features

An Identify operation is a query but applied to all layers in the MapServer

map_server ="")
results = map_server.identify({ geometryType: "esriGeometryPoint", geometry: "-120,40", tolerance: "10", mapExtent: "-119,38,-121,41", imageDisplay: "400,300,96" })

puts results # each results has its own feature and metadata

A feature is a simple class with Geometry and attributes, create one is easy

f ={ geometry: { x: 997986.5006082746, y: 5783631.06234916, spatialReference: { wkid: 102100 }}, attributes: {status:1,req_id:"12345",req_type:"Graffiti Complaint – Private Property",req_date:"30.09.2013",req_time:"14:00",address:"via dei matti 0",district:"4"} })

Once you have a feature, it's ready to be saved on a feature layer

fs ="")
results = fs.applyEdits('0', [ f ], [], []) # adds, updates, deletes

You can simply edit a feature if you have an objectId, maybe retrieved with a Query

f ={ attributes: { objectId: 12345, address: "via dei matti 0", district: "4"} })
results = fs.applyEdits('0', [], [ f ], []) # adds, updates, deletes

And if you want to delete some features?

feature_server ="")
feature_set = feature_server.query('0', { geometryType: 'esriGeometryEnvelope', geometry: '{"xmin":997878.8354556253,"ymin":5783588.635939264,"xmax":998147.5593831083,"ymax":5783767.785224252,"spatialReference":{"wkid":102100}}', outFields: "*", inSR: 102100, outSR: 102100 })
# we have to create an array of ids like this: '80012, 93002'
deletes = { |f| f.attributes[:objectid] }.join(',')
results = feature_server.applyEdits('0', [], [], deletes)

GeoProcessing Tool

Geoprocessing is a fundamental part of enterprise GIS operations. Geoprocessing provides the data analysis, data management, and data conversion tools necessary for all GIS users.

The ArcGIS Server supports two types of GPServer: Sync and Async.

The message in a bottle example, sync

gp ="")

feature ={ geometry:{ x: -76.2890625, y: 35.859375, spatialReference: { wkid: 4326 } }) })

feature_set ={ features: [ feature ] })

params = { Input_Point: feature_set.to_json, Days: 1 }
results =  gp.execute(params)

puts results # => {"paramName"=>"Output", "dataType"=>"GPFeatureRecordSetLayer", "value"=>{"geometryType"=>"esriGeometryPolyline", "spatialReference"=>{"wkid"=>4326}, "features"=>[{"attributes"=>{"FID"=>1, "FNODE_"=>0, "Shape_Length"=>0.19891537566450523}, "geometry"=>{"paths"=>[[[-76.2890625, 35.859375], [-76.09141540527344, 35.88180160522461]]]}}], "exceededTransferLimit"=>false}}

Example for async service:

gp ="")

params = { Web_Map_as_JSON: '{ ... super long map in json ... }', Format: 'JPG', Layout_Template: 'MAP_ONLY' }
gp.submitJob(params) do |results|
  puts results['Output_File']['url'] # => ... /map.jpg


This is a fork of arcserver.rb originally written by:

  • Colin Casey
  • Glenn Goodrich


If you'd like to hack on arcserver.rb, start by forking my repo on GitHub:

To get all of the dependencies, install the gem first. The best way to get your changes merged back into core is as follows:

  1. Clone your fork
  2. Create a thoughtfully named topic branch to contain your change
  3. Hack away
  4. Add tests and make sure everything still passes by running rake
  5. If you are adding new functionality, document it in the README
  6. Do not change the version number, I will do that on my end
  7. If necessary, rebase your commits into logical chunks, without errors
  8. Push the branch up to GitHub
  9. Send me a pull request for your branch


Copyright (c) 2010 Colin Casey. See LICENSE for details.