smnorris / bcdata

Python and command line tools for quick access to DataBC geo-data available via WFS/WCS.
MIT License
29 stars 7 forks source link

get_table_definition fails on FWA named point features #153

Closed smnorris closed 11 months ago

smnorris commented 11 months ago
>>> import bcdata
>>> bcdata.__version__
'0.9.0'
>>> bcdata.bcdc.get_table_definition('WHSE_BASEMAPPING.FWA_NAMED_POINT_FEATURES_SP')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/snorris/miniconda3/envs/bcfishpass/lib/python3.11/site-packages/bcdata/bcdc.py", line 112, in get_table_definition
    if json.loads(resource["preview_info"])["layer_name"] == table_name:
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/snorris/miniconda3/envs/bcfishpass/lib/python3.11/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/snorris/miniconda3/envs/bcfishpass/lib/python3.11/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/snorris/miniconda3/envs/bcfishpass/lib/python3.11/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
smnorris commented 11 months ago

This is the resource without a preview_info value (the key is present):

{'cache_last_updated': None, 'package_id': 'a4c778e3-837d-4fd3-9cb2-a9b25ab46d1d', 'datastore_active': False, 'id': 'ecf885b9-a952-4db8-90ef-a8f793edb570', 'size': None, 'spatial_datatype': 'SDO_GEOMETRY', 'iso_topic_category': ['biota', 'climatologyMeteorologyAtmosphere', 'environment', 'geoscientificInformation', 'imageryBaseMapsEarthCover'], 'object_name': 'WHSE_BASEMAPPING.GBA_GLACIERS_HISTORICAL_SP', 'temporal_extent': '', 'state': 'active', 'details': '', 'bcdc_type': 'geographic', 'resource_access_method': 'indirect access', 'hash': '', 'description': 'The Distribution Service allows for data to be downloaded in various file formats from the B.C. Geographic Warehouse (BCGW), a central government repository of spatial and non-spatial data.', 'format': 'multiple', 'projection_name': 'epsg3005', 'cache_url': None, 'preview_info': '', 'mimetype_inner': None, 'geographic_extent': '{\\"north_bound_latitude\\":\\"60.0\\",\\"south_bound_latitude\\":\\"48.0\\",\\"east_bound_longitude\\":\\"-113.5\\",\\"west_bound_longitude\\":\\"-139.5\\"}', 'url_type': None, 'mimetype': None, 'resource_storage_location': 'bc geographic warehouse', 'name': 'Export data or view details from the BC Geographic Warehouse (custom download) ', 'created': '2023-11-30T00:13:35.391229', 'url': '', 'last_modified': '2023-11-27T21:25:06', 'supplemental_info': 'Click <b>Access/Download</b> in the toolbar to download this dataset. For more information on using the distribution order form see [How to download data using the Catalogue or iMapBC](https://www2.gov.bc.ca/gov/content?id=51F40E44C9ED433DAAFC976014C8AF73).', 'resource_update_cycle': 'annually', 'position': 1, 'revision_id': 'c815dcdf-e14a-462f-ba3d-b80380193283', 'resource_type': 'data'}
smnorris commented 11 months ago

With 847e512 bcdata successfully handles this table. But note that I have not looked closely into what is going on with the bcdc api response, the fix is just a workaround for this specific error.