Simple client for publishing Shapefiles and GeoTIFFs to Geoserver.
Add this line to your application's Gemfile:
gem 'geoserver-publish'
And then execute:
$ bundle
Or install it yourself as:
$ gem install geoserver-publish
Geoserver::Publish.geotiff(workspace_name: "public", file_path: "file:///path/on/geoserver/raster.tif", id: "1234", title: "GeoTiff Title")
Because of a limitation in GeoServer, the layer id must be the same name as the shapefile without the extenstion. For example, if the file name is 1234.shp
, the id must be 1234
.
Geoserver::Publish.shapefile(workspace_name: "public", file_path: "file:///path/on/geoserver/1234.shp", id: "1234", title: "Shapefile Title")
Geoserver::Publish.delete_geotiff(workspace_name: "public", id: "1234")
Geoserver::Publish.delete_shapefile(workspace_name: "public", id: "1234")
For users wanting to publish styles, this can be done using the GeoServer styles API.
Geoserver::Publish::Style.new.create(style_name: "raster_layer", filename: "raster_layer.sld")
sld = File.read("./spec/fixtures/files/payload/raster_layer.sld")
Geoserver::Publish::Style.new.update(style_name: "raster_layer", filename: "raster_layer.sld", payload: sld)
The GeoWebCache REST API can also be used. Note: there is usually a different url that is used.
c = Geoserver::Publish::Connection.new({"url" => "http://localhost:8080/geoserver/gwc/rest", "user"=>"admin",
"password"=>"geoserver"})
Geoserver::Publish::Geowebcache.new(c).masstruncate(layer_name: 'nurc:Pk50095')
To use the default GeoServer connection parameters, no further configuration is needed. These are useful for testing and development against a local GeoServer instance.
- url: http://localhost:8080/geoserver/rest
- user: admin
- password: geoserver
GeoServer Connection parameters can be set using environment variables.
- GEOSERVER_URL
- GEOSERVER_USER
- GEOSERVER_PASSWORD
A connection object can be instantiated with a parameter hash and passed into publishing methods.
new_conn = Geoserver::Publish::Connection.new({"url"=> "http://mygeoserver.com:8181/geoserver/rest", "user" => "admin_user", "password" => "supersecret"})
Geoserver::Publish.geotiff(connection: new_conn, workspace_name: "public", file_path: "file:///path/on/geoserver/raster.tif", id: "1234", title: "GeoTiff Title")
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
Bug reports and pull requests are welcome on GitHub at https://github.com/samvera-labs/geoserver-publish.