[GIS] How to configure a available feature types in GeoServer using python gsconfig

geoservergeoserver-rest-apipublishingpython

How to configure a available feature types in GeoServer using python gsconfig?
I have created work space and data store using gsconfig. Now , how i can configure available layers in a exist data store (data store other than postgis table, data stores like directory of shape files)?

I have tried: as follow

from geoserver.layer import Layer
from geoserver.resource import FeatureType, Coverage
from geoserver.store import coveragestore_from_index, datastore_from_index, \
    wmsstore_from_index, UnsavedDataStore, \
    UnsavedCoverageStore, UnsavedWmsStore
from geoserver.style import Style
from geoserver.support import prepare_upload_bundle, url, _decode_list, _decode_dict
from geoserver.layergroup import LayerGroup, UnsavedLayerGroup
from geoserver.workspace import workspace_from_index, Workspace

def publish_featuretype(self, name, store, native_crs, srs=None):
        '''Publish a featuretype from data in an existing store'''
        # @todo native_srs doesn't seem to get detected, even when in the DB
        # metadata (at least for postgis in geometry_columns) and then there
        # will be a misconfigured layer
        if native_crs is None: raise ValueError("must specify native_crs")
        srs = srs or native_crs
        feature_type = FeatureType(self, store.workspace, store, name)
        # because name is the in FeatureType base class, work around that
        # and hack in these others that don't have xml properties
        feature_type.dirty['name'] = name
        feature_type.dirty['srs'] = srs
        feature_type.dirty['nativeCRS'] = native_crs
        feature_type.enabled = True
        feature_type.title = name
        headers = {
            "Content-type": "application/xml",
            "Accept": "application/xml"
        }
        headers, response = self.http.request(store.resource_url, "POST", feature_type.message(), headers)
        feature_type.fetch()
        return feature_type
publish_featuretype("self" name="Layername", store="store_name", native_crs="4326", srs="EPSG:4326")

I got the error as follow

AttributeError: 'str' objetcs has no attribute 'workspace'

code has taken from : http://pydoc.net/Python/GeobricksGeoserverManager/0.1.0/geobricks_geoserver_manager.core.geoserver_manager_core/

Best Answer

You say you're getting code from that site, but you're creating new code with errors in it.

The error message you're getting here is 'AttributeError: 'str' objetcs has no attribute 'workspace''

This is because you pass in an argument to the method you've created:

publish_featuretype("self" name="Layername", store="store_name", native_crs="4326", srs="EPSG:4326")

Here, you've passed in 'store-"store_name"' which assigns the store variable as a string.

Then, in the method, you do this:

feature_type = FeatureType(self, store.workspace, store, name)

where you try to access the attribute 'workspace' on the 'string' object. And as the error message says, the string object doesn't have an attribute called 'workspace'.

Related Question