[Geoserver-users] Refresh a Geoserver PostGIS layer after adding a new column to the data source (postgis table)

I am unable to update the layer configuration of a PostGIS geoserver layer.

  1. I am adding a new column to the existing and published PostGIS table in the first step.

  2. However, the geoserver automatically doesn’t reflect the changes made to the layer. We need to manually do it through the geoserver admin interface using the “Reload feature type” option (image below) or automate it through the geoserver rest API.
    gs_question.png

  3. The Python code for updating layer configuration through rest-API is given below.


session = requests.Session()
session.auth = (username, password)
layer_url_json = f"{geoserver_url_dL}/workspaces/{workspace_dL}/datastores/{store}/featuretypes/{layer_name}.json"
response1 = session.get(layer_url_json)
layer_info = response1.json()
#print(layer_info)
new_column = {
“name”: “type12”,
“type”: “Boolean”, # Set the data type for the new column
“nillable”:True,
“minOccurs”: 0, # Optional: Minimum occurrences
“maxOccurs”: 1 # Optional: Maximum occurrences
}
layer_info[‘featureType’][‘attributes’][‘attribute’].append(new_column)
response2 = session.put(layer_url_json, headers={‘Content-type’: ‘application/json’},


The above code was working perfectly in geoserver-2.20.0 and the changes to layer configuration are being reflected.

However, I am getting a 500 error for response2 with the text “The CQL source expression for attribute type12 refers to attributes unavailable in the data source: [type12]” in later versions of geoserver like geoserver-2.23, 2.24, 2.25-SNAPSHOT

I tried to verify the PostGIS table and the column is already added to the table, and the rest-api interactions with geoserver 2.23-SNAPSHOT are working fine as i was able to retrieve “layer_info” and also successfully tested adding a new workspace using rest-api in this version.

Unfortunately, I can’t fix this error. Is this my code error specific to the version of the geoserver or is it a geoserver bug?

···

Thanks and Regards,
Sriharsha Yegireddi

The format may of changed a bit as the ability to add CQL expressions (and generate columns on the fly) was added in that time frame.

There is an options to refresh the column definition from the database table that may be more suitable than manually adding a column.

···


Jody Garnett

Thanks and Regards,
Sriharsha Yegireddi

Hi Jody,

Thanks for the response. I have tried different methods and nothing works. The only workaround I figured out is that we can set the layer’s “enabled=false” and set it to true every time a column is altered or a new column is created.

However, geoserver is a part of my cloud saas platform. A user can upload vector data and the data is saved into a PostGIS table and then published to geoserver as a layer. The user can share this uploaded data/layer to multiple other users. All the shared users with edit permission can create, delete, duplicate, and rename the columns of this existing layer.

Altering the layers “enabled” every time a user performs column operations might affect the performance.

Please let me know if you have any suggestions.

Regards

gs_question.png

···


Jody Garnett

Thanks and Regards,
Sriharsha Yegireddi

Hi,

It is an uncommon solution to let users change the schema of the tables freely. I do not say that it is wrong, but users adding data into tables which are predefined by the administrators is the traditional way and therefore better supported.

Could the OpenStreetMaps data model suit for your use case? That does not have much attribute schema, just tags and values.

-Jukka Rahkonen-

gs_question.png

···

Lähettäjä: Harsha Yegireddi <harsha6772@…84…>
Lähetetty: perjantai 3. marraskuuta 2023 8.59
Vastaanottaja: Jody Garnett <jody.garnett@…84…>
Kopio: geoserver-users@lists.sourceforge.net
Aihe: Re: [Geoserver-users] Refresh a Geoserver PostGIS layer after adding a new column to the data source (postgis table)

Hi Jody,

Thanks for the response. I have tried different methods and nothing works. The only workaround I figured out is that we can set the layer’s “enabled=false” and set it to true every time a column is altered or a new column is created.

However, geoserver is a part of my cloud saas platform. A user can upload vector data and the data is saved into a PostGIS table and then published to geoserver as a layer. The user can share this uploaded data/layer to multiple other users. All the shared users with edit permission can create, delete, duplicate, and rename the columns of this existing layer.

Altering the layers “enabled” every time a user performs column operations might affect the performance.

Please let me know if you have any suggestions.

Regards

On Thu, Nov 2, 2023 at 10:14 PM Jody Garnett <jody.garnett@…84…> wrote:

The format may of changed a bit as the ability to add CQL expressions (and generate columns on the fly) was added in that time frame.

There is an options to refresh the column definition from the database table that may be more suitable than manually adding a column.

Jody Garnett

On Nov 2, 2023 at 6:10:12 AM, Harsha Yegireddi <harsha6772@…84…> wrote:

I am unable to update the layer configuration of a PostGIS geoserver layer.

  1. I am adding a new column to the existing and published PostGIS table in the first step.

  2. However, the geoserver automatically doesn’t reflect the changes made to the layer. We need to manually do it through the geoserver admin interface using the “Reload feature type” option (image below) or automate it through the geoserver rest API.

  1. The Python code for updating layer configuration through rest-API is given below.

session = requests.Session()


session.auth = (username, password)


layer_url_json = f"{geoserver_url_dL}/workspaces/{workspace_dL}/datastores/{store}/featuretypes/{layer_name}.json"


response1 = session.get(layer_url_json)


layer_info = response1.json()


#print(layer_info)


new_column = {


"name": "type12",

"type": "Boolean",  # Set the data type for the new column

"nillable":True,

"minOccurs": 0,  # Optional: Minimum occurrences

"maxOccurs": 1  # Optional: Maximum occurrences

}


layer_info[‘featureType’][‘attributes’][‘attribute’].append(new_column)


response2 = session.put(layer_url_json, headers={‘Content-type’: ‘application/json’},


The above code was working perfectly in geoserver-2.20.0 and the changes to layer configuration are being reflected.

However, I am getting a 500 error for response2 with the text “The CQL source expression for attribute type12 refers to attributes unavailable in the data source: [type12]” in later versions of geoserver like geoserver-2.23, 2.24, 2.25-SNAPSHOT

I tried to verify the PostGIS table and the column is already added to the table, and the rest-api interactions with geoserver 2.23-SNAPSHOT are working fine as i was able to retrieve “layer_info” and also successfully tested adding a new workspace using rest-api in this version.

Unfortunately, I can’t fix this error. Is this my code error specific to the version of the geoserver or is it a geoserver bug?

Thanks and Regards,

Sriharsha Yegireddi


Geoserver-users mailing list

Please make sure you read the following two resources before posting to this list:

If you want to request a feature or an improvement, also see this: https://github.com/geoserver/geoserver/wiki/Successfully-requesting-and-integrating-new-features-and-improvements-in-GeoServer

Geoserver-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users

I just want to be clear what you have tried (I cannot tell from your email when you say everything).

Did you try the reset method (some of these are recent additions to the rest api).

/workspaces/{workspaceName}/datastores/{storeName}/featuretypes/{featureTypeName}/reset

Did you retry post with recalculate=attribute parameter?

/workspaces/{workspaceName}/datastores/{storeName}/featuretypes/{featureTypeName}

The reset option was added to avoid people disabling and enabling their datastore connection, or even worse deleting and adding again.

I hope reset works for you, please let us know how it goes.

Jody

···


Jody Garnett

Thanks and Regards,
Sriharsha Yegireddi