-
Notifications
You must be signed in to change notification settings - Fork 50
feat(cli): Add support for geoparquet reading #247
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
bd5cab4
c4fedff
7471d1a
1e3b2e1
9535a6e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,8 @@ | ||
| use clap::Parser; | ||
| use flatgeobuf::{FgbReader, FgbWriter, GeometryType, HttpFgbReader}; | ||
| use geo::Rect; | ||
| use geoarrow::io::parquet::{GeoParquetReaderOptions, GeoParquetRecordBatchReaderBuilder}; | ||
| use geoarrow::io::RecordBatchReader; | ||
| use geozero::csv::{CsvReader, CsvWriter}; | ||
| use geozero::error::{GeozeroError, Result}; | ||
| use geozero::geojson::{GeoJsonLineReader, GeoJsonReader, GeoJsonWriter}; | ||
|
|
@@ -24,7 +27,7 @@ struct Cli { | |
| #[arg(short, long, value_parser = parse_extent)] | ||
| extent: Option<Extent>, | ||
|
|
||
| /// The path or URL to the FlatGeobuf file to read | ||
| /// The path or URL to the input file to read | ||
| input: String, | ||
|
|
||
| /// The path to the file to write | ||
|
|
@@ -88,6 +91,26 @@ async fn transform<P: FeatureProcessor>(args: Cli, processor: &mut P) -> Result< | |
| Some("jsonl") | Some("geojsonl") => { | ||
| GeozeroDatasource::process(&mut GeoJsonLineReader::new(filein), processor) | ||
| } | ||
| Some("parquet") | Some("geoparquet") => { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The community discourages against
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not have a strong opinion here, and tried to be consistent with |
||
| let mut geo_options = GeoParquetReaderOptions::default(); | ||
| if let Some(bbox) = &args.extent { | ||
| geo_options = geo_options.with_bbox( | ||
| Rect::new((bbox.minx, bbox.miny), (bbox.maxx, bbox.maxy)), | ||
| None, | ||
| ); | ||
| } | ||
| let reader = GeoParquetRecordBatchReaderBuilder::try_new_with_options( | ||
| File::open(path_in)?, | ||
| Default::default(), | ||
| geo_options, | ||
| ) | ||
| .map_err(arrow_to_geozero_err)? | ||
| .build() | ||
| .map_err(arrow_to_geozero_err)?; | ||
|
|
||
| let mut wrapper = RecordBatchReader::new(Box::new(reader)); | ||
| wrapper.process(processor) | ||
| } | ||
| Some("fgb") => { | ||
| let ds = FgbReader::open(&mut filein).map_err(fgb_to_geozero_err)?; | ||
| let mut ds = if let Some(bbox) = &args.extent { | ||
|
|
@@ -127,6 +150,7 @@ async fn process(args: Cli) -> Result<()> { | |
| } | ||
| Ok(()) | ||
| } | ||
|
|
||
| fn set_dimensions(processor: &mut SvgWriter<&mut BufWriter<File>>, extent: Option<Extent>) { | ||
| if let Some(extent) = extent { | ||
| processor.set_dimensions(extent.minx, extent.miny, extent.maxx, extent.maxy, 800, 600); | ||
|
|
@@ -136,6 +160,13 @@ fn set_dimensions(processor: &mut SvgWriter<&mut BufWriter<File>>, extent: Optio | |
| } | ||
| } | ||
|
|
||
| fn arrow_to_geozero_err(parquet_err: geoarrow::error::GeoArrowError) -> GeozeroError { | ||
| match parquet_err { | ||
| geoarrow::error::GeoArrowError::IOError(e) => GeozeroError::IoError(e), | ||
| err => GeozeroError::Dataset(format!("Unknown GeoArrow error: {err:?}")), | ||
| } | ||
| } | ||
|
|
||
| fn fgb_to_geozero_err(fgb_err: flatgeobuf::Error) -> GeozeroError { | ||
| match fgb_err { | ||
| flatgeobuf::Error::MissingMagicBytes => { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.