-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
540f683
commit 38a076e
Showing
5 changed files
with
115 additions
and
7 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
use anyhow::Result; | ||
use enum_dispatch::enum_dispatch; | ||
use geojson; | ||
use geojson::{Feature, GeoJson, Geometry, Value}; | ||
use polars::prelude::*; | ||
use serde::{Deserialize, Serialize}; | ||
use std::io::Cursor; | ||
use std::{convert::TryFrom, io::Write}; | ||
|
||
#[enum_dispatch] | ||
pub trait OutputGenerator { | ||
fn format(&self, df: &mut DataFrame) -> Result<String>; | ||
fn save(&self, writer: &mut impl Write, df: &mut DataFrame) -> Result<()>; | ||
} | ||
|
||
#[enum_dispatch(OutputGenerator)] | ||
#[derive(Serialize, Deserialize, Debug)] | ||
pub enum OutputFormatter { | ||
GeoJSON(GeoJSONFormatter), | ||
GeoJSONSeq(GeoJSONSeqFormatter), | ||
Csv(CSVFormatter), | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
pub struct GeoJSONSeqFormatter; | ||
|
||
impl OutputGenerator for GeoJSONSeqFormatter { | ||
fn format(&self, df: &mut DataFrame) -> Result<String> { | ||
Ok("Test".into()) | ||
} | ||
|
||
fn save(&self, writer: &mut impl Write, df: &mut DataFrame) -> Result<()> { | ||
let output = self.format(df)?; | ||
Ok(()) | ||
} | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug, Default)] | ||
pub struct GeoJSONFormatter; | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
pub enum GeoFormat { | ||
Wkb, | ||
Wkt, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug, Default)] | ||
pub struct CSVFormatter { | ||
geo_format: Option<GeoFormat>, | ||
} | ||
|
||
impl OutputGenerator for CSVFormatter { | ||
fn format(&self, df: &mut DataFrame) -> Result<String> { | ||
let mut data: Vec<u8> = vec![0; 200]; | ||
let mut buff = Cursor::new(&mut data); | ||
self.save(&mut buff, df)?; | ||
|
||
Ok(String::from_utf8(data)?) | ||
} | ||
|
||
fn save(&self, writer: &mut impl Write, df: &mut DataFrame) -> Result<()> { | ||
CsvWriter::new(writer).finish(df)?; | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl OutputGenerator for GeoJSONFormatter { | ||
fn format(&self, df: &mut DataFrame) -> Result<String> { | ||
Ok("Test".into()) | ||
} | ||
|
||
fn save(&self, writer: &mut impl Write, df: &mut DataFrame) -> Result<()> { | ||
let output = self.format(df)?; | ||
Ok(()) | ||
} | ||
} |
This file contains 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