-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathREADME.Rmd
191 lines (157 loc) · 5.24 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# openstac
<!-- badges: start -->
<!-- badges: end -->
## Introduction
`openstac` is an R package designed to facilitate the creation of a STAC (SpatioTemporal Asset Catalog) API server. This package leverages the `plumber` package to create a RESTful API compliant with the STAC 1.0.0 specification. With `openstac`, you can easily expose spatial and temporal data as STAC-compliant services, enabling seamless integration with other geospatial tools and platforms.
## Features
- Quickly set up a STAC API server using R
- Expose collections of geospatial data
- Retrieve individual items from collections
- Perform spatial and temporal searches
- Easily customize endpoints and responses
## Installation
You can install `openstac` from [GitHub](https://github.com/rolfsimoes/openstac) using the `remotes` package:
```{r preparation, eval=FALSE, include=TRUE}
remotes::install_github("Open-Earth-Monitor/openstac")
```
## Usage
To use `openstac`, follow these steps:
1. Import the `openstac` library: `library(openstac)`.
2. Create a new STAC API server using `create_api_stac()`.
3. Configure your API endpoints for STAC API using plumber.
4. Run your API using plumber.
## Example
This is a basic example:
```{r example, eval=FALSE, include=TRUE}
#* @apiTitle STAC API
#* @apiDescription R STAC API server.
#* @apiVersion 1.0.0
library(openstac)
# Create an STAC server API object
api <- create_stac(
id = "my_stac",
title = "R STAC API server",
description = "This is a STAC API 1.0.0 compliant R backend."
)
# Set API database
db_file <- system.file("db/olm-example.rds", package = "openstac")
api <- set_db(api, driver = "local", file = db_file)
#* Landing page
#* @get /
#* @serializer unboxedJSON
#* @tag 'STAC API v1.0.0'
function(req, res) {
api_landing_page(api, req, res)
}
#* Conformance endpoint
#* @get /conformance
#* @serializer unboxedJSON
#* @tag 'STAC API v1.0.0'
function(req, res) {
api_conformance(api, req, res)
}
#* Collections endpoint
#* @get /collections
#* @serializer unboxedJSON
#* @tag 'STAC API v1.0.0'
function(req, res) {
api_collections(api, req, res)
}
#* Collection endpoint
#* @get /collections/<collection_id>
#* @param collection_id:str The ID of the collection
#* @serializer unboxedJSON
#* @tag 'STAC API v1.0.0'
function(req, res, collection_id) {
api_collection(api, req, res, collection_id)
}
#* Items endpoint
#* @get /collections/<collection_id>/items
#* @param collection_id:str The ID of the collection
#* @param limit:int Maximum number of features to return (default: 10)
#* @param bbox:str Bounding box (minx,miny,maxx,maxy)
#* @param datetime:str Datetime filter
#* @param page:int Pagination parameter (default: 1)
#* @serializer unboxedJSON
#* @tag 'STAC API v1.0.0'
function(req,
res,
collection_id,
limit = 10,
bbox,
datetime,
page = 1) {
# check parameters
if (!is.null(limit)) {
limit <- parse_int(limit[[1]])
check_limit(limit, min = 1, max = 10000)
}
if (missing(bbox)) bbox <- NULL
if (!is.null(bbox)) {
bbox <- parse_dbl(bbox)
check_bbox(bbox)
}
if (missing(datetime)) datetime <- NULL
if (!is.null(datetime)) {
datetime <- parse_datetime(datetime[[1]])
}
if (!is.null(page)) {
page <- parse_int(page[[1]])
check_page(page)
}
# call api items
api_items(
api = api,
req = req,
res = res,
collection_id = collection_id,
limit = limit,
bbox = bbox,
datetime = datetime,
page = page
)
}
#* Item endpoint
#* @get /collections/<collection_id>/items/<item_id>
#* @param collection_id:str The ID of the collection
#* @param item_id:str The ID of the item
#* @serializer unboxedJSON
#* @tag 'STAC API v1.0.0'
function(req, res, collection_id, item_id) {
api_item(api, req, res, collection_id, item_id)
}
```
To run this example, save this code in a file, e.g. `my_api.R` and run:
```{r eun_api, eval=FALSE, include=TRUE}
library(plumber)
plumber::plumb("my_api.R") |>
plumber::run(host = "127.0.0.1", port = 8888)
```
## Documentation
For detailed usage and additional examples, please refer to the `openstac`
[documentation](https://github.com/Open-Earth-Monitor/openstac).
## Contributing
This package is under early development. We are going to add the contributing guidelines soon.
## License
© OpenGeoHub Foundation, 2024. Licensed under the [MIT License](LICENSE).
## Acknowledgements & Funding
This work is supported by [OpenGeoHub Foundation](https://opengeohub.org/) and has received
funding from the European Commission (EC) through the projects:
- [Open-Earth-Monitor Cyberinfrastructure](https://earthmonitor.org/): Environmental information
to support EU’s Green Deal (1 Jun. 2022 – 31 May 2026 -
[101059548](https://cordis.europa.eu/project/id/101059548))
- [AI4SoilHealth](https://ai4soilhealth.eu/): Accelerating collection and use of soil health
information using AI technology to support the Soil Deal for Europe and EU Soil Observatory
(1 Jan. 2023 – 31 Dec. 2026 - [101086179](https://cordis.europa.eu/project/id/101086179))