-
-
Notifications
You must be signed in to change notification settings - Fork 73
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
(Rust) Unclear documentation on the default behavior of add_feature_geom
when the columns do not exist
#216
Comments
I tried to reproduce this by extending the following write test: +++ b/src/rust/tests/write.rs
@@ -126,10 +126,29 @@ fn json_to_fgb() -> Result<()> {
})
.ok();
+ let fgbfile = NamedTempFile::new()?;
+ let mut file = BufWriter::new(&fgbfile);
// let mut file = BufWriter::new(File::create("test_multipoly.fgb")?);
- let mut file = BufWriter::new(tempfile()?);
fgb.write(&mut file)?;
+ file.flush()?;
+
+ // Load
+ let file = fgbfile.reopen()?;
+ let mut filein = BufReader::new(&file);
+ let mut fgb = FgbReader::open(&mut filein)?.select_all()?;
+ let feature = fgb.next().unwrap().unwrap();
+ assert_eq!(feature.geometry().unwrap().type_(), GeometryType::Unknown);
+ let props = feature.properties().unwrap();
+ assert_eq!(props["fid"], "42");
+ assert_eq!(props["name"], "New Zealand");
+
+ let feature = fgb.next().unwrap().unwrap();
+ assert_eq!(feature.geometry().unwrap().type_(), GeometryType::Unknown);
+ let props = feature.properties().unwrap();
+ assert_eq!(props["fid"], "43");
+ assert_eq!(props["name"], "South Africa");
+
Ok(())
} Can you reproduce your problem with a test like this? |
Changing the test does work: apparently you need to call the My workaround was actually wrong as the properties were set, but not on the correct features. In my original code I didn't add the calls to the Maybe you would accept a PR to update the documentation with the fact that the columns must actually exist before the method |
PropertyProcessor::property
method of FeatureWriter
.add_feature_geom
when the columns do not exist
A PR for improving the documentation would very welcome! Maybe there is also a good way to return an error in such cases, because the current behaviour is bad for sure. |
The
cfgfn
variable ofFgbWriter::add_feature_geom
does not allow us to set the properties of the feature being added.Using
rust-analyzer
I discovered that the implementation offeat.property(..)
as used in the usage example refers to the default no-op implementation ofgeozero::PropertyProcessor
.Luckily a simple workaround exists; instead of following the example code like this:
... use the
property
of theFgbWriter
to actually set the property values.I verified the properties' existence in QGIS.
Maybe the reason this bug happens is related to the fact that the module of
FeatureWriter
is not public? This fact also made it difficult to reason what was happening by reading the docs.The text was updated successfully, but these errors were encountered: