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

Add clip_geom, buffer and extent under auto_publish conf #887

Merged
merged 6 commits into from
Sep 21, 2023
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
6 changes: 6 additions & 0 deletions docs/src/config-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}'
Expand Down
18 changes: 12 additions & 6 deletions martin/src/pg/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ pub struct PgCfgPublishType {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(alias = "id_column")]
pub id_columns: Option<OneOrMany<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub clip_geom: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub buffer: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub extent: Option<u32>,
}

impl PgConfig {
Expand Down Expand Up @@ -196,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
Expand Down Expand Up @@ -227,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(),
Expand Down
51 changes: 47 additions & 4 deletions martin/src/pg/configurator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ pub struct PgBuilderAuto {
source_id_format: String,
schemas: Option<HashSet<String>>,
id_columns: Option<Vec<String>>,
clip_geom: Option<bool>,
buffer: Option<u32>,
extent: Option<u32>,
}

#[derive(Debug)]
Expand Down Expand Up @@ -145,7 +148,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,
Expand Down Expand Up @@ -262,9 +265,19 @@ impl PgBuilder {
}
}

/// 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) {
fn update_auto_fields(id: &str, inf: &mut TableInfo, auto_tables: &PgBuilderAuto) {
if inf.clip_geom.is_none() {
inf.clip_geom = auto_tables.clip_geom;
}
if inf.buffer.is_none() {
inf.buffer = auto_tables.buffer;
}
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.
let Some(props) = inf.properties.as_mut() else {
return;
};
Expand Down Expand Up @@ -317,6 +330,9 @@ fn new_auto_publish(config: &PgConfig, is_function: bool) -> Option<PgBuilderAut
source_id_format: default_id_fmt(is_function),
schemas,
id_columns: None,
clip_geom: None,
buffer: None,
extent: None,
})
};

Expand All @@ -339,6 +355,30 @@ fn new_auto_publish(config: &PgConfig, is_function: bool) -> Option<PgBuilderAut
Some(ids.iter().cloned().collect())
}
}),
clip_geom: {
if is_function {
error!("Configuration parameter auto_publish.functions.clip_geom is not supported");
None
} else {
item.clip_geom
}
},
buffer: {
if is_function {
error!("Configuration parameter auto_publish.functions.buffer is not supported");
None
} else {
item.buffer
}
},
extent: {
if is_function {
error!("Configuration parameter auto_publish.functions.extent is not supported");
None
} else {
item.extent
}
},
}),
BoolOrObject::Bool(true) => default(merge_opt_hs(&a.from_schemas, &None)),
BoolOrObject::Bool(false) => None,
Expand Down Expand Up @@ -420,6 +460,9 @@ 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,
sharkAndshark marked this conversation as resolved.
Show resolved Hide resolved
extent: None,
})
}

Expand Down
11 changes: 1 addition & 10 deletions martin/src/pg/table_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,16 @@ pub async fn query_available_tables(pool: &PgPool) -> Result<SqlTableInfoMapMapM
};

let info = TableInfo {
layer_id: None,
schema,
table,
geometry_column: row.get("geom"),
geometry_index: row.get("geom_idx"),
is_view: row.get("is_view"),
id_column: None,
minzoom: None,
maxzoom: None,
srid: row.get("srid"), // casting i32 to u32?
extent: Some(DEFAULT_EXTENT),
buffer: Some(DEFAULT_BUFFER),
clip_geom: Some(DEFAULT_CLIP_GEOM),
geometry_type: row.get("type"),
properties: Some(json_to_hashmap(&row.get("properties"))),
prop_mapping: HashMap::new(),
unrecognized: HashMap::new(),
bounds: None,
tilejson,
..Default::default()
};

// Warn for missing geometry indices. Ignore views since those can't have indices
Expand Down
3 changes: 3 additions & 0 deletions tests/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ postgres:
tables:
from_schemas: autodetect
id_columns: [feat_id, big_feat_id]
clip_geom: false
buffer: 3
extent: 9000

# Associative arrays of table sources
tables:
Expand Down
33 changes: 0 additions & 33 deletions tests/expected/generated_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ postgres:
table: MixPoints
srid: 4326
geometry_column: Geom
extent: 4096
buffer: 64
clip_geom: true
geometry_type: POINT
properties:
Gid: int4
Expand All @@ -21,9 +18,6 @@ postgres:
table: auto_table
srid: 4326
geometry_column: geom
extent: 4096
buffer: 64
clip_geom: true
geometry_type: POINT
properties:
feat_id: int4
Expand All @@ -33,9 +27,6 @@ postgres:
table: bigint_table
srid: 4326
geometry_column: geom
extent: 4096
buffer: 64
clip_geom: true
geometry_type: POINT
properties:
big_feat_id: int8
Expand All @@ -45,9 +36,6 @@ postgres:
table: points1
srid: 4326
geometry_column: geom
extent: 4096
buffer: 64
clip_geom: true
geometry_type: POINT
properties:
gid: int4
Expand All @@ -56,9 +44,6 @@ postgres:
table: points1_vw
srid: 4326
geometry_column: geom
extent: 4096
buffer: 64
clip_geom: true
geometry_type: POINT
properties:
gid: int4
Expand All @@ -67,9 +52,6 @@ postgres:
table: points2
srid: 4326
geometry_column: geom
extent: 4096
buffer: 64
clip_geom: true
geometry_type: POINT
properties:
gid: int4
Expand All @@ -78,9 +60,6 @@ postgres:
table: points3857
srid: 3857
geometry_column: geom
extent: 4096
buffer: 64
clip_geom: true
geometry_type: POINT
properties:
gid: int4
Expand All @@ -89,9 +68,6 @@ postgres:
table: points_empty_srid
srid: 900913
geometry_column: geom
extent: 4096
buffer: 64
clip_geom: true
geometry_type: GEOMETRY
properties:
gid: int4
Expand All @@ -100,9 +76,6 @@ postgres:
table: table_source
srid: 4326
geometry_column: geom
extent: 4096
buffer: 64
clip_geom: true
geometry_type: GEOMETRY
properties:
gid: int4
Expand All @@ -111,9 +84,6 @@ postgres:
table: table_source_multiple_geom
srid: 4326
geometry_column: geom1
extent: 4096
buffer: 64
clip_geom: true
geometry_type: POINT
properties:
gid: int4
Expand All @@ -122,9 +92,6 @@ postgres:
table: table_source_multiple_geom
srid: 4326
geometry_column: geom2
extent: 4096
buffer: 64
clip_geom: true
geometry_type: POINT
properties:
gid: int4
Expand Down
15 changes: 9 additions & 6 deletions tests/expected/given_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ postgres:
id_columns:
- feat_id
- big_feat_id
clip_geom: false
buffer: 3
extent: 9000
tables:
MixPoints:
schema: MixedCase
Expand All @@ -37,9 +40,9 @@ postgres:
- -53.44747249115674
- 168.14061220360549
- 84.22411861475385
extent: 4096
buffer: 64
clip_geom: true
extent: 9000
buffer: 3
clip_geom: false
geometry_type: POINT
properties:
gid: int4
Expand All @@ -54,9 +57,9 @@ postgres:
- -77.2579745396886
- 174.72753224514435
- 73.80785950599903
extent: 4096
buffer: 64
clip_geom: true
extent: 9000
buffer: 3
clip_geom: false
geometry_type: POINT
properties:
id: int4
Expand Down