mirror of
https://github.com/maplibre/martin.git
synced 2024-12-18 20:31:54 +03:00
Add clip_geom, buffer and extent under auto_publish conf (#887)
`postgres.auto_publish.tables` now lets users customize `clip_geom`, `buffer`, and `extent` instead of using their default values. See also #872 --------- Co-authored-by: Yuri Astrakhan <YuriAstrakhan@gmail.com>
This commit is contained in:
parent
6d5336d48c
commit
b2b3e2ce36
@ -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}'
|
||||
|
@ -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 {
|
||||
@ -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
|
||||
@ -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(),
|
||||
|
@ -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)]
|
||||
@ -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,
|
||||
@ -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;
|
||||
};
|
||||
@ -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,
|
||||
})
|
||||
};
|
||||
|
||||
@ -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,
|
||||
@ -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,
|
||||
extent: None,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
@ -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
|
||||
@ -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
|
||||
@ -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
|
||||
@ -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
|
||||
@ -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
|
||||
@ -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
|
||||
@ -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
|
||||
@ -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
|
||||
@ -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
|
||||
@ -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
|
||||
|
@ -11,6 +11,9 @@ postgres:
|
||||
id_columns:
|
||||
- feat_id
|
||||
- big_feat_id
|
||||
clip_geom: false
|
||||
buffer: 3
|
||||
extent: 9000
|
||||
tables:
|
||||
MixPoints:
|
||||
schema: MixedCase
|
||||
@ -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
|
||||
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user