I can't seem to publish a geoserver layer from our postgis database.
When running a basic script it trips on this line:
ft = cat.publish_featuretype(name=tableP, store=ds, native_crs='EPSG:{}'.format(tableEpsg),
srs='EPSG:{}'.format(tableEpsg), jdbc_virtual_table=None, native_bbox=None)
I get an error below.
Store: <geoserver.store.DataStore object at 0x000001FA23C7EE08>
Traceback (most recent call last):
File "C:\GIS\Tools\06. QGIS\Geoserver\gs Test (2).py", line 132, in <module>
ft = cat.publish_featuretype(name=tableP, store=ds, native_crs='EPSG:{}'.format(tableEpsg), srs='EPSG:{}'.format(tableEpsg), jdbc_virtual_table=None, native_bbox=None) #
File "C:\PythonEnvironments\Python37x64\lib\site-packages\geoserver\catalog.py", line 716, in publish_featuretype
headers=headers, params=params)
UnboundLocalError: local variable 'params' referenced before assignment
I don't see 'params' as a parameter of the 'cat.publish_featuretype' method but to be honest I'm struggling to find detailed documentation. So why does that come up, or what is the real error?
I read on a github page it could be related to the bbox, so I added that the value below as the 'native_bbox': {'minx': 671198.619943575, 'maxx': 676473.914171803, 'miny': 2732715.24096015, 'maxy': 2736892.48917506, 'crs': 'EPSG:32638'} But perhaps that was just a suggestion. I don't really know what the syntax of the 'native_bbox' should be. I also tried minx,maxx,miny,maxy,crs - same result.
All the examples online don't require you to put in the native_bbox. Perhaps there is another parameter I need to specify in 'cat.publish_featuretype':
It's worth mentioning that I can successfully create a data store using the code, so it does connect ok and authenticate.
Here is the base code:
from geoserver.catalog import Catalog
geoservP = 'GeoserverURL/geoserver/rest/'
username='username' # changed
password='password' # changed
wspaceP = "ProjectName"
storeP = "StoreName"
databaseP = "databaseName"
dbTypeP = "postgres"
hostP = "our.sql.server"
userP = "dbuser"
passP = "dbpass"
schemaP = "o7_environment"
tableP = "parkpoly_omr_dsgn"
tableEpsg = 32638
# Create Catalog Object
cat = Catalog(geoservP, username, password)
print("Catalog: {}".format(cat))
# Create New Datastore Object
ds = cat.create_datastore(storeP,wspaceP)
ds.connection_parameters.update(host=hostP, port='5432', database=databaseP, user=userP, passwd=passP, dbtype='postgis', schema=schemaP)
cat.save(ds)
print("Saved new Store: {}".format(storeP))
# if already created just open the existing one as a store object
##ds = cat.get_store(storeP)
##print("Store: {}".format(ds))
ft = cat.publish_featuretype(name=tableP, store=ds, native_crs='EPSG:{}'.format(tableEpsg), srs='EPSG:{}'.format(tableEpsg), jdbc_virtual_table=None, native_bbox=None)
cat.save(ft)
print("Published Table: {}".format(tableP))