向Resonant GeoData实例发送网络请求。
项目描述
rgd_imagery_client - Resonant GeoData影像客户端
安装
要安装影像客户端插件
pip install rgd-imagery-client
用法
检查栅格
预览栅格的缩略图
import imageio
from io import BytesIO
from rgd_client import create_rgd_client
from rgd_imagery_client import ImageryClient
client: ImageryClient = create_rgd_client(username='username', password='password')
raster = client.imagery.get_raster(q[0])
plot_geojson(bbox, 'k--')
plot_geojson(raster['outline'], 'r')
load_image = lambda imbytes: imageio.imread(BytesIO(imbytes))
count = len(raster['parent_raster']['image_set']['images'])
for i in range(count):
thumb_bytes = client.imagery.download_raster_thumbnail(q[0], band=i)
thumb = load_image(thumb_bytes)
plt.subplot(1, count, i+1)
plt.imshow(thumb)
plt.tight_layout()
plt.show()
下载栅格
下载整个栅格图像集
import rasterio
from rasterio.plot import show
paths = client.imagery.download_raster(q[0])
rasters = [rasterio.open(im) for im in paths.images]
for i, src in enumerate(rasters):
plt.subplot(1, len(rasters), i+1)
ax = plt.gca()
show(src, ax=ax)
plt.tight_layout()
plt.show()
STAC Item支持
Python客户端有一个针对栅格数据的搜索端点,返回搜索结果中的每个记录作为STAC Item。
q = client.imagery.search_raster_stac(query=json.dumps(bbox), predicate='intersects')
print(q[0]) # view result as STAC Item
# Download using the search result
paths = client.imagery.download_raster(q[0])
print(paths)
我们还可以以STAC Item格式上传新数据。在这里,我们只是返回相同的STAC Item JSON,实际上不会做任何事情,因为RGD已经识别出这些文件已经存在栅格中。
client.imagery.create_raster_stac(q[0])
请注意,STAC Item中的资产必须已经上传到带有 s3://
或 https://
URL的云存储提供商。此外,每项资产都必须有 data
标签。例如。
{
... # other STAC Item fields
'assets': {
'image-15030': {
'href': 'http://storage.googleapis.com/gcp-public-data-sentinel-2/tiles/17/S/MS/S2A_MSIL1C_20210302T161201_N0209_R140_T17SMS_20210302T200521.SAFE/GRANULE/L1C_T17SMS_A029738_20210302T161751/IMG_DATA/T17SMS_20210302T161201_B01.jp2',
'title': 'GRANULE/L1C_T17SMS_A029738_20210302T161751/IMG_DATA/T17SMS_20210302T161201_B01.jp2',
'eo:bands': [{'name': 'B1'}],
'roles': ['data'],
},
'image-15041': {
'href': 'http://storage.googleapis.com/gcp-public-data-sentinel-2/tiles/17/S/MS/S2A_MSIL1C_20210302T161201_N0209_R140_T17SMS_20210302T200521.SAFE/GRANULE/L1C_T17SMS_A029738_20210302T161751/IMG_DATA/T17SMS_20210302T161201_B02.jp2',
'title': 'GRANULE/L1C_T17SMS_A029738_20210302T161751/IMG_DATA/T17SMS_20210302T161201_B02.jp2',
'eo:bands': [{'name': 'B1'}],
'roles': ['data'],
},
... # ancillary files can lack a role but we like to see `metadata` used.
'ancillary-30687': {
'href': 'http://storage.googleapis.com/gcp-public-data-sentinel-2/tiles/17/S/MS/S2A_MSIL1C_20210302T161201_N0209_R140_T17SMS_20210302T200521.SAFE/GRANULE/L1C_T17SMS_A029738_20210302T161751/QI_DATA/MSK_TECQUA_B03.gml',
'title': 'GRANULE/L1C_T17SMS_A029738_20210302T161751/QI_DATA/MSK_TECQUA_B03.gml',
'roles': ['metadata'],
},
}
}