hyriver/py3dep

Error when using py3dep.check_3dep_availability(bbox). ZeroMatched: Service returned no features

LucRSquared opened this issue ยท 4 comments

What happened:

I'm trying to run this piece of code from the documentation

bbox = (-69.77, 45.07, -69.31, 45.45)
py3dep.check_3dep_availability(bbox)

The following error was returned:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
File c:\Users\Luc\anaconda3\envs\hyriver\lib\site-packages\pygeoogc\pygeoogc.py:171, in ArcGISRESTful.oids_bygeom(self, geom, geo_crs, spatial_relation, sql_clause, distance)
    170 try:
--> 171     return self.partition_oids(resp["objectIds"])
    172 except (KeyError, TypeError) as ex:

File c:\Users\Luc\anaconda3\envs\hyriver\lib\site-packages\pygeoogc\pygeoogc.py:256, in ArcGISRESTful.partition_oids(self, oids)
    244 """Partition feature IDs based on ``self.max_nrecords``.
    245 
    246 Parameters
   (...)
    254     A list of feature IDs partitioned by ``self.max_nrecords``.
    255 """
--> 256 return self.client.partition_oids(oids)

File c:\Users\Luc\anaconda3\envs\hyriver\lib\site-packages\pygeoogc\core.py:291, in ArcGISRESTfulBase.partition_oids(self, oids)
    290 """Partition feature IDs based on ``self.max_nrecords``."""
--> 291 oid_list = [oids] if isinstance(oids, int) else set(oids)
    292 if len(oid_list) == 0:

TypeError: 'NoneType' object is not iterable

The above exception was the direct cause of the following exception:
...
    173     msg = resp["error"]["message"] if "error" in resp else "No matched records"
--> 174     raise ZeroMatched(msg) from ex

ZeroMatched: Service returned no features with the following error message:
No matched records

What you expected to happen:

The output as described by the documentation

{'1m': True, '3m': False, '5m': False, '10m': True, '30m': True, '60m': False, 'topobathy': False}

Environment:

Output of py3dep.show_versions()

INSTALLED VERSIONS
------------------
commit: None
python: 3.9.13 | packaged by conda-forge | (main, May 27 2022, 16:50:36) [MSC v.1929 64 bit (AMD64)]
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 141 Stepping 1, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: English_United States.1252
libhdf5: 1.12.1
libnetcdf: 4.8.1

aiodns: 3.0.0
aiohttp: 3.8.1
aiohttp-client-cache: 0.7.0
aiosqlite: 0.17.0
async-retriever: 0.3.3
bottleneck: 1.3.4
brotli: installed
cchardet: 2.1.7
click: 8.1.3
cytoolz: 0.11.2
dask: 2022.6.0
defusedxml: 0.7.1
folium: 0.12.1.post1
geopandas: 0.10.2
lxml: 4.9.0
matplotlib: 3.4.3
netCDF4: 1.5.8
networkx: 2.8.4
numpy: 1.22.4
owslib: 0.25.0
pandas: 1.4.2
py3dep: 0.13.2
pyarrow: 6.0.0
pydantic: 1.9.1
pydaymet: 0.13.2
pygeohydro: 0.13.2
pygeoogc: 0.13.2
pygeos: 0.12.0
pygeoutils: 0.13.2
pynhd: 0.13.2
pyproj: 3.3.1
pytest: None
pytest-cov: None
rasterio: 1.2.10
requests: 2.28.0
requests-cache: 0.9.4
richdem: None
rioxarray: 0.11.1
scipy: 1.8.1
shapely: 1.8.2
tables: None
ujson: 5.3.0
urllib3: 1.26.9
xarray: 2022.3.0
xdist: None
yaml: 6.0

Experiencing the same issue here.

srs = "EPSG:4326"
bbox = (-93.328943, 41.615699, -93.309717, 41.630007)
py3dep.check_3dep_availability(bbox, srs)

With the same error message:

C:\Users\brand\AppData\Roaming\Python\Python310\site-packages\geopandas\_compat.py:111: UserWarning: The Shapely GEOS version (3.10.2-CAPI-1.16.0) is incompatible with the GEOS version PyGEOS was compiled with (3.10.1-CAPI-1.16.0). Conversions between both will be slow.
  warnings.warn(
Traceback (most recent call last):
  File "C:\Users\brand\AppData\Roaming\Python\Python310\site-packages\pygeoogc\pygeoogc.py", line 171, in oids_bygeom
    return self.partition_oids(resp["objectIds"])
  File "C:\Users\brand\AppData\Roaming\Python\Python310\site-packages\pygeoogc\pygeoogc.py", line 256, in partition_oids
    return self.client.partition_oids(oids)
  File "C:\Users\brand\AppData\Roaming\Python\Python310\site-packages\pygeoogc\core.py", line 291, in partition_oids
    oid_list = [oids] if isinstance(oids, int) else set(oids)
TypeError: 'NoneType' object is not iterable

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\brand\CLionProjects\libraster\libraster_utils\examples\typical_use.py", line 39, in <module>
    print(py3dep.check_3dep_availability(bbox))
  File "C:\Users\brand\AppData\Roaming\Python\Python310\site-packages\py3dep\py3dep.py", line 432, in check_3dep_availability
    return {res: _check(lyr) for res, lyr in res_layers.items()}
  File "C:\Users\brand\AppData\Roaming\Python\Python310\site-packages\py3dep\py3dep.py", line 432, in <dictcomp>
    return {res: _check(lyr) for res, lyr in res_layers.items()}
  File "C:\Users\brand\AppData\Roaming\Python\Python310\site-packages\py3dep\py3dep.py", line 429, in _check
    return len(list(wms.oids_bygeom(_bbox))[0]) > 0
  File "C:\Users\brand\AppData\Roaming\Python\Python310\site-packages\pygeoogc\pygeoogc.py", line 174, in oids_bygeom
    raise ZeroMatched(msg) from ex
pygeoogc.exceptions.ZeroMatched: Service returned no features with the following error message:
No matched records

Process finished with exit code 1

Version information:

INSTALLED VERSIONS
------------------
commit: 5c4b6085e618f2623386f395bf4a4d4ac726ce55
python: 3.10.5 (tags/v3.10.5:f377153, Jun  6 2022, 16:14:13) [MSC v.1929 64 bit (AMD64)]
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: AMD64 Family 23 Model 8 Stepping 2, AuthenticAMD
byteorder: little
LC_ALL: None
LANG: None
LOCALE: English_United States.1252
libhdf5: 1.10.7
libnetcdf: 4.8.1

aiodns: 3.0.0
aiohttp: 3.8.1
aiohttp-client-cache: 0.7.0
aiosqlite: 0.17.0
async-retriever: 0.3.3
bottleneck: None
brotli: 1.0.9
cchardet: 2.1.7
click: 8.1.3
cytoolz: 0.11.2
dask: 2022.6.0
defusedxml: 0.7.1
folium: 0.12.1.post1
geopandas: 0.10.2
lxml: 4.9.0
matplotlib: 3.5.2
netCDF4: 1.5.8
networkx: 2.8.4
numpy: 1.22.4
owslib: 0.25.0
pandas: 1.4.2
py3dep: 0.13.2
pyarrow: 8.0.0
pydantic: 1.9.1
pydaymet: None
pygeohydro: 0.13.2
pygeoogc: 0.13.2
pygeos: 0.12.0
pygeoutils: 0.13.2
pynhd: 0.13.2
pyproj: 3.3.1
pytest: None
pytest-cov: None
rasterio: 1.2.10
requests: 2.28.0
requests-cache: 0.9.4
richdem: None
rioxarray: 0.11.1
scipy: 1.8.1
shapely: 1.8.2
tables: None
ujson: 5.3.0
urllib3: 1.26.9
xarray: 2022.3.0
xdist: None
yaml: 6.0
None

Thanks for reporting the issue. I just pushed a fix that addresses this issue. I will release a new version with this fix soon. In the meanwhile you can install the latest version from GitHub like so:

pip install git+https://github.com/cheginit/py3dep

Just note that the The National Map's 3DEP service is currently down. You can check its status here.

I just released v0.13.3 with a fix.