mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-23 08:54:30 +03:00
Optional: rely on new default f64 type for geo-types
This commit is contained in:
parent
31637b4d61
commit
8dc7e43309
@ -28,7 +28,7 @@ downcast-rs = "1.2.0"
|
||||
enumset = "1.0.3"
|
||||
fs-err = "2.6.0"
|
||||
futures-channel = { version = "0.3.12"}
|
||||
geo = "0.21.0"
|
||||
geo = "0.22.0"
|
||||
geojson = { version = "0.22.2", features = ["geo-types"] }
|
||||
geom = { path = "../../geom" }
|
||||
getrandom = { version = "0.2.3", optional = true }
|
||||
|
@ -17,7 +17,7 @@ abstutil = { path = "../../abstutil" }
|
||||
anyhow = "1.0.38"
|
||||
contour = "0.4.0"
|
||||
flate2 = "1.0.20"
|
||||
geo = "0.21.0"
|
||||
geo = "0.22.0"
|
||||
geojson = { version = "0.22.2", features = ["geo-types"] }
|
||||
geom = { path = "../../geom" }
|
||||
getrandom = { version = "0.2.3", optional = true }
|
||||
|
@ -45,7 +45,7 @@ impl RenderCells {
|
||||
}
|
||||
|
||||
/// Per cell, convert all polygons to a `geo::MultiPolygon`. Leave the coordinate system as map-space.
|
||||
pub fn to_multipolygons(&self) -> Vec<geo::MultiPolygon<f64>> {
|
||||
pub fn to_multipolygons(&self) -> Vec<geo::MultiPolygon> {
|
||||
self.polygons_per_cell
|
||||
.clone()
|
||||
.into_iter()
|
||||
|
@ -95,7 +95,7 @@ fn geojson_string(ctx: &EventCtx, app: &App) -> Result<String> {
|
||||
for feature in &mut features {
|
||||
// geojson to geo
|
||||
// This could be a Polygon, MultiPolygon, LineString
|
||||
let mut geom: geo::Geometry<f64> = feature.geometry.take().unwrap().value.try_into()?;
|
||||
let mut geom: geo::Geometry = feature.geometry.take().unwrap().value.try_into()?;
|
||||
|
||||
geom.map_coords_in_place(|c| {
|
||||
let gps = Pt2D::new(c.x, c.y).to_gps(gps_bounds);
|
||||
|
@ -10,7 +10,7 @@ abstutil = { path = "../abstutil" }
|
||||
anyhow = "1.0.38"
|
||||
csv = "1.1.4"
|
||||
fs-err = "2.6.0"
|
||||
geo = "0.21.0"
|
||||
geo = "0.22.0"
|
||||
geojson = { version = "0.22.2", features = ["geo-types"] }
|
||||
geom = { path = "../geom" }
|
||||
importer = { path = "../importer" }
|
||||
|
@ -20,7 +20,7 @@ pub fn run(pbf_path: String, clip_path: String, out_path: String) -> Result<()>
|
||||
clip(&pbf_path, &boundary, &out_path)
|
||||
}
|
||||
|
||||
fn clip(pbf_path: &str, boundary: &Polygon<f64>, out_path: &str) -> Result<()> {
|
||||
fn clip(pbf_path: &str, boundary: &Polygon, out_path: &str) -> Result<()> {
|
||||
// TODO Maybe just have a single map with RcOSMObj. But then the order we write will be wrong.
|
||||
let mut way_node_ids: HashSet<i64> = HashSet::new();
|
||||
let mut way_ids: HashSet<i64> = HashSet::new();
|
||||
@ -97,7 +97,7 @@ fn clip(pbf_path: &str, boundary: &Polygon<f64>, out_path: &str) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn to_pt(pair: (osmio::Lat, osmio::Lon)) -> Point<f64> {
|
||||
fn to_pt(pair: (osmio::Lat, osmio::Lon)) -> Point {
|
||||
// Note our polygon uses (lon, lat)
|
||||
(pair.1.into(), pair.0.into()).into()
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ abstutil = { path = "../abstutil" }
|
||||
anyhow = "1.0.38"
|
||||
earcutr = "0.1.1"
|
||||
fs-err = "2.6.0"
|
||||
geo = "0.21.0"
|
||||
geo = "0.22.0"
|
||||
geojson = { version = "0.22.2", features = ["geo-types"] }
|
||||
histogram = "0.6.9"
|
||||
instant = "0.1.7"
|
||||
|
@ -5,8 +5,8 @@
|
||||
|
||||
use crate::Pt2D;
|
||||
|
||||
pub fn pts_to_line_string(raw_pts: &[Pt2D]) -> geo::LineString<f64> {
|
||||
let pts: Vec<geo::Point<f64>> = raw_pts
|
||||
pub fn pts_to_line_string(raw_pts: &[Pt2D]) -> geo::LineString {
|
||||
let pts: Vec<geo::Point> = raw_pts
|
||||
.iter()
|
||||
.map(|pt| geo::Point::new(pt.x(), pt.y()))
|
||||
.collect();
|
||||
|
@ -12,7 +12,7 @@ use crate::{Bounds, Distance, Pt2D};
|
||||
/// A quad-tree to quickly find the closest points to some polylines.
|
||||
pub struct FindClosest<K> {
|
||||
// TODO maybe any type of geo:: thing
|
||||
geometries: BTreeMap<K, geo::LineString<f64>>,
|
||||
geometries: BTreeMap<K, geo::LineString>,
|
||||
quadtree: QuadTree<K>,
|
||||
}
|
||||
|
||||
|
@ -189,7 +189,7 @@ impl fmt::Display for LonLat {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<LonLat> for geo::Point<f64> {
|
||||
impl From<LonLat> for geo::Point {
|
||||
fn from(pt: LonLat) -> Self {
|
||||
geo::Point::new(pt.x(), pt.y())
|
||||
}
|
||||
|
@ -338,7 +338,7 @@ impl Polygon {
|
||||
}
|
||||
|
||||
/// Union all of the polygons into one geo::MultiPolygon
|
||||
pub fn union_all_into_multipolygon(mut list: Vec<Polygon>) -> geo::MultiPolygon<f64> {
|
||||
pub fn union_all_into_multipolygon(mut list: Vec<Polygon>) -> geo::MultiPolygon {
|
||||
// TODO Not sure why this happened, or if this is really valid to construct...
|
||||
if list.is_empty() {
|
||||
return geo::MultiPolygon(Vec::new());
|
||||
@ -356,13 +356,13 @@ impl Polygon {
|
||||
}
|
||||
|
||||
pub fn convex_hull(list: Vec<Polygon>) -> Polygon {
|
||||
let mp: geo::MultiPolygon<f64> = list.into_iter().map(|p| p.to_geo()).collect();
|
||||
let mp: geo::MultiPolygon = list.into_iter().map(|p| p.to_geo()).collect();
|
||||
mp.convex_hull().into()
|
||||
}
|
||||
|
||||
pub fn concave_hull(points: Vec<Pt2D>, concavity: u32) -> Polygon {
|
||||
use geo::k_nearest_concave_hull::KNearestConcaveHull;
|
||||
let points: Vec<geo::Point<f64>> = points.iter().map(|p| geo::Point::from(*p)).collect();
|
||||
let points: Vec<geo::Point> = points.iter().map(|p| geo::Point::from(*p)).collect();
|
||||
points.k_nearest_concave_hull(concavity).into()
|
||||
}
|
||||
|
||||
@ -568,7 +568,7 @@ impl Polygon {
|
||||
// A less verbose way of invoking the From/Into impl. Note this hides a potentially expensive
|
||||
// clone. The eventual goal is for Polygon to directly wrap a geo::Polygon, at which point this
|
||||
// cost goes away.
|
||||
fn to_geo(&self) -> geo::Polygon<f64> {
|
||||
fn to_geo(&self) -> geo::Polygon {
|
||||
self.clone().into()
|
||||
}
|
||||
}
|
||||
@ -599,8 +599,8 @@ pub struct Triangle {
|
||||
pub pt3: Pt2D,
|
||||
}
|
||||
|
||||
impl From<geo::Polygon<f64>> for Polygon {
|
||||
fn from(poly: geo::Polygon<f64>) -> Self {
|
||||
impl From<geo::Polygon> for Polygon {
|
||||
fn from(poly: geo::Polygon) -> Self {
|
||||
let (exterior, interiors) = poly.into_inner();
|
||||
Polygon::with_holes(
|
||||
Ring::from(exterior),
|
||||
@ -609,11 +609,11 @@ impl From<geo::Polygon<f64>> for Polygon {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Polygon> for geo::Polygon<f64> {
|
||||
impl From<Polygon> for geo::Polygon {
|
||||
fn from(poly: Polygon) -> Self {
|
||||
if let Some(mut rings) = poly.rings {
|
||||
let exterior = rings.remove(0);
|
||||
let interiors: Vec<geo::LineString<f64>> =
|
||||
let interiors: Vec<geo::LineString> =
|
||||
rings.into_iter().map(geo::LineString::from).collect();
|
||||
Self::new(exterior.into(), interiors)
|
||||
} else {
|
||||
@ -628,7 +628,7 @@ impl From<Polygon> for geo::Polygon<f64> {
|
||||
}
|
||||
}
|
||||
|
||||
fn from_multi(multi: geo::MultiPolygon<f64>) -> Vec<Polygon> {
|
||||
fn from_multi(multi: geo::MultiPolygon) -> Vec<Polygon> {
|
||||
// TODO This should just call Polygon::from, but while importing maps, it seems like
|
||||
// intersection() is hitting non-Ring cases that crash. So keep using buggy_new for now.
|
||||
multi
|
||||
|
@ -987,8 +987,8 @@ impl PolyLine {
|
||||
self.first_pt().angle_to(self.last_pt())
|
||||
}
|
||||
|
||||
pub(crate) fn to_geo(&self) -> geo::LineString<f64> {
|
||||
let pts: Vec<geo::Point<f64>> = self
|
||||
pub(crate) fn to_geo(&self) -> geo::LineString {
|
||||
let pts: Vec<geo::Point> = self
|
||||
.pts
|
||||
.iter()
|
||||
.map(|pt| geo::Point::new(pt.x(), pt.y()))
|
||||
|
@ -164,26 +164,26 @@ impl HashablePt2D {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Pt2D> for geo::Coordinate<f64> {
|
||||
impl From<Pt2D> for geo::Coordinate {
|
||||
fn from(pt: Pt2D) -> Self {
|
||||
geo::Coordinate { x: pt.x, y: pt.y }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Pt2D> for geo::Point<f64> {
|
||||
impl From<Pt2D> for geo::Point {
|
||||
fn from(pt: Pt2D) -> Self {
|
||||
geo::Point::new(pt.x, pt.y)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<geo::Coordinate<f64>> for Pt2D {
|
||||
fn from(coord: geo::Coordinate<f64>) -> Self {
|
||||
impl From<geo::Coordinate> for Pt2D {
|
||||
fn from(coord: geo::Coordinate) -> Self {
|
||||
Pt2D::new(coord.x, coord.y)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<geo::Point<f64>> for Pt2D {
|
||||
fn from(point: geo::Point<f64>) -> Self {
|
||||
impl From<geo::Point> for Pt2D {
|
||||
fn from(point: geo::Point) -> Self {
|
||||
Pt2D::new(point.x(), point.y())
|
||||
}
|
||||
}
|
||||
|
@ -280,7 +280,7 @@ impl fmt::Display for Ring {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Ring> for geo::LineString<f64> {
|
||||
impl From<Ring> for geo::LineString {
|
||||
fn from(ring: Ring) -> Self {
|
||||
let coords = ring
|
||||
.pts
|
||||
@ -291,8 +291,8 @@ impl From<Ring> for geo::LineString<f64> {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<geo::LineString<f64>> for Ring {
|
||||
fn from(line_string: geo::LineString<f64>) -> Self {
|
||||
impl From<geo::LineString> for Ring {
|
||||
fn from(line_string: geo::LineString) -> Self {
|
||||
// Dedupe adjacent points. Only needed for results from concave hull.
|
||||
let mut pts: Vec<Pt2D> = line_string.0.into_iter().map(Pt2D::from).collect();
|
||||
pts.dedup();
|
||||
|
@ -45,11 +45,8 @@ async fn load_remote_geojson(path: String, url: &str) -> Result<GeoJson> {
|
||||
abstio::maybe_read_json(path, &mut Timer::throwaway())
|
||||
}
|
||||
|
||||
fn find_matching_regions(
|
||||
geojson: GeoJson,
|
||||
center: LonLat,
|
||||
) -> Vec<(geo::MultiPolygon<f64>, String)> {
|
||||
let center: geo::Point<f64> = center.into();
|
||||
fn find_matching_regions(geojson: GeoJson, center: LonLat) -> Vec<(geo::MultiPolygon, String)> {
|
||||
let center: geo::Point = center.into();
|
||||
|
||||
let mut matches = Vec::new();
|
||||
|
||||
@ -59,8 +56,7 @@ fn find_matching_regions(
|
||||
if let GeoJson::FeatureCollection(fc) = geojson {
|
||||
info!("Searching {} regions", fc.features.len());
|
||||
for mut feature in fc.features {
|
||||
let mp: geo::MultiPolygon<f64> =
|
||||
feature.geometry.take().unwrap().value.try_into().unwrap();
|
||||
let mp: geo::MultiPolygon = feature.geometry.take().unwrap().value.try_into().unwrap();
|
||||
if mp.contains(¢er) {
|
||||
matches.push((
|
||||
mp,
|
||||
|
@ -10,7 +10,7 @@ abstutil = { path = "../abstutil" }
|
||||
anyhow = "1.0.38"
|
||||
flatgeobuf = { version = "0.5" }
|
||||
futures = "0.3.12"
|
||||
geo = "0.21.0"
|
||||
geo = "0.22.0"
|
||||
geojson = { version = "0.22.2", features = ["geo-types"] }
|
||||
geom = { path = "../geom" }
|
||||
geozero = "0.7"
|
||||
|
@ -36,7 +36,7 @@ pub fn assign_people_to_houses(
|
||||
/// to residential buildings within that area. Returns a list of homes with the number of residents
|
||||
/// in each.
|
||||
pub fn distribute_population_to_homes(
|
||||
polygon: geo::Polygon<f64>,
|
||||
polygon: geo::Polygon,
|
||||
population: usize,
|
||||
map: &Map,
|
||||
rng: &mut XorShiftRng,
|
||||
|
@ -13,7 +13,7 @@ impl CensusArea {
|
||||
use flatgeobuf::HttpFgbReader;
|
||||
use geozero::geo_types::GeoWriter;
|
||||
|
||||
let mut geo_map_area: geo::Polygon<_> = map_area.clone().into();
|
||||
let mut geo_map_area: geo::Polygon = map_area.clone().into();
|
||||
geo_map_area.map_coords_in_place(|c| {
|
||||
let projected = geom::Pt2D::new(c.x, c.y).to_gps(bounds);
|
||||
(projected.x(), projected.y()).into()
|
||||
|
@ -43,7 +43,7 @@ pub mod od;
|
||||
/// have two overlapping areas.
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct CensusArea {
|
||||
pub polygon: geo::Polygon<f64>,
|
||||
pub polygon: geo::Polygon,
|
||||
pub population: usize,
|
||||
// TODO Not sure what goes here, whatever census data actually has that could be useful
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user