Skip to content

Commit

Permalink
Add GridFormat::Cells
Browse files Browse the repository at this point in the history
Closes #178.
  • Loading branch information
Notgnoshi committed May 26, 2024
1 parent 6af8663 commit 618a2b2
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tools/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use generative::graph::GeometryGraph;
use generative::io::{
get_output_writer, write_geometries, write_graph, GeometryFormat, GraphFormat,
};
#[cfg(feature = "cxx-bindings")]
use generative::noding::polygonize;
use geo::{Geometry, Point};
use petgraph::Undirected;
use stderrlog::ColorChoice;
Expand All @@ -17,6 +19,9 @@ enum GridFormat {
Lines,
/// Output the grid points in WKT
Points,
/// Output the grid cells as WKT POLYGONs
#[cfg(feature = "cxx-bindings")]
Cells,
}

impl std::fmt::Display for GridFormat {
Expand All @@ -26,6 +31,8 @@ impl std::fmt::Display for GridFormat {
GridFormat::Graph => write!(f, "graph"),
GridFormat::Lines => write!(f, "lines"),
GridFormat::Points => write!(f, "points"),
#[cfg(feature = "cxx-bindings")]
GridFormat::Cells => write!(f, "cells"),
}
}
}
Expand Down Expand Up @@ -479,5 +486,13 @@ fn main() {
graph.node_weights().map(|p| Geometry::Point(*p)),
GeometryFormat::Wkt,
),
#[cfg(feature = "cxx-bindings")]
GridFormat::Cells => {
let (polygons, dangles) = polygonize(&graph);
let polygons = polygons.into_iter().map(Geometry::Polygon);
let dangles = dangles.into_iter().map(Geometry::LineString);
let geoms = polygons.chain(dangles);
write_geometries(writer, geoms, GeometryFormat::Wkt);
}
}
}

0 comments on commit 618a2b2

Please sign in to comment.