0

I am trying to programmatically edit the dimension variable in GeoServer for 200+ NetCDF's.

This is how I am trying it:

from geoserver.catalog import Catalog
cat = Catalog("http://localhost:8080/geoserver/rest/", username=conf_dict['GEOSERVER_USER'], password=conf_dict['GEOSERVER_PASS'])
from geoserver.support import DimensionInfo
coverage = cat.get_resource_by_url(conf_dict['GEOSERVER_HOST'] + "/rest/workspaces/daressalaam/coveragestores/201903030300_grid_FloodForecast_V2/coverages/201903030300_grid_FloodForecast_V2.xml")
timeInfo = DimensionInfo("time", "true", "LIST", None, "ISO8601", None)
coverage.metadata = ({'dirName':'201903030300_grid_FloodForecast_V2', 'time': timeInfo})
cat.save(coverage)

I've copied the above code from here and here

yet when I run the code, I get an attribute error message

AttributeError: 'DimensionInfo' object has no attribute 'unitSymbol'

What am I doing wrong? How can I programmatically edit the time variable for all my NetCDFs in GeoServer?

  • looks like gsconfig is out of date or you are using an old version – Ian Turton Sep 11 at 8:22
  • I just checked with pip, I have version: gsconfig-py3==1.0.7. That is the latest version. – J.A.Cado Sep 11 at 8:25
  • doesn't mean it has kept up with GeoServer – Ian Turton Sep 11 at 8:35
  • So what are you saying, that gsconfig and geoserver are out of sync? – J.A.Cado Sep 11 at 8:36
  • seems like it - you need to look at the XML being sent and what GeoServer expects (unitSymbol) – Ian Turton Sep 11 at 8:41
0

so eventually, I skipped using the python package gsconfig, and applied the an xml model as is shown in this link.

However, I made some alterations:

  • I used it for a NetCDF, not a shapefile.
  • PUT request instead of POST.
  • presentation value LIST instead of CONTINUOUS_INTERVAL, and
  • Default value of NONE instead of MAXIMUM

.

   url = """<coverage>
                <title>{new_title_layer}</title>
                <metadata>
                    <entry key="time">
                    <dimensionInfo>
                    <enabled>true</enabled>
                    <attribute>time_attribute</attribute>
                    <presentation>LIST</presentation>
                    <units>ISO8601</units>
                    <defaultValue>NONE</defaultValue>
                    </dimensionInfo>
                    </entry>
                </metadata>
                <enabled>true</enabled>
            </coverage>""".format(new_title_layer=new_title_layer)

    r_change_name = requests.put("http://localhost:8080/geoserver/rest/workspaces/"+ workspace  + "/coveragestores/" + coveragestore +  "/coverages/" + coveragestore,
                                 auth=HTTPBasicAuth("admin","geoserver",
                                 data=url,
                                 headers={'content-type': 'text/xml'})

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.