Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Codesprint #5

Merged
merged 4 commits into from
May 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 17 additions & 37 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added data/ogcapi.qgz
Binary file not shown.
4 changes: 2 additions & 2 deletions ogcapi-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ impl Pagination<StacEntity> for StacEntities {

self.links.append(&mut children);

return Ok(Some(StacEntity::Catalog(catalog)));
return Ok(Some(StacEntity::Catalog(Box::new(catalog))));
}
Some("Collection") => {
let mut collection = serde_json::from_value::<Collection>(entity.clone())
Expand Down Expand Up @@ -271,7 +271,7 @@ impl Pagination<StacEntity> for StacEntities {

self.links.append(&mut children);

return Ok(Some(StacEntity::Item(item)));
return Ok(Some(StacEntity::Item(Box::new(item))));
}
_ => return Err(Error::ClientError("Unknown STAC entity!".to_string())),
};
Expand Down
2 changes: 1 addition & 1 deletion ogcapi-drivers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ http = "0.2.7"
rink-core = { version = "0.6.2", optional = true }
serde_json = "1.0.81"
sqlx = { version = "0.5.13", optional = true, features = ["runtime-tokio-rustls", "postgres", "json"] }
tokio = { version = "1.18.1", features = ["full"] }
tokio = { version = "1.18.2", features = ["full"] }
url = { version = "2.2.2", optional = true }

ogcapi-types = { path = "../ogcapi-types" }
5 changes: 3 additions & 2 deletions ogcapi-drivers/src/postgres/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,14 @@ impl CollectionTransactions for Db {
async fn list_collections(&self) -> Result<Collections, anyhow::Error> {
let collections = sqlx::query_scalar!(
r#"
SELECT array_to_json(array_agg(collection)) as "collections!: sqlx::types::Json<Vec<Collection>>"
SELECT array_to_json(array_agg(collection)) as "collections: sqlx::types::Json<Vec<Collection>>"
FROM meta.collections
"#)
.fetch_one(&self.pool)
.await?;

let mut collections = Collections::new(collections.0);
let collections = collections.map(|c| c.0).unwrap_or_default();
let mut collections = Collections::new(collections);
collections.number_matched = collections.number_returned;

Ok(collections)
Expand Down
7 changes: 4 additions & 3 deletions ogcapi-drivers/src/postgres/edr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl EdrQuerier for Db {
)
}
}
QueryType::Corridor => todo!(),
QueryType::Corridor | QueryType::Locations => unimplemented!(),
};

let properties = if let Some(parameters) = &query.parameter_name {
Expand Down Expand Up @@ -128,7 +128,7 @@ impl EdrQuerier for Db {
.await?
.rows_affected();

let features: Json<Vec<Feature>> = sqlx::query_scalar(&format!(
let features: Option<Json<Vec<Feature>>> = sqlx::query_scalar(&format!(
r#"
SELECT array_to_json(array_agg(row_to_json(t)))
FROM ( {} ) t
Expand All @@ -139,7 +139,8 @@ impl EdrQuerier for Db {
.fetch_one(&self.pool)
.await?;

let mut fc = FeatureCollection::new(features.0);
let features = features.map(|f| f.0).unwrap_or_default();
let mut fc = FeatureCollection::new(features);
fc.number_matched = Some(number_matched);

Ok(fc)
Expand Down
32 changes: 14 additions & 18 deletions ogcapi-drivers/src/postgres/feature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ impl FeatureTransactions for Db {
let id: (String,) = sqlx::query_as(&format!(
r#"
INSERT INTO items.{0} (
type,
properties,
geom,
links
) VALUES ($1, $2, ST_GeomFromGeoJSON($3), $4)
) VALUES (
$1 -> 'properties',
ST_GeomFromGeoJSON($1 -> 'geometry'),
$1 -> 'links'
)
RETURNING id
"#,
&collection
))
.bind(&feature.r#type)
.bind(serde_json::to_value(&feature.properties)?)
.bind(serde_json::to_value(&feature.geometry)?)
.bind(serde_json::to_value(&feature.links)?)
.bind(serde_json::to_value(&feature)?)
.fetch_one(&self.pool)
.await?;

Expand Down Expand Up @@ -74,19 +74,14 @@ impl FeatureTransactions for Db {
r#"
UPDATE items.{0}
SET
type = $2,
properties = $3,
geom = ST_GeomFromGeoJSON($4),
links = $5
WHERE id = $1
properties = $1 -> 'properties',
geom = ST_GeomFromGeoJSON($1 -> 'geometry'),
links = $1 -> 'links'
WHERE id = $1 -> 'id'
"#,
&feature.collection.as_ref().unwrap()
))
.bind(&feature.id)
.bind(&feature.r#type)
.bind(serde_json::to_value(&feature.properties)?)
.bind(serde_json::to_value(&feature.geometry)?)
.bind(serde_json::to_value(&feature.links)?)
.bind(serde_json::to_value(&feature)?)
.execute(&self.pool)
.await?;

Expand Down Expand Up @@ -160,7 +155,7 @@ impl FeatureTransactions for Db {
.await?
.rows_affected();

let features: sqlx::types::Json<Vec<Feature>> = sqlx::query_scalar(&format!(
let features: Option<Json<Vec<Feature>>> = sqlx::query_scalar(&format!(
r#"
SELECT array_to_json(array_agg(row_to_json(t)))
FROM ( {} ) t
Expand All @@ -171,7 +166,8 @@ impl FeatureTransactions for Db {
.fetch_one(&self.pool)
.await?;

let mut fc = FeatureCollection::new(features.0);
let features = features.map(|f| f.0).unwrap_or_default();
let mut fc = FeatureCollection::new(features);
fc.number_matched = Some(number_matched);

Ok(fc)
Expand Down
5 changes: 3 additions & 2 deletions ogcapi-drivers/src/postgres/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ impl StyleTransactions for Db {
async fn list_styles(&self) -> Result<Styles, anyhow::Error> {
let styles = sqlx::query_scalar!(
r#"
SELECT array_to_json(array_agg(row_to_json(t))) as "styles!: Json<Vec<Style>>"
SELECT array_to_json(array_agg(row_to_json(t))) as "styles: Json<Vec<Style>>"
FROM (
SELECT id, title, links FROM meta.styles
) t
Expand All @@ -22,7 +22,8 @@ impl StyleTransactions for Db {
.fetch_one(&self.pool)
.await?;

Ok(Styles { styles: styles.0 })
let styles = styles.map(|s| s.0).unwrap_or_default();
Ok(Styles { styles })
}

async fn read_style(&self, id: &str) -> Result<Value, anyhow::Error> {
Expand Down
3 changes: 1 addition & 2 deletions ogcapi-drivers/src/postgres/tile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ impl TileTransactions for Db {

sql.push(format!(
r#"
SELECT ST_AsMVT(mvtgeom, '{0}', 4096, 'geom', 'id')
SELECT ST_AsMVT(mvtgeom, '{0}', 4096, 'geom')
FROM (
SELECT
ST_AsMVTGeom(ST_Transform(ST_Force2D(geom), 3857), ST_TileEnvelope($1, $3, $2), 4096, 64, TRUE) AS geom,
'{0}' as collection,
id,
properties
FROM items.{0}
WHERE geom && ST_Transform(ST_TileEnvelope($1, $3, $2, margin => (64.0 / 4096)), {1})
Expand Down
6 changes: 3 additions & 3 deletions ogcapi-services/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ stac = ["ogcapi-types/stac", "ogcapi-drivers/stac"]

[dependencies]
anyhow = "1.0.57"
axum = { version = "0.5.4", features = ["headers"] }
axum = { version = "0.5.5", features = ["headers"] }
clap = { version = "3.1.17", features = ["derive", "env"] }
dotenv = "0.15.0"
hyper = { version = "0.14.18", features = ["full"] }
Expand All @@ -27,9 +27,9 @@ serde_json = "1.0.81"
serde_yaml = "0.8.24"
serde_qs = "0.9.2"
thiserror = "1.0.31"
tokio = { version = "1.18.1", features = ["full"] }
tokio = { version = "1.18.2", features = ["full"] }
tower = "0.4.12"
tower-http = { version = "0.3.2", features = ["cors", "trace"] }
tower-http = { version = "0.3.3", features = ["cors", "trace"] }
tracing = "0.1.34"
tracing-subscriber = { version="0.3.11", features = ["env-filter"] }
url = { version = "2.2.2", features = ["serde"] }
Expand Down
Loading