Skip to content

Commit c5a7efc

Browse files
committed
add sfeos-tools CLI tool
1 parent ad6f7f6 commit c5a7efc

File tree

8 files changed

+519
-263
lines changed

8 files changed

+519
-263
lines changed

CHANGELOG.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
99

1010
### Added
1111

12-
- Spatial search support for collections via `bbox` parameter on `/collections` endpoint. Collections are now indexed with a `bbox_shape` field (GeoJSON polygon) derived from their spatial extent for efficient geospatial queries. [#481](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/481)
12+
- Spatial search support for collections via `bbox` parameter on `/collections` endpoint. Collections are now indexed with a `bbox_shape` field (GeoJSON polygon) derived from their spatial extent for efficient geospatial queries when created or updated. [#481](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/481)
13+
- Introduced SFEOS Tools (`sfeos_tools/`) - An installable Click-based CLI package for managing SFEOS deployments. Initial command `add-bbox-shape` adds the `bbox_shape` field to existing collections for spatial search compatibility. Install with `pip install sfeos-tools[elasticsearch]` or `pip install sfeos-tools[opensearch]`. [#481](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/481)
1314

1415
### Changed
15-
- Migration scripts (`update_collections_mapping.py` and `recreate_collections_index.py`) to help add `bbox_shape` field to existing deployments. [#481](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/481)
16+
1617
- CloudFerro logo to sponsors and supporters list [#485](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/485)
1718
- Latest news section to README [#485](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/485)
1819

19-
### Changed
20-
2120
### Fixed
2221

2322
[v6.5.1] - 2025-09-30

README.md

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ This project is built on the following technologies: STAC, stac-fastapi, FastAPI
105105
- [Interacting with the API](#interacting-with-the-api)
106106
- [Configure the API](#configure-the-api)
107107
- [Collection Pagination](#collection-pagination)
108+
- [SFEOS Tools CLI](#sfeos-tools-cli)
108109
- [Ingesting Sample Data CLI Tool](#ingesting-sample-data-cli-tool)
109110
- [Elasticsearch Mappings](#elasticsearch-mappings)
110111
- [Managing Elasticsearch Indices](#managing-elasticsearch-indices)
@@ -160,9 +161,21 @@ These endpoints support advanced collection discovery features including:
160161
- Collections are matched if their temporal extent overlaps with the provided datetime parameter
161162
- This allows for efficient discovery of collections based on time periods
162163

164+
- **Spatial Filtering**: Filter collections by their spatial extent using the `bbox` parameter
165+
- Example: `/collections?bbox=-10,35,40,70` (finds collections whose spatial extent intersects with this bounding box)
166+
- Example: `/collections?bbox=-180,-90,180,90` (finds all collections with global coverage)
167+
- Supports both 2D bounding boxes `[minx, miny, maxx, maxy]` and 3D bounding boxes `[minx, miny, minz, maxx, maxy, maxz]` (altitude values are ignored for spatial queries)
168+
- Collections are matched if their spatial extent (stored in the `extent.spatial.bbox` field) intersects with the provided bbox parameter
169+
- **Implementation Note**: When collections are created or updated, a `bbox_shape` field is automatically generated from the collection's spatial extent and indexed as a GeoJSON polygon for efficient geospatial queries
170+
- **Migrating Legacy Collections**: Collections created before this feature was added will not be discoverable via bbox search until they have the `bbox_shape` field added. You can either:
171+
- Update each collection via the API (PUT `/collections/{collection_id}` with the existing collection data)
172+
- Run the migration tool (see [SFEOS Tools CLI](#sfeos-tools-cli) for installation and connection options):
173+
- `sfeos-tools add-bbox-shape --backend elasticsearch --no-ssl`
174+
- `sfeos-tools add-bbox-shape --backend opensearch --host db.example.com --no-ssl`
175+
163176
These extensions make it easier to build user interfaces that display and navigate through collections efficiently.
164177

165-
> **Configuration**: Collection search extensions (sorting, field selection, free text search, structured filtering, and datetime filtering) for the `/collections` endpoint can be disabled by setting the `ENABLE_COLLECTIONS_SEARCH` environment variable to `false`. By default, these extensions are enabled.
178+
> **Configuration**: Collection search extensions (sorting, field selection, free text search, structured filtering, datetime filtering, and spatial filtering) for the `/collections` endpoint can be disabled by setting the `ENABLE_COLLECTIONS_SEARCH` environment variable to `false`. By default, these extensions are enabled.
166179
>
167180
> **Configuration**: The custom `/collections-search` endpoint can be enabled by setting the `ENABLE_COLLECTIONS_SEARCH_ROUTE` environment variable to `true`. By default, this endpoint is **disabled**.
168181
@@ -470,6 +483,64 @@ The system uses a precise naming convention:
470483
curl -X "GET" "http://localhost:8080/collections?limit=1&token=example_token"
471484
```
472485

486+
## SFEOS Tools CLI
487+
488+
- **Overview**: SFEOS Tools is an installable CLI package for managing and maintaining SFEOS deployments.
489+
490+
- **Installation**:
491+
```shell
492+
# For Elasticsearch (from PyPI)
493+
pip install sfeos-tools[elasticsearch]
494+
495+
# For OpenSearch (from PyPI)
496+
pip install sfeos-tools[opensearch]
497+
498+
# For local development
499+
pip install -e sfeos_tools[elasticsearch]
500+
# or
501+
pip install -e sfeos_tools[opensearch]
502+
```
503+
504+
- **Available Commands**:
505+
- `add-bbox-shape`: Add bbox_shape field to existing collections for spatial search support
506+
507+
- **Basic Usage**:
508+
```shell
509+
sfeos-tools add-bbox-shape --backend elasticsearch
510+
sfeos-tools add-bbox-shape --backend opensearch
511+
```
512+
513+
- **Connection Options**: Configure database connection via CLI flags or environment variables:
514+
- `--host`: Database host (default: `localhost` or `ES_HOST` env var)
515+
- `--port`: Database port (default: `9200` or `ES_PORT` env var)
516+
- `--use-ssl` / `--no-ssl`: Use SSL connection (default: `true` or `ES_USE_SSL` env var)
517+
- `--user`: Database username (default: `ES_USER` env var)
518+
- `--password`: Database password (default: `ES_PASS` env var)
519+
520+
- **Examples**:
521+
```shell
522+
# Local Docker Compose (no SSL)
523+
sfeos-tools add-bbox-shape --backend elasticsearch --no-ssl
524+
525+
# Remote server with SSL
526+
sfeos-tools add-bbox-shape \
527+
--backend elasticsearch \
528+
--host db.example.com \
529+
--port 9200 \
530+
--user admin \
531+
--password secret
532+
533+
# Cloud deployment with environment variables
534+
ES_HOST=my-es-cluster.cloud.com ES_PORT=9243 ES_USER=elastic ES_PASS=changeme \
535+
sfeos-tools add-bbox-shape --backend elasticsearch
536+
537+
# Using --help for more information
538+
sfeos-tools --help
539+
sfeos-tools add-bbox-shape --help
540+
```
541+
542+
For more details, see the [SFEOS Tools README](./sfeos_tools/README.md).
543+
473544
## Ingesting Sample Data CLI Tool
474545

475546
- **Overview**: The `data_loader.py` script provides a convenient way to load STAC items into the database.

recreate_collections_index.py

Lines changed: 0 additions & 121 deletions
This file was deleted.

sfeos_tools/README.md

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# SFEOS Tools
2+
3+
CLI tools for managing [stac-fastapi-elasticsearch-opensearch](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch) deployments.
4+
5+
## Installation
6+
7+
### For Elasticsearch
8+
9+
```bash
10+
pip install sfeos-tools[elasticsearch]
11+
```
12+
13+
Or for local development:
14+
```bash
15+
pip install -e sfeos_tools[elasticsearch]
16+
```
17+
18+
### For OpenSearch
19+
20+
```bash
21+
pip install sfeos-tools[opensearch]
22+
```
23+
24+
Or for local development:
25+
```bash
26+
pip install -e sfeos_tools[opensearch]
27+
```
28+
29+
### For Development (both backends)
30+
31+
```bash
32+
pip install sfeos-tools[dev]
33+
```
34+
35+
Or for local development:
36+
```bash
37+
pip install -e sfeos_tools[dev]
38+
```
39+
40+
## Usage
41+
42+
After installation, the `sfeos-tools` command will be available:
43+
44+
```bash
45+
# View available commands
46+
sfeos-tools --help
47+
48+
# View version
49+
sfeos-tools --version
50+
51+
# Get help for a specific command
52+
sfeos-tools add-bbox-shape --help
53+
```
54+
55+
## Commands
56+
57+
### add-bbox-shape
58+
59+
Add `bbox_shape` field to existing collections for spatial search support.
60+
61+
**Basic usage:**
62+
63+
```bash
64+
# Elasticsearch
65+
sfeos-tools add-bbox-shape --backend elasticsearch
66+
67+
# OpenSearch
68+
sfeos-tools add-bbox-shape --backend opensearch
69+
```
70+
71+
**Connection options:**
72+
73+
```bash
74+
# Local Docker Compose (no SSL)
75+
sfeos-tools add-bbox-shape --backend elasticsearch --no-ssl
76+
77+
# Remote server with SSL
78+
sfeos-tools add-bbox-shape \
79+
--backend elasticsearch \
80+
--host db.example.com \
81+
--port 9200 \
82+
--user admin \
83+
--password secret
84+
85+
# Using environment variables
86+
ES_HOST=my-cluster.cloud.com ES_PORT=9243 ES_USER=elastic ES_PASS=changeme \
87+
sfeos-tools add-bbox-shape --backend elasticsearch
88+
```
89+
90+
**Available options:**
91+
92+
- `--backend`: Database backend (elasticsearch or opensearch) - **required**
93+
- `--host`: Database host (default: localhost or ES_HOST env var)
94+
- `--port`: Database port (default: 9200 or ES_PORT env var)
95+
- `--use-ssl / --no-ssl`: Use SSL connection (default: true or ES_USE_SSL env var)
96+
- `--user`: Database username (default: ES_USER env var)
97+
- `--password`: Database password (default: ES_PASS env var)
98+
99+
## Development
100+
101+
To develop sfeos-tools locally:
102+
103+
```bash
104+
# Install in editable mode with dev dependencies
105+
pip install -e ./sfeos_tools[dev]
106+
107+
# Run the CLI
108+
sfeos-tools --help
109+
```
110+
111+
## License
112+
113+
MIT License - see the main repository for details.

0 commit comments

Comments
 (0)