gicait / geoserver-rest

Python library for management of geospatial data in GeoServer.
https://geoserver-rest.readthedocs.io
MIT License
197 stars 79 forks source link

Allow publishing a "SQL View" #145

Closed iboates closed 7 months ago

iboates commented 7 months ago

Although it is not very clearly advertised, geoserver allows you to publish "SQL Views", which are actually just layers defined by a query. It seems that this should just be as easy and uploading the SQL embedded into the XML.

I can add this functionality. Would you prefer that I modify the code for publish_featurestore directly, or create a separate function, called something like publish_sqlview?

iboates commented 7 months ago

Sorry, I completely missed that this functionality already exists as publish_featurestore_sqlview

kalkun commented 7 months ago

I get a 500 "Unknown type" from geoserver v2.24.1 using this function:

geo.publish_featurestore_sqlview(
    name = "test-view",
    store_name = "store",
    sql = f"""
      SELECT *
      FROM capturelayer
    """,
    key_column = "cid",
    geom_name = "geom",
    geom_type = "Geometry",
    srid = 3857,
    workspace='test-workspace'
)

I can get it to return 201 if i set the name to a table that already exists 🤔

iboates commented 7 months ago

@kalkun I don't fully understand, what is the table that already exists? test-view or capturelayer?

kalkun commented 7 months ago

Thanks for the quick reply 🙏 I resolved it eventually and im not sure exactly what did it but I still have a name that does not exists prior - so what I described wasnt the cause of it. In any case, I think it wasnt specific to this library.