68 lines
1.6 KiB
Python
68 lines
1.6 KiB
Python
import os
|
|
import psycopg2
|
|
import time
|
|
import pystac_client
|
|
import geogif
|
|
import stackstac
|
|
from matplotlib import pyplot as plt
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
print("starting app.")
|
|
|
|
URL = "https://stac.dataspace.copernicus.eu/v1"
|
|
cat = pystac_client.Client.open(URL)
|
|
cat.add_conforms_to("ITEM_SEARCH")
|
|
|
|
geom = {
|
|
"type": "Polygon",
|
|
"coordinates": [
|
|
[
|
|
[32.6, -17.3],
|
|
[32.6, -17.1],
|
|
[33.0, -17.1],
|
|
[33.0, -17.3],
|
|
[32.6, -17.3],
|
|
]
|
|
],
|
|
}
|
|
|
|
|
|
params = {
|
|
"max_items": 1,
|
|
"collections": "sentinel-2-l2a",
|
|
"datetime": "2017-02-01/2017-10-01",
|
|
"intersects": geom,
|
|
"query": {"eo:cloud_cover": {"gte": 0, "lte": 20}},
|
|
"sortby": "properties.eo:cloud_cover",
|
|
"fields": {"exclude": ["geometry"]},
|
|
}
|
|
|
|
print("Searching items...")
|
|
items = list(cat.search(**params).items_as_dicts())
|
|
print("Search successful.")
|
|
|
|
|
|
|
|
stack = stackstac.stack(
|
|
items=items,
|
|
resolution=(60, 60),
|
|
bounds_latlon=(33.0, -17.1, 32.6, -17.3),
|
|
chunksize=98304,
|
|
epsg=32634,
|
|
gdal_env=stackstac.DEFAULT_GDAL_ENV.updated(
|
|
{
|
|
"GDAL_NUM_THREADS": -1,
|
|
"GDAL_HTTP_UNSAFESSL": "YES",
|
|
"GDAL_HTTP_TCP_KEEPALIVE": "YES",
|
|
"AWS_VIRTUAL_HOSTING": "FALSE",
|
|
"AWS_HTTPS": "YES",
|
|
}
|
|
),
|
|
)
|
|
|
|
rgb = stack.sel(band=["B04_60m", "B03_60m", "B02_60m"])
|
|
print(rgb)
|
|
rgb.plot()
|
|
plt.show() |