Skip to content

Commit a332cff

Browse files
committed
Add multitype option to force use of Multi* geometries
1 parent 4f2ddea commit a332cff

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/main.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ struct Column<'a> {
5858
replace: Option<&'a str>,
5959
consol: Option<&'a str>,
6060
subtable: Option<Table<'a>>,
61-
bbox: Option<BBox>
61+
bbox: Option<BBox>,
62+
multitype: bool
6263
}
6364
impl std::fmt::Debug for Column<'_> {
6465
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
@@ -99,10 +100,10 @@ impl BBox {
99100
}
100101
}
101102

102-
fn gml_to_ewkb(cell: &RefCell<String>, coll: &[Geometry], bbox: Option<&BBox>) -> bool {
103+
fn gml_to_ewkb(cell: &RefCell<String>, coll: &[Geometry], bbox: Option<&BBox>, multitype: bool) -> bool {
103104
let mut ewkb: Vec<u8> = vec![];
104105

105-
if coll.len() > 1 {
106+
if multitype || coll.len() > 1 {
106107
let multitype = coll.first().unwrap().gtype+3;
107108
ewkb.extend_from_slice(&[1, multitype, 0, 0, 0]);
108109
ewkb.extend_from_slice(&(coll.len() as u32).to_le_bytes());
@@ -126,7 +127,7 @@ fn gml_to_ewkb(cell: &RefCell<String>, coll: &[Geometry], bbox: Option<&BBox>) -
126127
for ring in geom.rings.iter() {
127128
if geom.gtype != 1 { ewkb.extend_from_slice(&((ring.len() as u32)/geom.dims as u32).to_le_bytes()); } // Points don't have multiple vertices
128129
for (i, pos) in ring.iter().enumerate() {
129-
if overlap == true { }
130+
if overlap { }
130131
else if geom.dims == 2 {
131132
if i%2 == 0 {
132133
overlapx = false;
@@ -144,7 +145,7 @@ fn gml_to_ewkb(cell: &RefCell<String>, coll: &[Geometry], bbox: Option<&BBox>) -
144145
ewkb.extend_from_slice(&pos.to_le_bytes());
145146
}
146147
}
147-
if overlap == false { return false; }
148+
if !overlap { return false; }
148149
}
149150
else {
150151
for ring in geom.rings.iter() {
@@ -185,7 +186,8 @@ fn add_table<'a>(rowpath: &str, outfile: Option<&str>, filemode: &str, skip: Opt
185186
let find = col["find"].as_str();
186187
let replace = col["repl"].as_str();
187188
let consol = col["cons"].as_str();
188-
let bbox = col["bbox"].as_str().and_then(|str| BBox::from(str));
189+
let bbox = col["bbox"].as_str().and_then(BBox::from);
190+
let multitype = col["mult"].as_bool().unwrap_or(false);
189191

190192
if convert.is_some() && !vec!("xml-to-text", "gml-to-ewkb").contains(&convert.unwrap()) {
191193
panic!("Option 'convert' contains invalid value {}", convert.unwrap());
@@ -205,7 +207,7 @@ fn add_table<'a>(rowpath: &str, outfile: Option<&str>, filemode: &str, skip: Opt
205207
eprintln!("Warning: the bbox option has no function without conversion type 'gml-to-ekwb'");
206208
}
207209

208-
let column = Column { name: name.to_string(), path, value: RefCell::new(String::new()), attr, hide, include, exclude, convert, find, replace, consol, subtable, bbox };
210+
let column = Column { name: name.to_string(), path, value: RefCell::new(String::new()), attr, hide, include, exclude, convert, find, replace, consol, subtable, bbox, multitype };
209211
table.columns.push(column);
210212
}
211213
table
@@ -499,7 +501,7 @@ fn main() -> std::io::Result<()> {
499501
for i in 0..table.columns.len() {
500502
if path == table.columns[i].path {
501503
gmltoewkb = false;
502-
if !gml_to_ewkb(&table.columns[i].value, &gmlcoll, table.columns[i].bbox.as_ref()) {
504+
if !gml_to_ewkb(&table.columns[i].value, &gmlcoll, table.columns[i].bbox.as_ref(), table.columns[i].multitype) {
503505
filtered = true;
504506
table.clear_columns();
505507
}

0 commit comments

Comments
 (0)