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:
You have basic knowledge of
You have uploaded your layers in
You have created a workspace in
You have created a store in GeoServer
You are using Linux OS
Kindly check my previous tutorials on the above topics
PostGIS and GeoServer
PostGIS and GeoServer
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
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”
This file contains the workspace and datastore name.
Executing the script.
Make the main_script executable by typing this in the terminal:
Execute the script by typing
If it is successful you will get '200 success' message.
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.
of any issues feel free to email me at email@example.com
or send me a text in WhatsApp at +254 727 597 235