<jupyter_start><jupyter_text>Example 4 - using xcube with a geographic data baseThis notebook shows how to access different data sets through the Sentinel Hub API:1. Query DCFS GeoDB service to retrieve vector data set2. Rasterize vector data3. (Relate vector data and gridded data retrieved through Sentinel Hub)To run this Notebook, make sure the SENTINEL Hub / xcube Integration is setup correctly, see [Ex0-DCFS-Setup](./Ex0-DCFS-Setup.ipynb).<jupyter_code># xcube / SENTINEL Integration
from xcube_sh.config import CubeConfig
from xcube_sh.cube import open_cube
from xcube_sh.sentinelhub import SentinelHub
from xcube_sh.geodb import get_geo_db_service
# xcube Tools
from xcube.core.geom import rasterize_features
# Utilities
import xarray as xr
import numpy as np
import functools
import pyproj
import shapely.geometry
import shapely.ops
import IPython.display<jupyter_output><empty_output><jupyter_text>We use [epsg:3794](https://epsg.io/3794) coordinates:<jupyter_code>x1 = 450000  # meters
y1 = 90000  # meters
x2 = 470000  # meters
y2 = 110000  # meters

bbox_3794 = x1, y1, x2, y2
def transf(geometry, src='epsg:3794', dst='epsg:4326', reverse=False):
    project = functools.partial(
        pyproj.transform,
        pyproj.Proj(init=dst if reverse else src),
        pyproj.Proj(init=src if reverse else dst))
    return shapely.ops.transform(project, geometry)
spatial_res = (x2 - x1) / 512  # degrees
geom_wgs84 = transf(shapely.geometry.box(*bbox_3794))
bbox_wgs84 = geom_wgs84.bounds
IPython.display.GeoJSON(geom_wgs84.__geo_interface__)
cube_config = CubeConfig(dataset_name='S2L2A',
                         band_names=['B04'],
                         tile_size=[512, 512],
                         geometry=bbox_3794,
                         crs='http://www.opengis.net/def/crs/EPSG/0/3794',
                         spatial_res=spatial_res,
                         time_range=['2019-05-01', '2019-07-01'],
                         time_period='2D')  
cube = open_cube(cube_config)
cube
cube.B04.isel(time=17).plot.imshow(cmap='gray', vmin=0, vmax=0.1)<jupyter_output><empty_output><jupyter_text>Get the DCFS GeoDB service:<jupyter_code>geo_db = get_geo_db_service(driver='pgsql', host="db-dcfs-geodb.cbfjgqxk302m.eu-central-1.rds.amazonaws.com",
            user="postgres",
            password="<PASSWORD>")<jupyter_output><empty_output><jupyter_text>The current user's feature collections:<jupyter_code>geo_db.collections<jupyter_output><empty_output><jupyter_text>Find features in collection `land_use` for our bounding box:<jupyter_code>features = geo_db.find_features(collection_name='land_use', bbox=bbox_3794, bbox_srid=3794)
features<jupyter_output><empty_output><jupyter_text>Rasterise feature properties into cube:<jupyter_code>cube2 = rasterize_features(cube, features, ['raba_id'])
cube2
cube2.raba_id.plot.imshow(figsize=(16, 16))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10417385305277682, 'fraction_numerical': 0.046912728527078305, 'mean_word_length': 4.350553505535055, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 26, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '402941', 'license': 'MIT', 'n_tokens_mistral': 1136, 'n_tokens_neox': 1036, 'n_words': 204, 'path': 'examples/notebooks/Ex4-DCFS-GeoDB.ipynb', 'repo_name': 'mocnik/xcube-sh', 'size': '2899'}