I created "by hand" (using GeoServer HTML configuration interface) a layer based on the following SQL view:

SELECT p1.suid, p1.id, p1.geometry, p1.classname, p2.date, COALESCE(p2.percentage, 0) - COALESCE(p1.percentage, 0) AS percentage
FROM get_300km_percentages('%classname%', '%enddate%'::date, '%prevdate%'::date) p1
LEFT OUTER JOIN get_300km_percentages('%classname%', '%startdate%'::date, '%enddate%'::date) p2
ON p1.suid = p2.suid
    percentage %order%

In the picture, we can see that all parameters, including %order% and %limit%" are ok. They were correctly guessed by the API.

enter image description here

How can I create a layer like that using geo.Geoserver or another Python-based GeoServer config library?

  • Tks, ThomasG77. May 17, 2021 at 21:33

1 Answer 1


You could do it without a dedicated GeoServer library, only using GeoServer REST in combination with requests library and since you already said you created the layer "by hand", then this approach should work for you.

1. Find the JSON or XML definition of your layer (previously created in GeoServer UI) as instructed in the top answer here:

Creating Layer in GeoServer using REST

The url with layer definition in json may look like this on local GeoServer:


What you get from this is what you should post as a body of the request later in order to create the layer via REST.

2. Make the proper request

Python example:

    import requests

    session = requests.Session()
    session.auth = ('user', 'pass') #admin - geoserver?
    url = '<geoserver_url>/rest/workspaces/<workspace>/datastores/<store>/featuretypes/'
    # 'http://localhost:8080/geoserver/rest/workspaces/leo/datastores/localpai/featuretypes/'

    test = session.get(url=url)
    #check if the url works - you should get a list of featuretypes for this workspace and datastore
    # print(test.text)

    headers = {'Content-Type': 'application/json'}
    #JSON definition of the layer obtained in step 1.
    resp = session.post(url=url, headers=headers, data=data)
  • Thank you, Leon. Jul 19, 2021 at 10:29
  • Did the solution help you? Jul 19, 2021 at 10:42
  • Yes, it helped. Jul 20, 2021 at 14:52
  • Please mark the answer as accepted then :) Jul 21, 2021 at 12:43
  • Tks! How should I do that? Jul 22, 2021 at 13:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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