Skip to content

Commit 1693405

Browse files
committed
feat(core, validate): update to STAC v1.1.0
1 parent 74643f3 commit 1693405

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+2836
-64
lines changed

cli/examples

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
../spec-examples/v1.0.0
1+
../spec-examples/v1.1.0

cli/tests/smoke.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ fn migrate() {
3131
let mut command = Command::cargo_bin("stacrs").unwrap();
3232
command
3333
.arg("migrate")
34-
.arg("examples/simple-item.json")
34+
.arg("../spec-examples/v1.0.0/simple-item.json")
3535
.arg("--version")
36-
.arg("1.1.0-beta.1")
36+
.arg("1.1.0")
3737
.assert()
3838
.success();
3939
}

core/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
2020
### Changed
2121

2222
- Update **geoarrow** to v0.3.0 ([#367](https://github.com/stac-utils/stac-rs/pull/367))
23+
- Default STAC version is now v1.1.0 ([#399](https://github.com/stac-utils/stac-rs/pull/399))
2324

2425
### Removed
2526

core/data/bands-v1.1.0-beta.1.json renamed to core/data/bands-v1.1.0.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"type": "Feature",
3-
"stac_version": "1.1.0-beta.1",
3+
"stac_version": "1.1.0",
44
"id": "bands-migration",
55
"geometry": null,
66
"properties": {

core/examples

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
../spec-examples/v1.0.0
1+
../spec-examples/v1.1.0

core/src/extensions/mod.rs

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
//!
3333
//! // Get extension information
3434
//! let mut projection: Projection = item.extension().unwrap().unwrap();
35-
//! println!("epsg: {}", projection.epsg.unwrap());
35+
//! println!("code: {}", projection.code.as_ref().unwrap());
3636
//!
3737
//! // Set extension information
3838
//! projection.centroid = Some(Centroid { lat: 34.595302, lon: -101.344483 });
@@ -112,7 +112,7 @@ pub trait Extensions: Fields {
112112
/// use stac::{Item, extensions::{Projection, Extensions}};
113113
/// let mut item = Item::new("an-id");
114114
/// assert!(!item.has_extension::<Projection>());
115-
/// let projection = Projection { epsg: Some(4326), ..Default::default() };
115+
/// let projection = Projection { code: Some("EPSG:4326".to_string()), ..Default::default() };
116116
/// item.set_extension(projection).unwrap();
117117
/// assert!(item.has_extension::<Projection>());
118118
/// ```
@@ -132,7 +132,7 @@ pub trait Extensions: Fields {
132132
/// use stac::{Item, extensions::{Projection, Extensions}};
133133
/// let item: Item = stac::read("examples/extensions-collection/proj-example/proj-example.json").unwrap();
134134
/// let projection: Projection = item.extension().unwrap().unwrap();
135-
/// assert_eq!(projection.epsg.unwrap(), 32614);
135+
/// assert_eq!(projection.code.unwrap(), "EPSG:32614");
136136
/// ```
137137
fn extension<E: Extension>(&self) -> Result<Option<E>> {
138138
if self.has_extension::<E>() {
@@ -165,7 +165,7 @@ pub trait Extensions: Fields {
165165
/// ```
166166
/// use stac::{Item, extensions::{Projection, Extensions}};
167167
/// let mut item = Item::new("an-id");
168-
/// let projection = Projection { epsg: Some(4326), ..Default::default() };
168+
/// let projection = Projection { code: Some("EPSG:4326".to_string()), ..Default::default() };
169169
/// item.set_extension(projection).unwrap();
170170
/// ```
171171
fn set_extension<E: Extension>(&mut self, extension: E) -> Result<()> {
@@ -229,31 +229,17 @@ mod tests {
229229
assert!(asset.has_extension::<Raster>());
230230
let mut item = Item::new("an-id");
231231
let _ = item.assets.insert("data".to_string(), asset);
232-
233-
// TODO how do we let items know about what their assets are doing?
234-
// Maybe we don't?
235-
// assert!(item.has_extension::<Raster>());
236-
// let item = serde_json::to_value(item).unwrap();
237-
// assert_eq!(
238-
// item.as_object()
239-
// .unwrap()
240-
// .get("stac_extensions")
241-
// .unwrap()
242-
// .as_array()
243-
// .unwrap(),
244-
// &vec!["https://stac-extensions.github.io/raster/v1.1.0/schema.json"]
245-
// );
246232
}
247233

248234
#[test]
249235
fn remove_extension() {
250236
let mut item = Item::new("an-id");
251237
item.extensions
252-
.push("https://stac-extensions.github.io/projection/v1.1.0/schema.json".to_string());
238+
.push("https://stac-extensions.github.io/projection/v2.0.0/schema.json".to_string());
253239
let _ = item
254240
.properties
255241
.additional_fields
256-
.insert("proj:epsg".to_string(), json!(4326));
242+
.insert("proj:code".to_string(), json!("EPSG:4326"));
257243
assert!(item.has_extension::<Projection>());
258244
item.remove_extension::<Projection>();
259245
assert!(!item.has_extension::<Projection>());

core/src/extensions/projection.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use serde_json::{Map, Value};
1010
pub struct Projection {
1111
/// EPSG code of the datasource
1212
#[serde(skip_serializing_if = "Option::is_none")]
13-
pub epsg: Option<i32>,
13+
pub code: Option<String>,
1414

1515
/// WKT2 string representing the Coordinate Reference System (CRS) that the
1616
/// proj:geometry and proj:bbox fields represent
@@ -56,14 +56,14 @@ pub struct Centroid {
5656
impl Projection {
5757
/// Returns this projection's bounds in WGS84.
5858
///
59-
/// Requires one of the crs fields to be set (epsg, wkt2, or projjson) as well as a bbox.
59+
/// Requires one of the crs fields to be set (code, wkt2, or projjson) as well as a bbox.
6060
///
6161
/// # Examples
6262
///
6363
/// ```
6464
/// use stac::extensions::Projection;
6565
/// let projection = Projection {
66-
/// epsg: Some(32621),
66+
/// code: Some("EPSG:32621".to_string()),
6767
/// bbox: Some(vec![
6868
/// 373185.0,
6969
/// 8019284.949381611,
@@ -109,8 +109,8 @@ impl Projection {
109109
use crate::Error;
110110
use gdal::spatial_ref::SpatialRef;
111111

112-
if let Some(epsg) = self.epsg {
113-
SpatialRef::from_epsg(epsg.try_into()?)
112+
if let Some(code) = self.code.as_deref() {
113+
SpatialRef::from_definition(code)
114114
.map(Some)
115115
.map_err(Error::from)
116116
} else if let Some(wkt) = self.wkt2.as_ref() {
@@ -127,19 +127,20 @@ impl Projection {
127127

128128
impl Extension for Projection {
129129
const IDENTIFIER: &'static str =
130-
"https://stac-extensions.github.io/projection/v1.1.0/schema.json";
130+
"https://stac-extensions.github.io/projection/v2.0.0/schema.json";
131131
const PREFIX: &'static str = "proj";
132132
}
133133

134134
#[cfg(test)]
135135
mod tests {
136+
use super::Projection;
137+
use crate::{Extensions, Item};
138+
136139
#[cfg(feature = "gdal")]
137140
#[test]
138141
fn axis_order() {
139-
use super::Projection;
140-
141142
let projection = Projection {
142-
epsg: Some(32621),
143+
code: Some("EPSG:32621".to_string()),
143144
bbox: Some(vec![
144145
373185.0,
145146
8019284.949381611,
@@ -156,4 +157,12 @@ mod tests {
156157
);
157158
assert!((bounds.ymin() - 72.229798).abs() < 0.1);
158159
}
160+
161+
#[test]
162+
fn example() {
163+
let item: Item =
164+
crate::read("examples/extensions-collection/proj-example/proj-example.json").unwrap();
165+
let projection = item.extension::<Projection>().unwrap().unwrap();
166+
assert_eq!(projection.code.unwrap(), "EPSG:32614");
167+
}
159168
}

core/src/fields.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ pub trait Fields {
100100
///
101101
/// ```
102102
/// use stac::{Fields, Item, extensions::Projection};
103-
/// let projection = Projection { epsg: Some(4326), ..Default::default() };
103+
/// let projection = Projection { code: Some("EPSG:4326".to_string()), ..Default::default() };
104104
/// let mut item = Item::new("an-id");
105105
/// item.set_fields_with_prefix("proj", projection); // Prefer `Extensions::set_extension`
106106
/// ```
@@ -122,7 +122,7 @@ pub trait Fields {
122122
///
123123
/// ```
124124
/// use stac::{Fields, Item, extensions::Projection};
125-
/// let projection = Projection { epsg: Some(4326), ..Default::default() };
125+
/// let projection = Projection { code: Some("EPSG:4326".to_string()), ..Default::default() };
126126
/// let mut item = Item::new("an-id");
127127
/// item.remove_fields_with_prefix("proj"); // Prefer `Extensions::remove_extension`
128128
/// ```

core/src/gdal.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,13 @@ fn update_asset(
123123
.map(|auth_name| auth_name == "EPSG")
124124
.unwrap_or_default()
125125
{
126-
projection.epsg = spatial_ref.auth_code().ok();
126+
projection.code = spatial_ref
127+
.auth_code()
128+
.map(|code| format!("EPSG:{}", code))
129+
.ok();
127130
}
128131
// FIXME Don't know how to get WKT2 out of the gdal crate yet.
129-
if projection.epsg.is_none() {
132+
if projection.code.is_none() {
130133
projection.projjson = spatial_ref
131134
.to_projjson()
132135
.ok()
@@ -223,7 +226,7 @@ mod tests {
223226
.unwrap();
224227
super::update_item(&mut item, false, true).unwrap();
225228
let projection: Projection = item.extension().unwrap().unwrap();
226-
assert_eq!(projection.epsg.unwrap(), 32621);
229+
assert_eq!(projection.code.unwrap(), "EPSG:32621");
227230
assert_eq!(
228231
projection.bbox.unwrap(),
229232
vec![373185.0, 8019284.949381611, 639014.9492102272, 8286015.0]

core/src/lib.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
//! use stac::{Value, Migrate, Version};
5757
//!
5858
//! let value: Value = stac::read("examples/simple-item.json").unwrap();
59-
//! let value = value.migrate(&Version::v1_1_0_beta_1).unwrap();
59+
//! let value = value.migrate(&Version::v1_1_0).unwrap();
6060
//! ```
6161
//!
6262
//! # Input and output
@@ -204,7 +204,7 @@ pub use {
204204
};
205205

206206
/// The default STAC version of this library.
207-
pub const STAC_VERSION: Version = Version::v1_0_0;
207+
pub const STAC_VERSION: Version = Version::v1_1_0;
208208

209209
/// Custom [Result](std::result::Result) type for this crate.
210210
pub type Result<T> = std::result::Result<T, Error>;
@@ -385,7 +385,7 @@ mod tests {
385385
($function:ident, $filename:expr, $object:ident) => {
386386
#[test]
387387
fn $function() {
388-
use assert_json_diff::assert_json_eq;
388+
use assert_json_diff::{assert_json_matches, CompareMode, Config, NumericMode};
389389
use chrono::{DateTime, Utc};
390390
use serde_json::Value;
391391
use std::{fs::File, io::BufReader};
@@ -439,7 +439,11 @@ mod tests {
439439
}
440440
let object: $object = serde_json::from_value(before.clone()).unwrap();
441441
let after = serde_json::to_value(object).unwrap();
442-
assert_json_eq!(before, after);
442+
assert_json_matches!(
443+
before,
444+
after,
445+
Config::new(CompareMode::Strict).numeric_mode(NumericMode::AssumeFloat)
446+
);
443447
}
444448
};
445449
}

0 commit comments

Comments
 (0)