Last active
November 17, 2021 22:46
-
-
Save highway900/c7d095713b9a4521fc4aebf6c1f3eec7 to your computer and use it in GitHub Desktop.
Write fgb file with properties
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pub fn write_fgb_file(filename: String, linestrings: &Vec<LineString<f64>>) -> Result<()> { | |
| let mut fgb = FgbWriter::create( | |
| "countries", | |
| GeometryType::LineString, | |
| Some(4326), | |
| |header| { | |
| header.description = Some(FgbWriter::create_string("Country polygons")); | |
| }, | |
| )?; | |
| fgb.add_column("fid", ColumnType::ULong, |col| { | |
| col.nullable = false; | |
| }); | |
| fgb.add_column("name", ColumnType::String, |_| {}); | |
| // let geom: geo_types::Geometry<f64> = geo::Point::new(10.0, 20.0).into(); | |
| for ls in linestrings.iter() { | |
| let geom: geo_types::Geometry<f64> = ls.to_owned().into(); | |
| fgb.add_feature_geom(geom, |feat| { | |
| feat.property(0, "fid", &ColumnValue::Long(43)).unwrap(); | |
| feat.property(1, "name", &ColumnValue::String("South Africa")) | |
| .unwrap(); | |
| }) | |
| .ok(); | |
| } | |
| let mut file = BufWriter::new(std::fs::File::create(filename)?); | |
| fgb.write(&mut file)?; | |
| Ok(()) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment