2

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/

  • Can you be more specific? What values are you using for store_name, workspace_name and layer_name. I/O error could imply that the file can't be found. – Alex Leith Apr 20 '15 at 4:32
  • I had already existed workspace and store (directory of shapefiles). Now I added shapefiles in the store folder which means they are available in GeoServer but not configured, my question is how to configure the available shapefiles or layers in GeoServer using gsconfig python (not curl).. – Satya Chandra Apr 20 '15 at 4:58
  • Yep, so add more info to your code excerpt above. I can't find add_data_to_store in the doco, either. Where have you got that code example from? – Alex Leith Apr 20 '15 at 6:36
  • I have tried as follow: gis.stackexchange.com/questions/84031/… – Satya Chandra Apr 20 '15 at 9:40
  • You'd better post your whole code. That post you provided doesn't do anything with the 'add_data_to_store' method. They do something like: 'ft = cat.publish_featuretype('newLayerName', ds, 'EPSG:4326', srs='EPSG:4326')' – Alex Leith Apr 20 '15 at 22:52
3

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'.

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.