DOV-Vlaanderen / pydov

Python package to retrieve data from Databank Ondergrond Vlaanderen (DOV)
https://pydov.readthedocs.io/en/latest/
MIT License
31 stars 19 forks source link

PropertyInList InvalidFieldError pkey_sondering cannot be used in query #402

Open pdweerdt opened 1 month ago

pdweerdt commented 1 month ago

Description

I want to search for interpretations (formele stratigrafie) based on a list of sonderingen (pkey_sondering) After running the code, I got an InvalidFieldError: Cannot use return field 'pkey_sondering' in query."

What I Did


from pydov.util.query import PropertyInList

query = PropertyInList(propertyname='pkey_sondering', lst = so_keys)

df = itp.search(
        query=query
    )

{
    "name": "InvalidFieldError",
    "message": "Cannot use return field 'pkey_sondering' in query.",
    "stack": "---------------------------------------------------------------------------
InvalidFieldError                         Traceback (most recent call last)
Cell In[75], line 3
      1 query = PropertyInList(propertyname='pkey_sondering', lst = so_keys)
----> 3 df_test = itp.search(
      4         query=query
      5     )

File c:\\Users\\pdweerdt\\.conda\\envs\\pydov\\Lib\\site-packages\\pydov\\search\\abstract.py:1085, in AbstractSearch.search(self, location, query, sort_by, return_fields, max_features)
   1028 \"\"\"Search for objects of this type. Provide `location` and/or
   1029 `query` and/or `max_features`.
   1030 When `return_fields` is None, all fields are returned.
   (...)
   1081 
   1082 \"\"\"
   1083 return_fields = ReturnFieldList.from_field_names(return_fields)
-> 1085 trees = self._search(location=location, query=query, sort_by=sort_by,
   1086                      return_fields=return_fields,
   1087                      max_features=max_features)
   1089 feature_generators = []
   1090 for tree in trees:

File c:\\Users\\pdweerdt\\.conda\\envs\\pydov\\Lib\\site-packages\\pydov\\search\\abstract.py:820, in AbstractSearch._search(self, location, query, return_fields, sort_by, max_features, extra_wfs_fields)
    773 def _search(self, location=None, query=None, return_fields=None,
    774             sort_by=None, max_features=None, extra_wfs_fields=[]):
    775     \"\"\"Perform the WFS search by issuing a GetFeature request.
    776 
    777     Parameters
   (...)
    818 
    819     \"\"\"
--> 820     self._pre_search_validation(location, query, sort_by, return_fields,
    821                                 max_features)
    822     self._init_namespace()
    823     self._init_wfs()

File c:\\Users\\pdweerdt\\.conda\\envs\\pydov\\Lib\\site-packages\\pydov\\search\\abstract.py:648, in AbstractSearch._pre_search_validation(self, location, query, sort_by, return_fields, max_features)
    645 if name not in self._map_df_wfs_source \\
    646         and name not in self._wfs_fields:
    647     if name in self._fields:
--> 648         raise InvalidFieldError(
    649             \"Cannot use return field '{}' in query.\".format(
    650                 name))
    651     raise InvalidFieldError(
    652         \"Unknown query parameter: '{}'\".format(name))
    654 if name in self._wfs_fields and name in self._fields and \\
    655         self._fields[name]['type'] == 'geometry':

InvalidFieldError: Cannot use return field 'pkey_sondering' in query."
}

´´´
Roel commented 3 weeks ago

This is indeed expected, pkey_sonderingis a custom calculated field in pydov, and is not queryable. This is also listed in the fields (query: false):

from pydov.search.interpretaties import FormeleStratigrafieSearch

itp = FormeleStratigrafieSearch()
print(itp.get_fields()['pkey_sondering'])

{'name': 'pkey_sondering', 'type': 'string', 'definition': 'URL die verwijst naar de gegevens van de sondering waaraan deze interpretatie gekoppeld is (indien gekoppeld aan een sondering).', 'notnull': False, 'query': False, 'cost': 1}

However you could use the field Proefficheon which the pkey_sonderingfield is based. In your use case this will yield the same results:

from pydov.util.query import PropertyInList
from pydov.search.interpretaties import FormeleStratigrafieSearch

itp = FormeleStratigrafieSearch()

so_keys = ['https://www.dov.vlaanderen.be/data/sondering/1992-000977',
           'https://www.dov.vlaanderen.be/data/sondering/2009-000089']

query = PropertyInList(propertyname='Proeffiche', lst=so_keys)

df = itp.search(
    query=query
)

print(df)