Skip to content

RGeoServer is a Ruby client for the GeoServer RESTful Configuration interface.

Notifications You must be signed in to change notification settings

rnz0/rgeoserver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

95 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

<img src=“https://gemnasium.com/rnz0/rgeoserver.png” alt=“Dependency Status” /> <img src=“https://secure.travis-ci.org/rnz0/rgeoserver.png” />

RGeoServer

RGeoServer is a Ruby client for the GeoServer RESTful Configuration interface.

It provides primitive Ruby model abstraction.

Documentation

The GeoServer REST Configuration API Reference can be found here:

docs.geoserver.org/stable/en/user/rest/index.html

Installation

$ gem install rgeoserver

Example:

Sample usage from an irb console

> catalog = RGeoServer::Catalog.new :user=>"admin", :url=>"http://10.0.0.2/geoserver/rest", :password=>"osgeo!"
=> Catalog: http://10.0.0.2/geoserver/rest
> w = catalog.get_workspace('topp') 
=> RGeoServer::Workspace: topp
> ds = w.data_stores.first
=> RGeoServer::DataStore: states_shapefile
> ds.profile
=> {"name"=>"states_shapefile", "enabled"=>"true", "connectionParameters"=>{"url"=>"file:data/shapefiles/states.shp", "namespace"=>"http://www.openplans.org/topp"}, "featureTypes"=>["states"]} 
> ft = ds.featuretypes.first
=> RGeoServer::FeatureType: states 
> ft.profile
=> {:name=>"states", :workspace=>"topp", :nativeName=>"states"}  

> lyr = RGeoServer::Layer.new c, :name => 'Arc_Sample'
=> RGeoServer::Layer: Arc_Sample 
> lyr.profile
=> {"name"=>"Arc_Sample", "path"=>"/", "defaultstyle"=>"rain", "styles"=>["raster"], "type"=>"RASTER", "enabled"=>"true", "attribution"=>{"logoWidth"=>"0", "logoHeight"=>"0"}, "resource"=>{"type"=>"coverage", "name"=>"Arc_Sample", "store"=>"arcGridSample", "workspace"=>"nurc"}, "metadata"=>{"GWC.autoCacheStyles"=>"true", "GWC.metaTilingX"=>"4", "GWC.metaTilingY"=>"4", "GWC.gutter"=>"0", "GWC.cachedNonDefaultStyles"=>"raster", "GWC.enabled"=>"true", "GWC.cacheFormats"=>"image/jpeg,image/png", "GWC.gridSets"=>"EPSG:4326,EPSG:900913"}}
> sld = lyr.styles.first
=> RGeoServer::Style: raster 
> sld.profile
=> {"name"=>"raster", "sld_version"=>"1.0.0", "filename"=>"raster.sld", "sld"=>{"sld_name"=>"raster", "sld_title"=>"Default Raster"}}

A full sample script creating coverage stores in a small cluster:

require 'rgeoserver'

layers = {
  'south_america_1787' => {
    'url' => 'file:///geo_data/rumsey/g0411047.tif',
    'description' => "Map of South America by D'Anville",
    'type' => 'GeoTIFF'
   },
  'city_of_san_francisco_1859' => {
    'url' => 'file:///geo_data/rumsey/g1030000alpha.tif',
    'description' => 'Map of San Francisco by the U.S. Coast Survey, with detail of the unsettled lands',
    'type' => 'GeoTIFF'
  }
}

(1..7).each do |cat_id|
  cat = RGeoServer::Catalog.new :user=>'admin', :url => "http://geoserver-app#{cat_id}/rest", :password => "osgeo!"
  ws = cat.get_default_workspace
  cat.list(RGeoServer::CoverageStore, layers.keys, :workspace => ws) do |cs|
    cs.url = layers[cs.name]['url']
    cs.data_type = layers[cs.name]['type']
    cs.enabled = 'true'
    cs.save
    # Create the corresponding layer
    c = RGeoServer::Coverage.new cat, :workspace => ws, :coverage_store => cs, :name => cs.name 
    c.title = cs_name.gsub('_',' ').titleize
    c.abstract = layers[cs.name]['description']
    c.save
    # Seed the tile cache
    l = RGeoServer::Layer.new cat, :name => cs.name
    l.seed :issue, {
      :srs => {
        :number => 4326
      },
      :zoomStart => 1,
      :zoomStop => 10,
      :format => 'image/png',
      :threadCount => 1
    }
  end
end

Testing

We use jettywrapper to wrap a test instance of GeoServer. In theory, you should be able to point to any other local installation. Suppose that you download the binary stable version 2.1.3 binary from here, then unzip it under say, /tmp/geoserver-2.1.3. The integration tests are executed as follows:

$ rake integration['/tmp/geoserver-2.1.3','8080','-DGEOSERVER_DATA_DIR=data_dir']

If you have the test instance running already on port 8080, you can run the tests simply with:

$ rake

To generate the documentation run:

$ rake yard

To enter into an irb console with all classess loaded:

$ rake console

Logging

For now we use RestClient’s base logger. It can be enabled by setting:

RestClient.log = '/tmp/restclient.log'

or set an environment variable, for example:

$ RESTCLIENT_LOG=stdout ruby ingest_layer.rb 
RestClient.get "http://localhost:8080/geoserver/rest/workspaces/cite.xml", "Accept"=>"application/xml", "Accept-Encoding"=>"gzip, deflate", "Content-Type"=>"application/xml"
# => 200 OK | application/xml 662 bytes
RestClient.get "http://localhost:8080/geoserver/rest/workspaces/cite/coveragestores/city_of_san_francisco_1859.xml", "Accept"=>"application/xml", "Accept-Encoding"=>"gzip, deflate", "Content-Type"=>"application/xml"
# => 404 NotFound | text/plain 73 bytes
RestClient.post "http://localhost:8080/geoserver/rest/workspaces/cite/coveragestores", "<?xml version=\"1.0\"?>\n<coverageStore>\n  <name>city_of_san_francisco_1859</name>\n  <workspace>\n    <name>cite</name>\n  </workspace>\n  <enabled>true</enabled>\n  <type>GeoTIFF</type>\n  <description>Map of San Francisco by the U.S. Coast Survey, with detail of the unsettled lands</description>\n  <url>file:///geo_data/rumsey/g1030000alpha.tif</url>\n</coverageStore>\n", "Accept"=>"application/xml", "Accept-Encoding"=>"gzip, deflate", "Content-Length"=>"363", "Content-Type"=>"application/xml"
# => 201 Created |  0 bytes

Related Resources

Release History

  • v0.5 - Initial alpha release

TODO

  • Complete data stores and coverages functionality and data upload.

  • Complete updating data in objects. On failure, objects should roll back.

  • Complete documentation.

  • Complete test coverage:

    • Break down testing into separate specs per class.

    • Add more flexibility for integration tests with embedded Jetty and other containers.

    • Add ability to perform integration tests in a CI server.

  • Provide more examples:

    • Customize configuration.

    • Connect under SSL.

    • Batch processing.

  • Migrate base HTTP client to Faraday?

  • Curlify operations: To provide optional log/output of the curl command that would produce the same

result as the ResourceInfo#save method.

Contributing with Patches and Pull requests checklist

  • Check out the latest master to make sure the feature hasn’t been implemented or the bug hasn’t been fixed yet

  • Check out the issue tracker to make sure someone already hasn’t requested it and/or contributed it

  • Fork the project

  • Start a feature/bugfix branch

  • Commit and push until you are happy with your contribution

  • Make sure to add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

Acknowledgements

Inspired on the Rubydora gem. Followed somewhat closely to gsconfig.py

Contributors

This package is supported and maintained by Stanford University Libraries.

Bess Sadler <bess@stanford.edu>

License

Copyright © 2012 Stanford University

Author: Renzo Sanchez-Silva <renzo.sanchez.silva@gmail.com>.

Licensed under the Apache License, Version 2.0

About

RGeoServer is a Ruby client for the GeoServer RESTful Configuration interface.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages