Publishing multiple layers of GeoServer using script

Publishing multiple layers of GeoServer is a repetitive and tiresome task. I came across this tweet https://twitter.com/iamtekson/status/1195371425021886464 and i thought of sharing a script that i have always used to automate this repetitive process.

This tutorial assumes that:

  1. You have basic knowledge of GeoServer
  2. You have uploaded your layers in PostGIS
  3. You have created a workspace in GeoServer
  4. You have created a store in GeoServer
  5. You are using Linux OS

Kindly check my previous tutorials on the above topics

PostGIS

GeoServer

PostGIS and GeoServer (YouTube Video)

PostGIS and GeoServer (PDF Tutorial)

Lets go straight into the theme of this tutorial

I have provided a link to a zipped file (https://drive.google.com/drive/folders/1NuQjlKTG5g7gDaIxwx-uJ74X1RJCyjGA?usp=sharing) containing the script. It contains a main file called main_script, url.txt, feature_list.txt and a folder which contains text files containing publishing information for each layer. In this case I want to publish only 5 layers.

Explanation of contents of the files

main_script

This is a batch file that will be executed in the command line in linux. A batch file is a script file in DOS, OS/2 and Microsoft Windows. It consists of a series of commands to be executed by the command-line interpreter, stored in a plain text file.

This batch file logs in to geoserver through a command line tool called cURL. Thereafter it checks at a folder called features which contains all the information for layers to be published. It then publishes the layers using the workspace and store provided in the url.txt.

The feautures folder

Each text file herein represents publishing information for each layer. To get this information, you can publish one layer manually in geoserver and access the details by typing this in the browser:

http://localhost/geoserver/rest/workspaces/workspce_name/datastores/datastore_name/featuretypes” . Click on the feature that you have published to see the publishing information e.g. the Coordinate system”

Url.txt

This file contains the workspace and datastore name.

Executing the script.

1. Make the main_script executable by typing this in the terminal:

chmod +x main_script

2. Execute the script by typing

./main_script

If it is successful you will get '200 success' message.

If you get any error countercheck to ensure that all the details in the files are correct e.g the geoserver username, password, the layer names provided exist in the database etc.

In case of any issues feel free to email me at benardonyango16@gmail.com or send me a text in WhatsApp at +254 727 597 235

Add a Comment

Your email address will not be published. Required fields are marked *