diff --git a/README.md b/README.md index 663409d..7c5bb53 100644 --- a/README.md +++ b/README.md @@ -64,11 +64,11 @@ In order to configure the behavior of the service, there is couple of environmen MERCATOR_ALLOWED_ORIGINS="http://localhost:3200,http://localhost:3201, http://localhost:3202" ``` -* `MERCATOR_IMPORT_DATA`: Provide the data set to expose. +* `MERCATOR_DATA`: Provide the root folder of the data sets to expose. Complete example of a run: ```sh -RUST_LOG="warn,actix_web=info,mercator_service=trace" MERCATOR_IMPORT_DATA="1000k" MERCATOR_ALLOWED_ORIGINS="http://localhost:3200,http://localhost:3201, http://localhost:3202" cargo run --release +RUST_LOG="warn,actix_web=info,mercator_service=trace" MERCATOR_DATA="../mercator_indexer" MERCATOR_ALLOWED_ORIGINS="http://localhost:3200,http://localhost:3201, http://localhost:3202" cargo run --release ``` ## Documentation diff --git a/src/rest_api/actions.rs b/src/rest_api/actions.rs index 056d476..f047f4e 100644 --- a/src/rest_api/actions.rs +++ b/src/rest_api/actions.rs @@ -15,7 +15,7 @@ use super::HandlerResult; #[derive(Debug, Deserialize)] pub struct Query { query: String, - resolution: Option>, // None means automatic selection, based on ViewPort + resolution: Option>, // None means automatic selection, based on ViewPort view_port: Option<(Vec, Vec)>, } @@ -24,7 +24,7 @@ impl Query { &self.query } - pub fn resolution(&self) -> Option> { + pub fn resolution(&self) -> Option> { self.resolution.clone() } @@ -54,7 +54,13 @@ fn query((parameters, state): (Json, Data>)) -> Handl .core_keys() .iter() .flat_map(|core| { - match context.query(query, core, parameters.volume(), parameters.resolution()) { + match context.query( + query, + core, + parameters.volume(), + ¶meters.view_port, + parameters.resolution(), + ) { Err(_) => vec![], // FIXME: Return errors here instead!! Ok(objects) => to_spatial_objects(context.db(), objects), } diff --git a/src/rest_api/cores.rs b/src/rest_api/cores.rs index ae186b4..9c9f711 100644 --- a/src/rest_api/cores.rs +++ b/src/rest_api/cores.rs @@ -42,13 +42,13 @@ fn post((parameters, state): (Json, Data>)) -> Hand Some(filter) => { // Retrieve the list of core ids. let mut results = HashSet::new(); - for core in db.core_keys() { match context.filter( filter, core, space.clone(), parameters.volume(), + ¶meters.view_port, parameters.resolution(), ) { Err(e) => return error_422(e), diff --git a/src/rest_api/mod.rs b/src/rest_api/mod.rs index 34bbf0d..776f8f8 100644 --- a/src/rest_api/mod.rs +++ b/src/rest_api/mod.rs @@ -29,6 +29,7 @@ use actix_web::App; use actix_web::Either; use actix_web::HttpResponse; use actix_web::HttpServer; +use mercator_db::space::Shape; #[cfg(feature = "static-error-pages")] pub use helpers_static_pages::*; @@ -47,7 +48,7 @@ pub struct Filters { filters: Option, ids_only: Option, space: Option, // Output space, None, means each object in its own original space - resolution: Option>, // None means automatic selection, based on ViewPort + resolution: Option>, // None means automatic selection, based on ViewPort view_port: Option<(Vec, Vec)>, } @@ -75,14 +76,16 @@ impl Filters { Ok(self.space.clone()) } - pub fn resolution(&self) -> Option> { + pub fn resolution(&self) -> Option> { self.resolution.clone() } pub fn volume(&self) -> Option { match &self.view_port { None => None, - Some(_view) => None, // FIXME: Need to move the Volume functions from mercator_parser to mercator_db. + Some((low, high)) => { + Some(Shape::BoundingBox(low.clone().into(), high.clone().into()).volume()) + } } } } diff --git a/src/rest_api/spaces.rs b/src/rest_api/spaces.rs index 4e1130b..db370c3 100644 --- a/src/rest_api/spaces.rs +++ b/src/rest_api/spaces.rs @@ -49,6 +49,7 @@ fn post((parameters, state): (Json, Data>)) -> Hand core, space.clone(), parameters.volume(), + ¶meters.view_port, parameters.resolution(), ) { Err(e) => return error_422(e), diff --git a/src/rest_api/spatial_object.rs b/src/rest_api/spatial_object.rs index de25a1d..d3ff799 100644 --- a/src/rest_api/spatial_object.rs +++ b/src/rest_api/spatial_object.rs @@ -30,8 +30,10 @@ fn get((path, state): (Path<(String, String)>, Data>)) -> Ha let parameters = CoreQueryParameters { db, output_space: None, - threshold_volume: Some(0.0), // Empty volume => Highest resolution possible - resolution: None, + // Enforce highest resolution index. + threshold_volume: None, + view_port: &None, + resolution: Some(vec![0]), }; match db.core(core) { diff --git a/src/rest_api/spatial_objects.rs b/src/rest_api/spatial_objects.rs index 370a816..86f79e8 100644 --- a/src/rest_api/spatial_objects.rs +++ b/src/rest_api/spatial_objects.rs @@ -43,6 +43,7 @@ fn post( db, output_space: space.as_ref().map(String::as_str), threshold_volume: parameters.volume(), + view_port: ¶meters.view_port, resolution: parameters.resolution(), }; @@ -64,6 +65,7 @@ fn post( &core_id, space, parameters.volume(), + ¶meters.view_port, parameters.resolution(), ) { Err(e) => error_422(e), diff --git a/src/shared_state.rs b/src/shared_state.rs index 4139166..7945fac 100644 --- a/src/shared_state.rs +++ b/src/shared_state.rs @@ -34,27 +34,29 @@ impl SharedState { pub fn filter( &self, - input: &str, + filter: &str, core: &str, output_space: Option, volume: Option, - resolution: Option>, + view_port: &Option<(Vec, Vec)>, + resolution: Option>, ) -> mercator_db::ResultSet { let parser = self.filter_parser(); let parse; - let parameters = CoreQueryParameters { db: self.db(), output_space: output_space.as_ref().map(String::as_str), threshold_volume: volume, + view_port, resolution, }; // Parse Input { info_time!("Parsing"); - parse = parser.parse(input); + parse = parser.parse(filter); } + match parse { Err(e) => { debug!("Parsing failed: \n{:?}", e); @@ -92,10 +94,11 @@ impl SharedState { pub fn query( &self, - input: &str, + query: &str, core: &str, volume: Option, - resolution: Option>, + view_port: &Option<(Vec, Vec)>, + resolution: Option>, ) -> mercator_db::ResultSet { let parser = self.query_parser(); let parse; @@ -103,13 +106,14 @@ impl SharedState { db: self.db(), output_space: None, threshold_volume: volume, + view_port, resolution, }; // Parse Input { info_time!("Parsing"); - parse = parser.parse(input); + parse = parser.parse(query); } match parse { Err(e) => { diff --git a/static/api/v0.2.yaml b/static/api/v0.2.yaml index de4d360..841781f 100644 --- a/static/api/v0.2.yaml +++ b/static/api/v0.2.yaml @@ -115,7 +115,7 @@ paths: delete: tags: [Spaces] summary: > - Delete mulltiple spaces at a time. + Delete multiple spaces at a time. Each reference space can only be removed if and only if there are no spatial objects left referencing it. @@ -249,7 +249,7 @@ paths: delete: tags: [Cores] summary: > - Delete mulltiple Cores at a time. This also removes all the + Delete multiple Cores at a time. This also removes all the Spatial Objects tied to these cores. operationId: delete_cores parameters: @@ -401,7 +401,7 @@ paths: delete: tags: [Spatial Objects] summary: > - Delete mulltiple spatial objects at a time. + Delete multiple spatial objects at a time. operationId: delete_spatial_objects parameters: - $ref: '#/parameters/SpatialObjectIds' @@ -682,6 +682,20 @@ parameters: ids_only: type: boolean default: false + space: + type: string + resolution: + type: array + items: + type: number + minimum: 0 + format: int32 + view_port: + type: array + items: + type: array + items: + type: number Query: name: query @@ -690,7 +704,22 @@ parameters: description: > For more about the query syntax, please refer to `FIXME: URL` http://repo/queries.g4. schema: - type: string + type: object + properties: + query: + type: string + resolution: + type: array + items: + type: number + minimum: 0 + format: int32 + view_port: + type: array + items: + type: array + items: + type: number responses: Space200: