Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ edition = "2021"
[workspace.dependencies]
anyhow = "1.0.82"
bincode = "1.3.3"
geo = { git = "https://github.com/georust/geo", branch="mkirk/geo-buffer" }
geo = { git = "https://github.com/georust/geo", branch="mkirk/geo-ltn" }
geojson = { git = "https://github.com/georust/geojson", features = ["geo-types"] }
serde = "1.0.188"
utils = { git = "https://github.com/a-b-street/utils", features = ["serde"] }
Expand All @@ -23,6 +23,6 @@ utils = { git = "https://github.com/a-b-street/utils", features = ["serde"] }
opt-level = 3

[patch.crates-io]
geo = { git = "https://github.com/georust/geo", branch="mkirk/geo-buffer" }
geo = { git = "https://github.com/georust/geo", branch="mkirk/geo-ltn" }
#geo = { path = "../../georust/geo/geo" }
geo-types = { git = "https://github.com/georust/geo" }
geo-types = { git = "https://github.com/georust/geo", branch="mkirk/geo-ltn" }
2 changes: 1 addition & 1 deletion backend/src/boundary_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,5 @@ pub struct PopulationZone {

pub struct PreparedPopulationZone {
pub population_zone: PopulationZone,
pub prepared_geometry: PreparedGeometry<'static>,
pub prepared_geometry: PreparedGeometry<'static, MultiPolygon>,
}
5 changes: 3 additions & 2 deletions backend/src/create.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use std::collections::{BTreeMap, BTreeSet, HashMap};

use anyhow::Result;
use geo::{Coord, LineInterpolatePoint, LineString, MultiPolygon, PreparedGeometry};
use geo::line_measures::InterpolatableLine;
use geo::{Coord, Euclidean, LineString, MultiPolygon, PreparedGeometry};
use osm_reader::{NodeID, OsmID, RelationID, WayID};
use petgraph::graphmap::UnGraphMap;
use rstar::{primitives::GeomWithData, RTree};
Expand Down Expand Up @@ -360,7 +361,7 @@ fn apply_existing_filters(
let pt = map
.get_r(r)
.linestring
.line_interpolate_point(percent)
.point_at_ratio_from_start(&Euclidean, percent)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the new api from georust/geo#1321 - it's more explicit about metric space, and also has some new APIs which you can see further down.

.unwrap();
map.add_modal_filter(pt.into(), Some(vec![r]), filter);
}
Expand Down
6 changes: 3 additions & 3 deletions backend/src/geo_helpers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
mod slice_nearest_boundary;
pub use slice_nearest_boundary::SliceNearestFrechetBoundary;

use geo::line_measures::InterpolatableLine;
use geo::{
BooleanOps, BoundingRect, Contains, Coord, Distance, Euclidean, Intersects, Length, Line,
LineInterpolatePoint, LineIntersection, LineLocatePoint, LineString, MultiPolygon, Point,
Polygon, Rect, Validation,
LineIntersection, LineLocatePoint, LineString, MultiPolygon, Point, Polygon, Rect, Validation,
};
use rstar::AABB;
use utils::LineSplit;
Expand Down Expand Up @@ -71,7 +71,7 @@ pub fn clip_linestring_to_polygon(linestring: &LineString, polygon: &Polygon) ->
continue;
};
// Is this piece inside the polygon or not? Check the midpoint
if let Some(midpt) = split.line_interpolate_point(0.5) {
if let Some(midpt) = split.point_at_ratio_from_start(&Euclidean, 0.5) {
if polygon.contains(&midpt) {
results.push(split);
}
Expand Down
12 changes: 8 additions & 4 deletions backend/src/map_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::route::RouterInput;
use crate::{od::DemandModel, Router};
use anyhow::Result;
use geo::{
Closest, ClosestPoint, Coord, Distance, Euclidean, Length, LineInterpolatePoint,
line_measures::InterpolatableLine, Closest, ClosestPoint, Coord, Distance, Euclidean, Length,
LineLocatePoint, LineString, MultiPolygon, Point, Polygon,
};
use geojson::{Feature, FeatureCollection, GeoJson, Geometry, JsonValue};
Expand Down Expand Up @@ -511,7 +511,7 @@ impl MapModel {
let road = self.get_r(*r);
let pt = road
.linestring
.line_interpolate_point(filter.percent_along)
.point_at_ratio_from_start(&Euclidean, filter.percent_along)
.unwrap();
let angle = limit_angle(angle_of_pt_on_line(&road.linestring, pt.into()) + 90.0);
let mut f = self.mercator.to_wgs84_gj(&pt);
Expand Down Expand Up @@ -558,7 +558,7 @@ impl MapModel {
let pt = self
.get_r(*r)
.linestring
.line_interpolate_point(filter.percent_along)
.point_at_ratio_from_start(&Euclidean, filter.percent_along)
.unwrap();
let mut f = self.mercator.to_wgs84_gj(&pt);
f.set_property("kind", "deleted_existing_modal_filter");
Expand Down Expand Up @@ -891,7 +891,11 @@ impl MapModel {
let mut highest_time_ratio: f64 = 1.0;
for r in from {
let road = self.get_r(r);
let pt1 = road.linestring.line_interpolate_point(0.5).unwrap().into();
let pt1 = road
.linestring
.point_at_ratio_from_start(&Euclidean, 0.5)
.unwrap()
.into();

// TODO How to handle missing one or both routes missing?
if let (Some(before), Some(after)) = (
Expand Down
24 changes: 10 additions & 14 deletions backend/src/movements.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use anyhow::Result;
use geo::{Euclidean, Length, Line, LineInterpolatePoint, Point, Polygon};
use geo::line_measures::InterpolatableLine;
use geo::{Euclidean, Line, Point, Polygon};
use geojson::GeoJson;
use itertools::Itertools;

Expand Down Expand Up @@ -211,20 +212,15 @@ impl Road {
/// Returns a point on the road this far away from the intersection. If the road is too short,
/// clamps at the other end of the road.
fn pt_from_intersection(&self, meters_away: f64, i: IntersectionID) -> Point {
let len = Euclidean.length(&self.linestring);

if len > meters_away {
let pct = if self.src_i == i {
meters_away / len
} else {
1.0 - (meters_away / len)
};
return self.linestring.line_interpolate_point(pct).unwrap();
if self.src_i == i {
self.linestring
.point_at_distance_from_start(&Euclidean, meters_away)
.unwrap()
} else {
self.linestring
.point_at_distance_from_end(&Euclidean, meters_away)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's a good use of the new api - we're using distance not ratio and computing from the end not the start.

Note that this method already clamps the output to the linestring.

.unwrap()
}

// If not, just take the other endpoint
let pct = if self.src_i == i { 1.0 } else { 0.0 };
self.linestring.line_interpolate_point(pct).unwrap()
}
}

Expand Down
4 changes: 2 additions & 2 deletions backend/src/neighbourhood.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,10 +482,10 @@ enum LineInPolygon {
}

// NOTE: polygon must be `valid` (no spikes!) to get reasonable results
fn line_in_polygon(
fn line_in_polygon<'a>(
linestring: &LineString,
polygon: &Polygon,
prepared_polygon: &PreparedGeometry,
prepared_polygon: &PreparedGeometry<'a, &'a Polygon>,
) -> LineInPolygon {
let perimeter_likelihood = perimeter_likelihood(&linestring, polygon);
// This is an arbitrary threshold - we could tune it if we're getting false positives/negatives
Expand Down
3 changes: 2 additions & 1 deletion data_prep/scotland/src/bin/generate_prioritization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ impl PopulationZoneInput {
Ok(population_zones)
}

fn read_all_prepared_from_file() -> Result<Vec<(PreparedGeometry<'static>, Self)>> {
fn read_all_prepared_from_file() -> Result<Vec<(PreparedGeometry<'static, MultiPolygon>, Self)>>
{
let iter = Self::read_all_from_file()?
.into_iter()
.map(|population_zone| {
Expand Down
3 changes: 2 additions & 1 deletion data_prep/scotland/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ impl StudyArea {
println!("Read {} study area boundaries", study_areas.len());
Ok(study_areas)
}
pub fn read_all_prepared_from_file() -> Result<Vec<(PreparedGeometry<'static>, Self)>> {
pub fn read_all_prepared_from_file(
) -> Result<Vec<(PreparedGeometry<'static, MultiPolygon>, Self)>> {
let iter = Self::read_all_from_file()?.into_iter().map(|study_area| {
(
PreparedGeometry::from(study_area.geometry.clone()),
Expand Down