Add support for view port & resolution selection.

This commit is contained in:
2019-10-15 19:58:27 +02:00
parent 75b3529eb9
commit 5cbd2a0b69
9 changed files with 69 additions and 22 deletions

View File

@@ -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

View File

@@ -15,7 +15,7 @@ use super::HandlerResult;
#[derive(Debug, Deserialize)]
pub struct Query {
query: String,
resolution: Option<Vec<u64>>, // None means automatic selection, based on ViewPort
resolution: Option<Vec<u32>>, // None means automatic selection, based on ViewPort
view_port: Option<(Vec<f64>, Vec<f64>)>,
}
@@ -24,7 +24,7 @@ impl Query {
&self.query
}
pub fn resolution(&self) -> Option<Vec<u64>> {
pub fn resolution(&self) -> Option<Vec<u32>> {
self.resolution.clone()
}
@@ -54,7 +54,13 @@ fn query((parameters, state): (Json<Query>, Data<RwLock<SharedState>>)) -> Handl
.core_keys()
.iter()
.flat_map(|core| {
match context.query(query, core, parameters.volume(), parameters.resolution()) {
match context.query(
query,
core,
parameters.volume(),
&parameters.view_port,
parameters.resolution(),
) {
Err(_) => vec![], // FIXME: Return errors here instead!!
Ok(objects) => to_spatial_objects(context.db(), objects),
}

View File

@@ -42,13 +42,13 @@ fn post((parameters, state): (Json<Filters>, Data<RwLock<SharedState>>)) -> 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(),
&parameters.view_port,
parameters.resolution(),
) {
Err(e) => return error_422(e),

View File

@@ -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<String>,
ids_only: Option<bool>,
space: Option<String>, // Output space, None, means each object in its own original space
resolution: Option<Vec<u64>>, // None means automatic selection, based on ViewPort
resolution: Option<Vec<u32>>, // None means automatic selection, based on ViewPort
view_port: Option<(Vec<f64>, Vec<f64>)>,
}
@@ -75,14 +76,16 @@ impl Filters {
Ok(self.space.clone())
}
pub fn resolution(&self) -> Option<Vec<u64>> {
pub fn resolution(&self) -> Option<Vec<u32>> {
self.resolution.clone()
}
pub fn volume(&self) -> Option<f64> {
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())
}
}
}
}

View File

@@ -49,6 +49,7 @@ fn post((parameters, state): (Json<Filters>, Data<RwLock<SharedState>>)) -> Hand
core,
space.clone(),
parameters.volume(),
&parameters.view_port,
parameters.resolution(),
) {
Err(e) => return error_422(e),

View File

@@ -30,8 +30,10 @@ fn get((path, state): (Path<(String, String)>, Data<RwLock<SharedState>>)) -> 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) {

View File

@@ -43,6 +43,7 @@ fn post(
db,
output_space: space.as_ref().map(String::as_str),
threshold_volume: parameters.volume(),
view_port: &parameters.view_port,
resolution: parameters.resolution(),
};
@@ -64,6 +65,7 @@ fn post(
&core_id,
space,
parameters.volume(),
&parameters.view_port,
parameters.resolution(),
) {
Err(e) => error_422(e),

View File

@@ -34,27 +34,29 @@ impl SharedState {
pub fn filter(
&self,
input: &str,
filter: &str,
core: &str,
output_space: Option<String>,
volume: Option<f64>,
resolution: Option<Vec<u64>>,
view_port: &Option<(Vec<f64>, Vec<f64>)>,
resolution: Option<Vec<u32>>,
) -> 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<f64>,
resolution: Option<Vec<u64>>,
view_port: &Option<(Vec<f64>, Vec<f64>)>,
resolution: Option<Vec<u32>>,
) -> 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) => {

View File

@@ -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: 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: