# gRPC stac-client-python
### What is this Good for
Use this library to access download information and other details for aerial imagery and for other geospatial datasets. This client accesses [Near Space Labs](https://nearspacelabs.com)' gRPC STAC service (or any gRPC STAC service). Landsat, NAIP and the Near Space Labs's Swift datasets are available for search.
### Quick Code Example
Using a [StacRequest](https://geo-grpc.github.io/api/#epl.protobuf.StacRequest) query the service for one [StacItem](https://geo-grpc.github.io/api/#epl.protobuf.StacItem). Under the hood the client.search_one method uses the [StacService's](https://geo-grpc.github.io/api/#epl.protobuf.StacService) SearchOne gRPC method
```python
from datetime import datetime
# the StacRequest is a protobuf message for making filter queries for data, you can think of it as
# the query string in a url
from epl.protobuf.stac_pb2 import StacRequest
# the client package stubs out a little bit of the gRPC connection code
from nsl.stac.client import NSLClient
# This search looks for any type of imagery hosted in the STAC service; anywhere in the world, at any
# moment in time and of any data type
stac_request = StacRequest()
# get a client interface to the gRPC channel
client = NSLClient()
# search_one method requests only one item be returned that meets the query filters in the StacRequest
# the item returned is a StacItem protobuf message
stac_item = client.search_one(stac_request)
# display the scene id
print("STAC item id {}".format(stac_item.id))
# display the observed date of the scene. The observed
dt_observed = datetime.fromtimestamp(stac_item.observed.seconds)
print("Date observed {}".format(dt_observed.strftime("%m/%d/%Y, %H:%M:%S")))
```
The above python prints out:
```bash
STAC item id: LE70980132019174EDC00
Date observed: 06/23/2019, 03:00:46
```
### What are Protobufs, gRPC, and Spatio Temporal Asset Catalogs?
This python client library is used for connecting to a gRPC enabled STAC service. STAC items and STAC requests are Protocol Buffers (protobuf) instead of traditional JSON.
Never hear of gRPC, Protocol Buffers or STAC? Below are summary blurbs and links for more details about this open source projects.
Definition of STAC from https://stacspec.org/:
> The SpatioTemporal Asset Catalog (STAC) specification provides a common language to describe a range of geospatial information, so it can more easily be indexed and discovered. A 'spatiotemporal asset' is any file that represents information about the earth captured in a certain space and time.
Definition of gRPC from https://grpc.io
> gRPC is a modern open source high performance RPC framework that can run in any environment. It can efficiently connect services in and across data centers with pluggable support for load balancing, tracing, health checking and authentication. It is also applicable in last mile of distributed computing to connect devices, mobile applications and browsers to backend services.
Definitions of Protocol Buffers (protobuf) from https://developers.google.com/protocol-buffers/
> Protocol buffers are Google's language-neutral, platform-neutral, extensible mechanism for serializing structured data – think XML, but smaller, faster, and simpler. You define how you want your data to be structured once, then you can use special generated source code to easily write and read your structured data to and from a variety of data streams and using a variety of languages.
In other words:
- You can think of Protobuf as strict a data format like xml or JSON + linting, except Protobuf is a compact binary message with strongly typed fields
- gRPC is similar to REST + OpenAPI, except gRPC is an [RPC](https://en.wikipedia.org/wiki/Remote_procedure_call) framework that supports bi-directional streaming
- STAC is a specification that helps remove repeated efforts for searching geospatial datasets (like WFS for specific data types)
### Setup
Grab it from [pip](https://pypi.org/project/nsl.stac/):
```bash
pip install nsl.stac
```
Install it from source:
```bash
pip install -r requirements.txt
python setup.py install
```
### Environment Variables
There are a few environment variables that the stac-client-python library relies on for accessing the STAC service:
- STAC_SERVICE, the address of the STAC service you connect to (defaults to "localhost:10000")
### Queries
#### Simple Query and the Makeup of a StacItem
There easiest query to construct is a `StacRequest` constructor with no variables, and the next simplest, is the case where we know the STAC item `id` that we want to search. If we already know the STAC `id` of an item, we can construct the `StacRequest` as follows:
```python
from nsl.stac.client import NSLClient
from epl.protobuf.stac_pb2 import StacRequest
stac_request = StacRequest(id='LE70380352019169EDC00')
# get a client interface to the gRPC channel
client = NSLClient()
# for this request we might as well use the search one, as STAC ids ought to be unique
stac_item = client.search_one(stac_request)
print(stac_item)
```
The print out for the stac item is quite lengthy. Although `stac_item` is a protobuf object, it's `__str__` method prints out a JSON-like object. You can see in the below example that this `StacItem` contains the following:
- [GeometryData](https://geo-grpc.github.io/api/#epl.protobuf.GeometryData) which is defined with a WGS-84 well-known binary geometry
- [EnvelopeData](https://geo-grpc.github.io/api/#epl.protobuf.EnvelopeData) which is also WGS-84
- [Timestamp](https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/timestamp.proto) Google's protobuf unix time format
- [Eo](https://geo-grpc.github.io/api/#epl.protobuf.Eo) for electro-optical sensor details
- [Landsat](https://geo-grpc.github.io/api/#epl.protobuf.Landsat) for Landsat sepcific details
- an array map of [StacItem.AssetsEntry](https://geo-grpc.github.io/api/#epl.protobuf.StacItem.AssetsEntry) with each [Asset](https://geo-grpc.github.io/api/#epl.protobuf.Asset) containing details about [AssetType](https://geo-grpc.github.io/api/#epl.protobuf.AssetType), Electro Optical [Band enums](https://geo-grpc.github.io/api/#epl.protobuf.Eo.Band) (if applicable), and other details for downloading and interpreting data
<details><summary>StacItem print out</summary>
```text
id: "LE70380352019169EDC00"
geometry {
wkb: "\001\006\000\000\000\001\000\000\000\001\003\000\000\000\001\000\000\000\013\000\000\000&\271i\3470\237\\\300\014]J\037b\301A@\215\227n\022\203\240\\\300V\237\253\255\330\267A@\215\227n\022\203 \\\300\264\310v\276\237\222A@)\314\366\0230 \\\300\"A\357;\304\224A@\360*%j\324\004\\\300\356;\241\373\221IB@\010\254\034Zd\003\\\300P\215\227n\022SB@Rf6\004\277\205\\\300\310\021wH\373xB@\366(\\\217\302\205\\\300\360\026HP\374xB@\013\312\004\350J\206\\\300\016\241\001\362#uB@\032x\271\\\025\207\\\300\230\340\226JnoB@&\271i\3470\237\\\300\014]J\037b\301A@"
sr {
wkid: 4326
}
simple: STRONG_SIMPLE
}
bbox {
xmin: -114.508
ymin: 35.1455
xmax: -112.053
ymax: 36.9452
sr {
wkid: 4326
}
}
datetime {
seconds: 1560880732
nanos: 695231000
}
observed {
seconds: 1560880732
nanos: 695231000
}
updated {
seconds: 1566935318
nanos: 354185000
}
eo {
platform: LANDSAT_7
instrument: ETM
constellation: LANDSAT
gsd {
value: 30.0
}
cloud_cover {
value: 10.0
}
}
landsat {
scene_id: "LE70380352019169EDC00"
product_id: "LE07_L1TP_038035_20190618_20190618_01_RT"
processing_level: L1TP
wrs_path: 38
wrs_row: 35
}
assets {
key: "GEOTIFF_GCP_BLUE"
value {
href: "https://gcp-public-data-landsat.storage.googleapis.com/LE07/01/038/035/LE07_L1TP_038035_20190618_20190618_01_RT/LE07_L1TP_038035_20190618_20190618_01_RT_B1.TIF"
type: "image/vnd.stac.geotiff"
eo_bands: BLUE
asset_type: GEOTIFF
cloud_platform: GCP
bucket_manager: "Google"
bucket_region: "us-multi-region"
bucket: "gcp-public-data-landsat"
object_path:
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
共14个文件
py:5个
txt:4个
pkg-info:2个
资源分类:Python库 所属语言:Python 资源全名:nsl.stac-0.2.3.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源推荐
资源详情
资源评论
收起资源包目录
nsl.stac-0.2.3.tar.gz (14个子文件)
nsl.stac-0.2.3
PKG-INFO 558B
test
test_client.py 15KB
nsl.stac.egg-info
PKG-INFO 558B
requires.txt 43B
not-zip-safe 1B
SOURCES.txt 296B
top_level.txt 4B
dependency_links.txt 1B
nsl
stac
utils.py 9KB
client.py 2KB
__init__.py 3KB
setup.cfg 82B
setup.py 1011B
README.md 33KB
共 14 条
- 1
资源评论
挣扎的蓝藻
- 粉丝: 12w+
- 资源: 15万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功