Skip to main content

Package for GeoServer rest API

Project description

Installation

The geoserver-rest package is useful for the management for geospatial data in GeoServer. The package is usefull for the creating, updating and deleting geoserver workspaces, stores, layers, and style files. For installation of this package following package should be installed first,

Dependencies
  1. Gdal
  2. Pycurl

The geoserver-rest package can be installed with pip, if all the dependencies are installed already

pip install geoserver-rest

How to use

This library is used for creating workspace, coveragestore, featurestore, styles. Some of the examples are shown below.

Initialize the library

This step is used to initialize the library. It takes parameters as geoserver url, username, password.

from geo.Geoserver import Geoserver
geo = Geoserver('http://localhost:8080/geoserver', username='admin', password='geoserver')
Create workspace
geo.create_workspace(workspace='demo')
Create coveragestore

It is helpful for publishing the raster data to the geoserver. Here if you didn't to pass the lyr_name parameter, it will take the raster file name as the layer name.

geo.create_coveragestore(lyr_name='layer1' path=r'path\to\raster\file.tif', workspace='demo')

If the layername already exist in geoserver you can pass another parameter overwrite=True,

geo.create_coveragestore(lyr_name='layer1' path=r'path\to\raster\file.tif', workspace='demo' overwrite=True)
Create featurestore and publish layer

It is use for connecting the PostGIS with geoserver and publish this as a layer. It is only useful for vector data. The postgres connection parameters should be pass in the parameters. For publish the PostGIS tables, the pg_table parameter represent the table name in postgres

geo.create_featurestore(store_name='geo_data', workspace='demo', db='postgres', host='localhost', pg_user='postgres', pg_password='admin')
geo.publish_featurestore(workspace='demo', store_name='geo_data', pg_table='geodata_table_name')
Upload style and publish it

It is use for uploading SLD files and publish style. If the style name already exist, you can pass the parameter overwrite=True to overwrite it. The name of the style will be name of the uploaded file name.

geo.upload_style(path=r'path\to\sld\file.sld', workspace='demo')
geo.publish_style(layer_name='geoserver_layer_name', style_name='sld_file_name', workspace='demo')
Create Coverage Style based on the raster (Dynamic) and apply style

It is use to create the style file for raster data. You can get the color_ramp name from matplotlib colormaps. By default color_ramp='RdYlGn' (red to green color ramp).

#Style name will be the same as the raster_file_name
geo.create_coveragestyle(raster_path=r'path\to\raster\file.tiff', style_name='style_1', workspace='demo', color_ramp='RdYiGn')
geo.publish_style(layer_name='geoserver_layer_name', style_name='raster_file_name', workspace='demo')

For generate the style for classified raster you can pass the another parameter called cmap_type='values' as,

geo.create_coveragestyle(raster_path=r'path\to\raster\file.tiff', style_name='style_1', workspace='demo', color_ramp='RdYiGn', cmap_type='values')
Option Type Default Description
style_name string file_name This is optional field. If you didn't pass the style_name parameter, then it will take the raster file name as the default name of style in geoserver
raster_path path None path to the raster file
workspace string None The name of the workspace
color_ramp string RdYlGn The color ramp name. The name of the color ramp can be found here in matplotlib colormaps
cmap_type string ramp By default the continuous style will be generated, If you want to generate the style for classified raster then pass the parameter color_ramp='values'
overwrite boolean False For overwrite the previous style file in geoserver
Create featur style

It is use for creating the style for point, line, polygon dynamically. Currently it supports three different type of feature styles,

  1. Outline featurestyle: For creating the style which have only boundary color not the fill style
  2. Catagorized featurestyle: For creating catagorized dataset
  3. Classified featurestyle: Classify the input data and style it: (For now only support for polygon geometry)
geo.create_outline_featurestyle(style_name='new_style' color="#3579b1" geom_type='polygon', workspace='demo')
geo.create_catagorized_featurestyle(style_name='name_of_style', column_name='name_of_column', column_distinct_values=[1,2,3,4,5,6,7], workspace='demo')
geo.create_classified_featurestyle(style_name='name_of_style' column_name='name_of_column', column_distinct_values=[1,2,3,4,5,6,7], workspace='demo')

Note:

  • The geom_type must be point or line or polygon
  • The color_ramp name can be get from matplotlib colormaps.
The options for creating catagorized/classified featurestyle are as follows,
Option Type Default Description
style_name string None The name of the style file in geoserver
column_name string None The name of the column, based on which the style will be generated
column_distinct_values list/array None The column distinct values based on which the style will be applied/classified
workspace string None The name of the workspace
color_ramp string RdYlGn The color ramp name. The name of the color ramp can be found here in matplotlib colormaps
geom_type string polygon The geometry type, Available options are point, line, polygon .
outline_color color hex value '#3579b1' The outline color of the polygon/line
overwrite boolean False For overwrite the previous style file in geoserver
Some of the delete request examples
# delete workspace 
geo.delete_workspace(workspace='demo')

# delete layer
geo.delete_layer(layer_name='agri_final_proj', workspace='demo')

# delete feature store, i.e. remove postgresql connection
geo.delete_featurestore(featurestore_name='ftry', workspace='demo')

# delete coveragestore, i.e. delete raster store
geo.delete_coveragestore(coveragestore_name='agri_final_proj', workspace='demo')

# delete style file
geo.delete_style(style_name='kamal2', workspace='demo')

Acknowledgements

Created and managed by Tek Bahadur Kshetri for the project Spatial Disaster Support System (SDSS).

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

geoserver-rest-1.0.0.tar.gz (12.2 kB view details)

Uploaded Source

Built Distribution

geoserver_rest-1.0.0-py3-none-any.whl (11.6 kB view details)

Uploaded Python 3

File details

Details for the file geoserver-rest-1.0.0.tar.gz.

File metadata

  • Download URL: geoserver-rest-1.0.0.tar.gz
  • Upload date:
  • Size: 12.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for geoserver-rest-1.0.0.tar.gz
Algorithm Hash digest
SHA256 e44f2962f76e938add974aa136f70a0539429b6be9e24ec04656ff439777f34a
MD5 7c6e85b624366be52b2f0ec65a283d97
BLAKE2b-256 ee78cb68c5911a68f9883e7841c20e38960932b857bf37aaf22071773c82b897

See more details on using hashes here.

File details

Details for the file geoserver_rest-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: geoserver_rest-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 11.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for geoserver_rest-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 835441f48468dc98f615420c61627a2727695b34b4160fd3eee33711aa4d9833
MD5 5e7b112a1b66e9b3208dbd0f049d291f
BLAKE2b-256 453cdfbb367e5fc0ce381567233986e3ebafbe108b82ebd123706b537ceaa8e7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page