gicait / geoserver-rest

Python library for management of geospatial data in GeoServer.
https://geoserver-rest.readthedocs.io
MIT License
197 stars 79 forks source link

create_coveragestyle maybe is not work well #18

Closed polzader closed 3 years ago

polzader commented 3 years ago

I'm using the function to create dynamic style:

` workspace="general" image="../data/NDVI_20201104.tif" style="ndvi" color_ramp ='RdYlGn'

geo.create_coveragestyle(raster_path=image, style_name=style, workspace=workspace, color_ramp=color_ramp, overwrite=True)

` But I getting error response: Invalid style: null

  <h1>Estado HTTP 400 – Bad Request</h1>
  <hr class="line" />
  <p><b>Tipo</b> Informe de estado</p>
  <p><b>mensaje</b> Invalid style:null</p>
  <p><b>descripción</b> El requerimiento enviado por el cliente era sintácticamente incorrecto.</p>
  <hr class="line" />
  <h3>

I noticed that, if the style exists in geoserver, then the function works fine. Otherwise, it is not able to upload the style file. However, the function says:

def create_coveragestyle(self, raster_path, style_name=None, workspace=None, color_ramp='RdYlGn_r', cmap_type='ramp', overwrite=False): ...

create the xml file for associated style

       ...
        # upload the style file  <------ (this block upload style file???)
        c.setopt(c.URL, '{0}/rest/workspaces/{1}/styles/{2}'.format(
            self.service_url, workspace, style_name))
        c.setopt(pycurl.HTTPHEADER, [
                 "Content-type:application/vnd.ogc.sld+xml"])
        c.setopt(pycurl.READFUNCTION, FileReader(
            open('style.sld', 'rb')).read_callback)
        c.setopt(pycurl.INFILESIZE, os.path.getsize('style.sld'))
        if overwrite:
            c.setopt(pycurl.PUT, 1)
        else:
            c.setopt(pycurl.POST, 1)
        c.setopt(pycurl.UPLOAD, 1)
        c.perform()
        c.close()

I understand that you upload the style file to the geoserver.

iamtekson commented 3 years ago

I think the problem with the overwrite option. I saw the overwrite=True, in your function call. If the style file is not already available in geoserver, you don't have to pass the overwrite parameter.

polzader commented 3 years ago

Thanks. I resolved the problem: remove the parameter overwrite=Trueand it's work well.