From cf18ac719aa6776586e35519629514dc3158b8ff Mon Sep 17 00:00:00 2001 From: Frank Jimenez <49205177+jjcfrank@users.noreply.github.com> Date: Sun, 10 Dec 2023 22:09:35 +0000 Subject: [PATCH] Updated README with examples & fixed main --- .gitignore | 1 + README.md | 7 ++++++- src/main.rs | 16 ++++++++-------- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 49cbaf4..9ec14d4 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ Cargo.lock src/shp .envrc query.sql +README.local.md diff --git a/README.md b/README.md index 29ca6a3..173edb4 100644 --- a/README.md +++ b/README.md @@ -3,5 +3,10 @@ In time, this will be a nice looking README page. # Usage ```bash -cargo run -- -u postgresql://user:password@localhost:5432/my_db --sql query.sql -w og-water-polys.shp -o intersected-water-polys.geojson +cargo run -- --uri postgresql://user:password@localhost:5432/my_db --sql query.sql --shp og-water-polys.shp --output intersected-water-polys.geojson ``` + +# Improvements +* Needs parsing of args +* Allow input sources other than PostGIS +* Allow outputs other than GeoJSON \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 9e34ecd..b273f34 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,16 +14,16 @@ use std::path::Path; struct Cli { /// Connection string to a database - #[arg(short, long)] + #[arg(long)] uri: String, /// SQL statement to pull the target geometries - #[arg(short, long)] + #[arg(long)] sql: String, /// A path to the OSM water shapefile - #[arg(short, long)] - water: String, + #[arg(long)] + shp: String, /// A path for the output GeoJSON file #[arg(short, long)] @@ -73,7 +73,7 @@ fn to_geo(polygon: shapefile::Polygon) -> geo::Polygon { #[derive(Debug)] struct Feature { - name: String, + //name: String, geom: geo::Polygon, } @@ -87,7 +87,7 @@ fn postgis_data(pgcon: &str, query: String) -> Vec { if result.is_ok() { let geom: geo::Polygon = result.unwrap(); features.push(Feature{ - name: row.get("project_name"), + //name: row.get("project_name"), geom, }); } @@ -188,7 +188,7 @@ fn to_geojson(output_path: &str, targets: Vec) { let geojson_string = geojson.to_string(); let result = fs::write(output_path, geojson_string); match result { - Ok(_) => println!("File succesfully saved"), + Ok(_) => println!("\n GeoJSON succesfully saved.\n"), Err(e) => println!("{:?}", e), } @@ -202,7 +202,7 @@ fn main() { // In the future sql can be either a string statement or path // to a more complex SQL statement let sql_path:String = args.sql; - let water_path:String = args.water; + let water_path:String = args.shp; let output_path:String = args.output; let root = Path::new("./");