nansencenter / nansat

Scientist friendly Python toolbox for processing 2D satellite Earth observation data.
http://nansat.readthedocs.io
GNU General Public License v3.0
182 stars 66 forks source link

path too long on windows when opening radarsat2 dataset #465

Open underchemist opened 4 years ago

underchemist commented 4 years ago

Hi,

when opening a radarsat2 dataset on windows the Node.py module throws an error similar to

stat: path too long for Windows
  File "C:\Users\yanns\Miniconda3\envs\nansat\Lib\genericpath.py", line 19, in exists
    os.stat(path)
  File "C:\Users\yanns\Miniconda3\envs\nansat\Lib\site-packages\nansat\node.py", line 307, in create
    if os.path.exists(dom):
  File "C:\Users\yanns\Miniconda3\envs\nansat\Lib\site-packages\nansat\mappers\mapper_radarsat2.py", line 75, in __init__
    rs2_0 = Node.create(productXml)
  File "C:\Users\yanns\Miniconda3\envs\nansat\Lib\site-packages\nansat\nansat.py", line 1143, in _get_mapper
    tmp_vrt = nansatMappers[mappername](self.filename, gdal_dataset, metadata, **kwargs)
  File "C:\Users\yanns\Miniconda3\envs\nansat\Lib\site-packages\nansat\nansat.py", line 160, in __init__
    self.vrt = self._get_mapper(mapper, **kwargs)
  File "C:\Users\yanns\Downloads\nansat-scratch.py", line 3, in <module>
    src = nansat.Nansat('RS2_OK76385_PK678064_DK606753_F2N_20080419_142127_HH_HV_SLC\RS2_OK76385_PK678064_DK606753_F2N_20080419_142127_HH_HV_SLC', mapper='radarsat2')
  File "C:\Users\yanns\Miniconda3\envs\nansat\Lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\yanns\Miniconda3\envs\nansat\Lib\runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "C:\Users\yanns\Miniconda3\envs\nansat\Lib\runpy.py", line 263, in run_path
    pkg_name=pkg_name, script_name=fname)
  File "C:\Users\yanns\Miniconda3\envs\nansat\Lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\yanns\Miniconda3\envs\nansat\Lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)

which seems to be tied to the fact that productXml is a raw xml string and os.path.exists is being called on it. I was able to avoid this by checking adding a check to Node.py:create method something like

WIN_PATH_MAX_LENGTH = 32000  # arbitrary, sourced from a stack overflow post on NT max path length
if len(dom) < WIN_PATH_MAX_LENGTH and os.path.exists(dom):
    ...

Although maybe it would be better to ensure that dom is either a path or already parsed xml object. I'm new to nansat but can submit a PR.

Thanks!