use flatgeobuf::*; use geozero::error::Result; use geozero_core::svg::SvgWriter; use std::fs::File; use std::io::{BufReader, Write}; fn invert_y(header: &Header) -> bool { if let Some(crs) = header.crs() { if crs.code() == 4326 { return true; } } false } fn svg_writer<'a, W: Write>( header: &Header, width: u32, height: u32, out: &'a mut W, ) -> SvgWriter<'a, W> { let mut svg = SvgWriter::new(out, invert_y(header)); if let Some(envelope) = header.envelope() { svg.set_dimensions( envelope.get(0), envelope.get(1), envelope.get(2), envelope.get(3), width, height, ); } svg } #[test] fn fgb_to_svg() -> Result<()> { let mut filein = BufReader::new(File::open("tests/data/countries.fgb")?); let mut fgb = FgbReader::open(&mut filein)?; let _count = fgb.select_bbox(8.8, 47.2, 9.5, 55.3)?; let mut svg_data: Vec = Vec::new(); let mut svg = svg_writer(&fgb.header(), 800, 400, &mut svg_data); fgb.process_features(&mut svg)?; let out = std::str::from_utf8(&svg_data).unwrap(); let expected = r#" "#; assert_eq!(&out[..expected.len()], expected); let expected = r#"99.93976 -78.88094 Z "/> "#; assert_eq!(&out[svg_data.len() - expected.len()..], expected); Ok(()) }