1

I have more than 200 layers in my PostGIS database and I want to publish those layers in GeoServer using curl. I've imported one layer using the command below but can't figure out how to upload all layers in one step.

curl -v -u admin:geoserver -XPOST -H "Content-type: text/xml" -d "<featureType><name>testlayer</name></featureType>" http://localhost:8088/geoserver/rest/workspaces/myworkspace/datastores/mystore/featuretypes
1

You can use any programming language eg: Java, Phython etc. Where you can run your command in for loop and change parameter 'name' with your layer name in each iteration.

  • I wanted to do it in a cmd but I managed to do it like u said, Thanks – Anass Ayar Feb 18 at 13:15
3

Example of a simple bash script to create Geoserver layers for all tables of a given Postgresql schema.

The workspace and the store should already exist in Geoserver. In this example I use the workspace name = database name; the store name = schema name; postgresql server = geoserver server. That is why my URL is: http://$pghost/geoserver/rest/workspaces/$pgdb/datastores/$pgschema/featuretypes

#!/bin/bash

pghost='server.com'
pgport=5432
pguser='geobox'
pgpass='******'
pgschema='sigpdm_2015'
pgdb='pdm2017'

table_names=`PGPASSWORD=$pgpass psql -U $pguser -h $pghost -p $pgport -d $pgdb -t -c "SELECT * FROM (select table_name as t from information_schema.tables where table_schema = '$pgschema') as tnames"`

while read -a table_name ; do
    curl -v -u admin:geoserver -XPOST -H "Content-type: text/xml" -d "<featureType><name>$table_name</name><nativeCRS>EPSG:3763</nativeCRS><srs>EPSG:3763</srs><nativeBoundingBox><minx>-33313.0</minx><maxx>-13047.0</maxx><miny>198924.0</miny><maxy>216948.0</maxy><crs>EPSG:3763</crs></nativeBoundingBox></featureType>" http://$pghost/geoserver/rest/workspaces/$pgdb/datastores/$pgschema/featuretypes
done <<< "$table_names"

The <featureType> could be more simpler, but I usually run into problems when layers get new features outside the initial bounding box. So I prefer to create the layers with the larger possible bounding box. I also added the local CRS, instead of a global one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.