from xcube_geodb.core.geodb import GeoDBClient
### uncomment if not in managed environment
#client_id=YourID
#client_secret=YourSecret
#geodb = GeoDBClient(client_id=client_id, client_secret=client_secret, auth_mode="client-credentials")
Login in managed environment¶
The environment is prepared with your user credentials, so you simply can start the client.
geodb = GeoDBClient()
Preparation¶
import time
# Setting the database name; this database contains the EuroCrops data collections
db = 'geodb_b34bfae7-9265-4a3e-b921-06549d3c6035'
Demo #1¶
This step computes the area growing wheat in NRW (Germany), and measures the time needed to do that. Within the collection 'DE_NRW_2021_EC21', the crop types are identified by different codes stored in the column 'code'; the values 112 and 115 identify wheat, therefore the respective query is 'or=(code.eq.112,code.eq.115)'
. The sizes of the fields are stored in the column 'area_ha'
.
if geodb.collection_exists('DE_NRW_2021_EC21', database=db):
tic = time.perf_counter()
df = geodb.get_collection('DE_NRW_2021_EC21', query='or=(code.eq.112,code.eq.115)', database=db)
area_acc = df['area_ha'].sum()
toc = time.perf_counter()
print(f"Computed the area growing wheat in NRW (Germany): {area_acc:0.0f} ha, within {toc - tic} seconds")
Demo #2¶
This step computes the area growing wheat in Belgium, and measures the time needed to do that. Within the collection 'BE_VLG_2021_EC21', the crop types are identified by different codes stored in the column 'gwscod_h'; the values 311 and 312 identify wheat, therefore the respective query is 'or=(gwscod_h.eq.311,gwscod_h.eq.312)'
. The sizes of the fields are stored in the column 'graf_opp'
if geodb.collection_exists('BE_VLG_2021_EC21', database=db):
tic = time.perf_counter()
df = geodb.get_collection('BE_VLG_2021_EC21', query='or=(gwscod_h.eq.311,gwscod_h.eq.312)', database=db)
area_acc = df['graf_opp'].sum()
toc = time.perf_counter()
print(f"Computed the area growing wheat in Belgium (VLG): {area_acc:0.0f} ha, within {toc - tic} seconds")
Demo #3¶
This step extracts 1000 fields growing wheat in Austria. Within the collection 'AT_2021_EC21', the crop types are identified by different codes stored in the column 'snar_code'; the values 140, 168 and 170 identify wheat, and the column 'sl_flaeche'
stores the sizes of the fields.
if geodb.collection_exists('AT_2021_EC21', database=db):
tic = time.perf_counter()
df = geodb.get_collection('AT_2021_EC21',
query='and=(or(snar_code.eq.140,snar_code.eq.168,snar_code.eq.170),sl_flaeche.gt.1)',
database=db, limit=1000)
toc = time.perf_counter()
print(f"Extracted 1000 areas in Austria growing wheat, larger than 1 ha, within {toc - tic} seconds")