Skip to content

Instantly share code, notes, and snippets.

@highway900
Last active November 17, 2021 22:46
Show Gist options
  • Save highway900/c7d095713b9a4521fc4aebf6c1f3eec7 to your computer and use it in GitHub Desktop.
Save highway900/c7d095713b9a4521fc4aebf6c1f3eec7 to your computer and use it in GitHub Desktop.
Write fgb file with properties
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