cgre-aachen / gemgis

Spatial data processing for geomodeling
https://gemgis.readthedocs.io/en/latest
GNU Lesser General Public License v3.0
257 stars 41 forks source link

[BUG] WMS version 1.3 #332

Open spasquet opened 1 month ago

spasquet commented 1 month ago

Hi,

there is a bug when using WMS 1.3 in load_as_array with the following code :

import gemgis as gg

url = 'https://data.geopf.fr/wms-r?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap'
layer='ORTHOIMAGERY.ORTHOPHOTOS'
wms_aerial_array = gg.web.load_as_array(url=url, layer=layer, style='normal', crs='EPSG:2154', 
                             bbox=[966860,967275, 6446505, 6446800], 
                             size=[600, 600], filetype='image/png',
                             save_image=False)

I get the following error :

File "/home/pasquet/Documents/Python/developments/GeoVizPy/geovizpy.py", line 129, in <module>
    wms_aerial_array = gg.web.load_as_array(url=url, layer=layer, style='normal', crs=crs, 
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/trame_env/lib/python3.12/site-packages/gemgis/web.py", line 468, in load_as_array
    wms_map = load_as_map(url=url,
              ^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/trame_env/lib/python3.12/site-packages/gemgis/web.py", line 267, in load_as_map
    wms = load_wms(url)
          ^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/trame_env/lib/python3.12/site-packages/gemgis/web.py", line 91, in load_wms
    wms = owslib.wms.WebMapService(url)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/trame_env/lib/python3.12/site-packages/owslib/wms.py", line 50, in WebMapService
    return wms111.WebMapService_1_1_1(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/trame_env/lib/python3.12/site-packages/owslib/map/wms111.py", line 75, in __init__
    self._capabilities = reader.read(self.url, timeout=self.timeout)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/trame_env/lib/python3.12/site-packages/owslib/map/common.py", line 65, in read
    u = openURL(spliturl[0], spliturl[1], method='Get',
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/trame_env/lib/python3.12/site-packages/owslib/util.py", line 212, in openURL
    raise ServiceException(req.text)
owslib.util.ServiceException: <ServiceExceptionReport xmlns="http://www.opengis.net/ogc">
<ServiceException code="InvalidParameterValue" >
  Valeur du parametre VERSION invalide (1.3.0 disponible seulement))
</ServiceException>
</ServiceExceptionReport>

I found a workaround by modifying line 91 of gemgis/web.py, but there is probably a better way to generalize it. wms = owslib.wms.WebMapService(url,version='1.3.0')

I'm using gemgis 1.1.8

AlexanderJuestel commented 1 month ago

@spasquet Thanks for pointing that out. I will put that on my list for the next release which I started working on now

AlexanderJuestel commented 1 month ago

@spasquet, I added a version argument to the code in https://github.com/cgre-aachen/gemgis/commit/6676046da307058539460b48d0c8eb0b70a453ff which should fix the issue. I can open your image without a problem.

image

spasquet commented 1 month ago

Thanks @AlexanderJuestel ! Do you have an estimate of when the next release will be out ?

AlexanderJuestel commented 1 month ago

Since I have not been active lately due to completing (successfully) my PhD, I was planning on including a lot of fixes in the next release as GemGIS is also up for being accepted in the PyOpenSci community and I have some stuff to fix there. This may take a month or so. However, I have already pushed the changes to the gemgis_dev branch. Feel free to clone that one :)

spasquet commented 1 month ago

Congrats on the PhD ! And thanks for the feedback.