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 bd8c85b
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tools/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use generative::graph::GeometryGraph;
use generative::io::{
get_output_writer, write_geometries, write_graph, GeometryFormat, GraphFormat,
};
use generative::noding::polygonize;
use geo::{Geometry, Point};
use petgraph::Undirected;
use stderrlog::ColorChoice;
Expand All @@ -17,6 +18,8 @@ enum GridFormat {
Lines,
/// Output the grid points in WKT
Points,
/// Output the grid cells as WKT POLYGONs
Cells,
}

impl std::fmt::Display for GridFormat {
Expand All @@ -26,6 +29,7 @@ impl std::fmt::Display for GridFormat {
GridFormat::Graph => write!(f, "graph"),
GridFormat::Lines => write!(f, "lines"),
GridFormat::Points => write!(f, "points"),
GridFormat::Cells => write!(f, "cells"),
}
}
}
Expand Down Expand Up @@ -479,5 +483,12 @@ fn main() {
graph.node_weights().map(|p| Geometry::Point(*p)),
GeometryFormat::Wkt,
),
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 bd8c85b

Please sign in to comment.