4

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))
5

That is one of the bugs I proposed a fix for a while back - You might be better off using my fork. However, given the lack of progress being made fixing things on any of the forks out there it might be best to consider the project essentially dead.

1
  • You nailed it! thanks for the fork. I can now publish postgis layers, not requiring anything beyond the example code. For anyone else finding this, I replaced the original file '..\Python37x64\Lib\site-packages\geoserver\catalog.py' with Ian's version. I just hope my next step of saving and setting symbology will be nice and easy....
    – GIS_py
    Apr 22 at 13:48

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.