From d3de38079608e4589876be9d63e3cbfce09a7332 Mon Sep 17 00:00:00 2001 From: sharkAndshark Date: Mon, 18 Sep 2023 11:14:04 +0800 Subject: [PATCH] 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, }) }