0.0
No commit activity in last 3 years
No release in over 3 years
A simple wrapper for ArcGIS REST (GeoServices) API
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 1.12
~> 10.0
~> 3.0
 Project Readme

GeoServices Ruby Library

Build status Gem Version

This Gem is a fork of the official ESRI repo. Full attribubution is given to the original authors and license-holders

This library is a simple wrapper around the ArcGIS REST ("GeoServices") API. You can see the GeoServices REST Specification

If you have not worked with GeoServices before, there are a few basic concepts to get started:

  • Service is the base and has many layers. This just holds metadata about who created the service, and the layers it contains.
  • Layer a layer is like a dataset with many features. You can query a Layer by spatial extent, attribute parameters and even perform aggregations with statistics and group by fields
  • Feature an individual location, or record, or row, is called a 'feature'. A feature has many attributes

Install

Just install using Rubygems:

gem install geoservices

Usage

@service = Geoservice::MapService.new(:url => "http://rmgsc.cr.usgs.gov/ArcGIS/rest/services/nhss_weat/MapServer")
@service.layers[0]["name"] #=> "Watches/Warnings"

If calling to a secure service, include :token => TOKEN in the constructor.

Query

To request data from a service, you need the URL to the service, the layer index, and then add optional query parameters.

To get all features:

service_url = "https://services2.arcgis.com/1gVyYKfYgW5Nxb1V/ArcGIS/rest/services/MesaAzCouncilDistricts/FeatureServer"
service = Geoservice::MapService.new(url: service_url)
features = service.query(0)["features"]
puts features.length #=> 6
puts features.first["attributes"]
#=> {"OBJECTID"=>1, "DISTRICT"=>1, "DISTRICTS"=>"DISTRICT 1", "FACILITYID"=>nil, "GLOBALID"=>"1c14efc5-cef2-4757-a9f5-8be2c3eeab66"}

You can also perform spatial queries:

params = {
  geometry: [-111.835,33.42].join(','),
  geometryType: "esriGeometryPoint",
  inSR: 4326,
  spatialRel: "esriSpatialRelIntersects",
  units: "esriSRUnit_Meter",
  returnGeometry: false
}
query = service.query(0, params)
puts query["features"]
#=> {"attributes"=>{"OBJECTID"=>4, "DISTRICT"=>4, "DISTRICTS"=>"DISTRICT 4", "FACILITYID"=>nil, "GLOBALID"=>"c9f2f6f1-d210-4332-8610-8ad176ab9d07"}}

Testing

geoservices-ruby uses Rake and RSpec for tests.

$ rake spec

Requirements

  • Ruby

Resources

Licensing

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

A copy of the license is available in the repository's license.txt file.

[](Esri Tags: ArcGIS Ruby API GeoServices Public) [](Esri Language: Ruby)