Environmental data retrieval API query parser
Project description
Environmental Data Retrieval Query Parser
The OGC API Environmental Data Retrieval query parser makes it easy to parse and use the API query.
install
pip install edr-query-parser
Usage
EDR Collection Name Example
from edr_query_parser import EDRQueryParser
edr_query = EDRQueryParser('https://somewhere.com/collections/my_collection/position?parameter-name=param1,param2&coords=POINT(57.819 '
'-3.966)&datetime=2019-09-07T15:50-04:00/2019-09-07T15:50-05:00&f=geoJSON&crs=84&z=500/400')
select = 'SELECT * FROM ' + edr_query.collection_name
print(select) # SELECT * FROM my_collection
EDR Query Type Example
from edr_query_parser import EDRQueryParser
edr_query = EDRQueryParser('https://somewhere.com/collections/my_collection/position?parameter-name=param1,param2&coords=POINT(57.819 '
'-3.966)&datetime=2019-09-07T15:50-04:00/2019-09-07T15:50-05:00&f=geoJSON&crs=84&z=500/400')
if edr_query.is_instances:
print(edr_query.instances_id)
else:
print(edr_query.query_type) # position
EDR coords Example
The EDR query parser returns a WKT object
from edr_query_parser import EDRQueryParser
edr_query = EDRQueryParser('https://somewhere.com/collections/my_collection/position?coords=POINT(57.819 '
'-3.966)&datetime=2019-09-07T15:50-04:00/2019-09-07T15:50-05:00¶meter-name=parameter1,'
'parameter2&f=geoJSON&crs=84&z=all')
select = 'SELECT * FROM observations'
if edr_query.coords.is_set:
if edr_query.coords.coords_type == 'Point':
select += ' WHERE NEAREST_NEIGHBOUR(' + str(edr_query.coords.coordinates[0]) + ',' + str(edr_query.coords.coordinates[0]) + ')'
print(select) # SELECT * FROM observations WHERE NEAREST_NEIGHBOUR(57.819,-3.966)
EDR parameter-name Example
from edr_query_parser import EDRQueryParser
edr_query = EDRQueryParser('https://somewhere.com/collections/my_collection/position?coords=POINT(57.819 '
'-3.966)&datetime=2019-09-07T15:50-04:00/2019-09-07T15:50-05:00¶meter-name=parameter1,'
'parameter2&f=geoJSON&crs=84&z=all')
select = 'SELECT '
if edr_query.parameter_name.is_set:
select += ','.join(edr_query.parameter_name.list)
else:
select += '*'
select += ' FROM observations'
print(select) # SELECT parameter1, parameter2 FROM observations'
EDR datetime Example
The EDR query parser returns a dateutil object
from edr_query_parser import EDRQueryParser
edr_query = EDRQueryParser('https://somewhere.com/collections/my_collection/position?coords=POINT(57.819 '
'-3.966)&datetime=2019-09-07T15:50-04:00/2019-09-07T15:50-05:00¶meter-name=parameter1,'
'parameter2&f=geoJSON&crs=84&z=all')
select = 'SELECT * FROM observations'
if edr_query.datetime.is_set:
if edr_query.datetime.is_interval:
select += ' date BETWEEN ' + str(edr_query.datetime.interval_from.timestamp()) + ' AND ' + str(edr_query.datetime.interval_to.timestamp())
else:
select += ' date = ' + str(edr_query.datetime.exact.timestamp()) + ')'
print(select) # SELECT * FROM observations date BETWEEN 1567885800.0 AND 1567889400.0
EDR f Parameter Example
from edr_query_parser import EDRQueryParser
edr_query = EDRQueryParser('https://somewhere.com/collections/my_collection/position?parameter-name=param1,param2&coords=POINT(57.819 '
'-3.966)&datetime=2019-09-07T15:50-04:00/2019-09-07T15:50-05:00&f=geoJSON&crs=84&z=500/400')
print(edr_query.format) # geoJSON
EDR z Parameter Example
from edr_query_parser import EDRQueryParser
edr_query = EDRQueryParser('https://somewhere.com/collections/my_collection/position?coords=POINT(57.819 '
'-3.966)&datetime=2019-09-07T15:50-04:00/2019-09-07T15:50-05:00¶meter-name=parameter1,'
'parameter2&f=geoJSON&crs=84&z=12/240')
select = 'SELECT * FROM observations'
if edr_query.z.is_set:
if edr_query.z.is_interval:
select += ' height BETWEEN ' + str(edr_query.z.interval_from) + ' AND ' + str(edr_query.z.interval_to)
if edr_query.z.is_list:
select += ' height IN (' + ','.join(map(str, edr_query.z.list)) + ')'
print(select) # SELECT * FROM observations height BETWEEN 12.0 AND 240.0
EDR crs Parameter Example
from edr_query_parser import EDRQueryParser
edr_query = EDRQueryParser('https://somewhere.com/collections/my_collection/position?coords=POINT(57.819 '
'-3.966)&datetime=2019-09-07T15:50-04:00/2019-09-07T15:50-05:00¶meter-name=parameter1,'
'parameter2&f=geoJSON&crs=84&z=12/240')
print(edr_query.crs.value) # 84
EDR bbox Parameter Example
from edr_query_parser import EDRQueryParser
edr_query = EDRQueryParser('https://somewhere.com/collections/my_collection/items/some_item/?bbox=12,13,20,21')
print(edr_query.bbox.list) # [12.0, 13.0, 20.0, 21.0]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
edr query parser-2.3.tar.gz
(6.6 kB
view hashes)
Built Distribution
Close
Hashes for edr_query_parser-2.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1396602b98f8cdb9875a996d78b34cb31481aac6ffdc92e4fda0e2340db9ab06 |
|
MD5 | bcb3267f916fbb3221ce2e97b1c17b92 |
|
BLAKE2b-256 | 24fbd58969a851a38c2959c7912d0354f906d6016d46f150d749ed8024c23da6 |