-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Bring back GDAL and cli create-item
- Loading branch information
Showing
15 changed files
with
438 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use stac::{item::Builder as ItemBuilder, Asset, ToJson}; | ||
use stac_gdal::update_item; | ||
use std::path::Path; | ||
|
||
use crate::Result; | ||
|
||
/// Arguments for the `create_item` subcommand. | ||
#[derive(clap::Args, Debug, Clone)] | ||
pub struct Args { | ||
/// The input file. | ||
// /// | ||
// /// If not provided or `-`, the input will be read from standard input. | ||
href: String, | ||
|
||
/// Asset key | ||
#[arg(default_value = "data")] | ||
asset_key: String, | ||
|
||
/// Semantic roles of the asset | ||
#[arg(short, long)] | ||
roles: Option<String>, | ||
} | ||
|
||
impl crate::Args { | ||
pub async fn create_item(&self, args: &Args) -> Result<()> { | ||
// TODO: Filename must be present or we need to react | ||
let filename = Path::new(&args.href) | ||
.file_name() | ||
.and_then(|s| s.to_str()) | ||
.unwrap(); | ||
let mut asset = Asset::new(&args.href); | ||
if let Some(roles) = &args.roles { | ||
asset = asset.role(roles); | ||
} | ||
|
||
let mut item = ItemBuilder::new(filename) | ||
.asset(&args.asset_key, asset) | ||
.build()?; | ||
|
||
update_item(&mut item, false, true)?; | ||
|
||
{ | ||
let mut stdout = std::io::stdout().lock(); | ||
item.to_json_writer(&mut stdout, false)?; | ||
} | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod create_item; | ||
#[cfg(feature = "pgstac")] | ||
pub mod pgstac; | ||
pub mod search; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[package] | ||
name = "stac-gdal" | ||
description = "STAC utilities that use GDAL" | ||
version = "0.1.0" | ||
authors.workspace = true | ||
edition.workspace = true | ||
homepage.workspace = true | ||
repository.workspace = true | ||
license.workspace = true | ||
categories.workspace = true | ||
rust-version.workspace = true | ||
|
||
[dependencies] | ||
gdal.workspace = true | ||
geojson.workspace = true | ||
log.workspace = true | ||
serde_json.workspace = true | ||
stac.workspace = true | ||
stac-extensions.workspace = true | ||
thiserror.workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use thiserror::Error; | ||
|
||
/// Crate specific error type. | ||
#[derive(Debug, Error)] | ||
#[non_exhaustive] | ||
pub enum Error { | ||
/// [gdal::errors::GdalError] | ||
#[error(transparent)] | ||
GdalError(#[from] gdal::errors::GdalError), | ||
|
||
/// [stac::Error] | ||
#[error(transparent)] | ||
STACError(#[from] stac::Error), | ||
|
||
/// [std::num::ParseIntError] | ||
#[error(transparent)] | ||
ParseIntError(#[from] std::num::ParseIntError), | ||
|
||
/// [serde_json::Error] | ||
#[error(transparent)] | ||
SerdeJson(#[from] serde_json::Error), | ||
|
||
/// Failed to parse EPSG projection from proj extension. | ||
#[error("Failed to parse EPSG projection from: `{0}`")] | ||
ParseEPSGProjectionError(String), | ||
|
||
/// Unsupported STAC extension | ||
#[error("STAC extension `{0}` is not supported")] | ||
UnsupportedExtension(String), | ||
} |
Oops, something went wrong.