From d3de38079608e4589876be9d63e3cbfce09a7332 Mon Sep 17 00:00:00 2001 From: sharkAndshark Date: Mon, 18 Sep 2023 11:14:04 +0800 Subject: [PATCH 1/5] Add clip_geom,buffer under auto_publish conf --- martin/src/pg/config.rs | 6 ++++++ martin/src/pg/configurator.rs | 37 ++++++++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/martin/src/pg/config.rs b/martin/src/pg/config.rs index 85df68e91..ee5ea0db1 100644 --- a/martin/src/pg/config.rs +++ b/martin/src/pg/config.rs @@ -82,6 +82,12 @@ pub struct PgCfgPublishType { #[serde(skip_serializing_if = "Option::is_none")] #[serde(alias = "id_column")] pub id_columns: Option>, + + #[serde(skip_serializing_if = "Option::is_none")] + pub clip_geom: Option, + + #[serde(skip_serializing_if = "Option::is_none")] + pub buffer: Option, } impl PgConfig { diff --git a/martin/src/pg/configurator.rs b/martin/src/pg/configurator.rs index f4290a54a..0bf43ae8a 100755 --- a/martin/src/pg/configurator.rs +++ b/martin/src/pg/configurator.rs @@ -28,6 +28,8 @@ pub struct PgBuilderAuto { source_id_format: String, schemas: Option>, id_columns: Option>, + clip_geom: Option, + buffer: Option, } #[derive(Debug)] @@ -145,7 +147,7 @@ impl PgBuilder { continue; }; db_inf.srid = srid; - update_id_column(&id2, &mut db_inf, auto_tables); + update_auto_fields(&id2, &mut db_inf, auto_tables); info!("Discovered source {id2} from {}", summary(&db_inf)); pending.push(table_to_query( id2, @@ -262,6 +264,19 @@ impl PgBuilder { } } +// Should we borrow the hand of tableinfo to update its status, like tableinfo.update(...) +fn update_auto_fields(id: &str, inf: &mut TableInfo, auto_tables: &PgBuilderAuto) { + update_id_column(id, inf, auto_tables); + + // for fine tuning the auto-discovered sources, maybe there will be more auto fileds be setted/merged here + if auto_tables.buffer.is_some() { + inf.buffer = auto_tables.buffer; + } + if auto_tables.clip_geom.is_some() { + inf.clip_geom = auto_tables.clip_geom; + } +} + /// Try to find any ID column in a list of table columns (properties) that match one of the given `id_column` values. /// If found, modify `id_column` value on the table info. fn update_id_column(id: &str, inf: &mut TableInfo, auto_tables: &PgBuilderAuto) { @@ -317,6 +332,8 @@ fn new_auto_publish(config: &PgConfig, is_function: bool) -> Option Option default(merge_opt_hs(&a.from_schemas, &None)), BoolOrObject::Bool(false) => None, @@ -420,6 +453,8 @@ mod tests { source_id_format: source_id_format.to_string(), schemas: schemas.map(|s| s.iter().map(|s| (*s).to_string()).collect()), id_columns: None, + clip_geom: None, + buffer: None, }) } From 48c467b246d1bd2042b5c6f9a3b4b1d66a39a39c Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Thu, 21 Sep 2023 00:05:08 -0400 Subject: [PATCH 2/5] add extent, fix a few things --- martin/src/pg/config.rs | 16 +++++++------- martin/src/pg/configurator.rs | 30 +++++++++++++++---------- martin/src/pg/table_source.rs | 6 ++--- tests/config.yaml | 3 +++ tests/expected/generated_config.yaml | 33 ---------------------------- tests/expected/given_config.yaml | 15 ++++++++----- 6 files changed, 42 insertions(+), 61 deletions(-) diff --git a/martin/src/pg/config.rs b/martin/src/pg/config.rs index ee5ea0db1..8d4207538 100644 --- a/martin/src/pg/config.rs +++ b/martin/src/pg/config.rs @@ -82,12 +82,12 @@ pub struct PgCfgPublishType { #[serde(skip_serializing_if = "Option::is_none")] #[serde(alias = "id_column")] pub id_columns: Option>, - #[serde(skip_serializing_if = "Option::is_none")] pub clip_geom: Option, - #[serde(skip_serializing_if = "Option::is_none")] pub buffer: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub extent: Option, } impl PgConfig { @@ -202,9 +202,9 @@ mod tests { minzoom: 0 maxzoom: 30 bounds: [-180.0, -90.0, 180.0, 90.0] - extent: 4096 - buffer: 64 - clip_geom: true + extent: 2048 + buffer: 10 + clip_geom: false geometry_type: GEOMETRY properties: gid: int4 @@ -233,9 +233,9 @@ mod tests { minzoom: Some(0), maxzoom: Some(30), bounds: Some([-180, -90, 180, 90].into()), - extent: Some(4096), - buffer: Some(64), - clip_geom: Some(true), + extent: Some(2048), + buffer: Some(10), + clip_geom: Some(false), geometry_type: some("GEOMETRY"), properties: Some(HashMap::from([( "gid".to_string(), diff --git a/martin/src/pg/configurator.rs b/martin/src/pg/configurator.rs index 0bf43ae8a..d5fbf77d0 100755 --- a/martin/src/pg/configurator.rs +++ b/martin/src/pg/configurator.rs @@ -30,6 +30,7 @@ pub struct PgBuilderAuto { id_columns: Option>, clip_geom: Option, buffer: Option, + extent: Option, } #[derive(Debug)] @@ -264,22 +265,19 @@ impl PgBuilder { } } -// Should we borrow the hand of tableinfo to update its status, like tableinfo.update(...) fn update_auto_fields(id: &str, inf: &mut TableInfo, auto_tables: &PgBuilderAuto) { - update_id_column(id, inf, auto_tables); - - // for fine tuning the auto-discovered sources, maybe there will be more auto fileds be setted/merged here - if auto_tables.buffer.is_some() { + if inf.clip_geom.is_none() { + inf.clip_geom = auto_tables.clip_geom; + } + if inf.buffer.is_none() { inf.buffer = auto_tables.buffer; } - if auto_tables.clip_geom.is_some() { - inf.clip_geom = auto_tables.clip_geom; + if inf.extent.is_none() { + inf.extent = auto_tables.extent; } -} -/// Try to find any ID column in a list of table columns (properties) that match one of the given `id_column` values. -/// If found, modify `id_column` value on the table info. -fn update_id_column(id: &str, inf: &mut TableInfo, auto_tables: &PgBuilderAuto) { + // Try to find any ID column in a list of table columns (properties) that match one of the given `id_column` values. + // If found, modify `id_column` value on the table info. let Some(props) = inf.properties.as_mut() else { return; }; @@ -334,6 +332,7 @@ fn new_auto_publish(config: &PgConfig, is_function: bool) -> Option Option default(merge_opt_hs(&a.from_schemas, &None)), BoolOrObject::Bool(false) => None, @@ -455,6 +462,7 @@ mod tests { id_columns: None, clip_geom: None, buffer: None, + extent: None, }) } diff --git a/martin/src/pg/table_source.rs b/martin/src/pg/table_source.rs index 38fb11618..05e161ce5 100644 --- a/martin/src/pg/table_source.rs +++ b/martin/src/pg/table_source.rs @@ -54,9 +54,9 @@ pub async fn query_available_tables(pool: &PgPool) -> Result Date: Thu, 21 Sep 2023 00:21:01 -0400 Subject: [PATCH 3/5] defaults --- martin/src/pg/table_source.rs | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/martin/src/pg/table_source.rs b/martin/src/pg/table_source.rs index 05e161ce5..9fe61a913 100644 --- a/martin/src/pg/table_source.rs +++ b/martin/src/pg/table_source.rs @@ -44,25 +44,16 @@ pub async fn query_available_tables(pool: &PgPool) -> Result Date: Thu, 21 Sep 2023 12:44:50 +0800 Subject: [PATCH 4/5] little bit format --- martin/src/pg/config.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/martin/src/pg/config.rs b/martin/src/pg/config.rs index 8d4207538..936e89134 100644 --- a/martin/src/pg/config.rs +++ b/martin/src/pg/config.rs @@ -73,19 +73,24 @@ pub struct PgCfgPublishType { #[serde(skip_serializing_if = "Option::is_none")] #[serde(alias = "from_schema")] pub from_schemas: Option>, + #[serde(skip_serializing_if = "Option::is_none")] #[serde(alias = "id_format")] pub source_id_format: Option, + /// A table column to use as the feature ID /// If a table has no column with this name, `id_column` will not be set for that table. /// If a list of strings is given, the first found column will be treated as a feature ID. #[serde(skip_serializing_if = "Option::is_none")] #[serde(alias = "id_column")] pub id_columns: Option>, + #[serde(skip_serializing_if = "Option::is_none")] pub clip_geom: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub buffer: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub extent: Option, } From 5b1392472007e30572007fab0bb19d3add65137c Mon Sep 17 00:00:00 2001 From: sharkAndshark Date: Thu, 21 Sep 2023 13:20:40 +0800 Subject: [PATCH 5/5] add doc --- docs/src/config-file.md | 6 ++++++ martin/src/pg/config.rs | 5 ----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/docs/src/config-file.md b/docs/src/config-file.md index c10bc97c2..8fe58a638 100644 --- a/docs/src/config-file.md +++ b/docs/src/config-file.md @@ -71,6 +71,12 @@ postgres: # If a table has no column with this name, `id_column` will not be set for that table. # If a list of strings is given, the first found column will be treated as a feature ID. id_columns: feature_id + # Boolean to control if geometries should be clipped or encoded as is, optional, default to true + clip_geom: true + # Buffer distance in tile coordinate space to optionally clip geometries, optional, default to 64 + buffer: 64 + # Tile extent in tile coordinate space, optional, default to 4096 + extent: 4096 functions: # Optionally set how source ID should be generated based on the function's name and schema source_id_format: '{schema}.{function}' diff --git a/martin/src/pg/config.rs b/martin/src/pg/config.rs index 936e89134..8d4207538 100644 --- a/martin/src/pg/config.rs +++ b/martin/src/pg/config.rs @@ -73,24 +73,19 @@ pub struct PgCfgPublishType { #[serde(skip_serializing_if = "Option::is_none")] #[serde(alias = "from_schema")] pub from_schemas: Option>, - #[serde(skip_serializing_if = "Option::is_none")] #[serde(alias = "id_format")] pub source_id_format: Option, - /// A table column to use as the feature ID /// If a table has no column with this name, `id_column` will not be set for that table. /// If a list of strings is given, the first found column will be treated as a feature ID. #[serde(skip_serializing_if = "Option::is_none")] #[serde(alias = "id_column")] pub id_columns: Option>, - #[serde(skip_serializing_if = "Option::is_none")] pub clip_geom: Option, - #[serde(skip_serializing_if = "Option::is_none")] pub buffer: Option, - #[serde(skip_serializing_if = "Option::is_none")] pub extent: Option, }