Skip to content

Commit

Permalink
Updated README with examples & fixed main
Browse files Browse the repository at this point in the history
  • Loading branch information
jjcfrancisco committed Dec 10, 2023
1 parent f461726 commit cf18ac7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ Cargo.lock
src/shp
.envrc
query.sql
README.local.md
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 8 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -73,7 +73,7 @@ fn to_geo(polygon: shapefile::Polygon) -> geo::Polygon {

#[derive(Debug)]
struct Feature {
name: String,
//name: String,
geom: geo::Polygon,
}

Expand All @@ -87,7 +87,7 @@ fn postgis_data(pgcon: &str, query: String) -> Vec<Feature> {
if result.is_ok() {
let geom: geo::Polygon = result.unwrap();
features.push(Feature{
name: row.get("project_name"),
//name: row.get("project_name"),
geom,
});
}
Expand Down Expand Up @@ -188,7 +188,7 @@ fn to_geojson(output_path: &str, targets: Vec<geo::Polygon>) {
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),
}

Expand All @@ -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("./");
Expand Down

0 comments on commit cf18ac7

Please sign in to comment.