Skip to content

Commit

Permalink
Get Lisbon DEM working and change costs
Browse files Browse the repository at this point in the history
  • Loading branch information
dabreegster committed Feb 25, 2024
1 parent afd3798 commit b86c01a
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 16 deletions.
29 changes: 23 additions & 6 deletions examples/lisbon/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,30 @@
"destinations_path": "schools.geojson"
},
"cost": {
"ByLTS": {
"lts1": 1.0,
"lts2": 1.5,
"lts3": 3.0,
"lts4": 5.0
"OsmHighwayType": {
"cycleway": 8,
"footway": 20,
"living_street": 10,
"motorway": 30,
"motorway_link": 30,
"path": 10,
"pedestrian": 10,
"primary": 15,
"primary_link": 15,
"residential": 20,
"secondary": 12,
"secondary_link": 12,
"service": 10,
"steps": 40,
"tertiary": 11,
"tertiary_link": 11,
"track": 10,
"trunk": 30,
"trunk_link": 30,
"unclassified": 10
}
},
"uptake": "Identity",
"lts": "BikeOttawa"
"lts": "BikeOttawa",
"elevation_geotiff": "LisboaIST_10m_4326.tif"
}
8 changes: 3 additions & 5 deletions examples/lisbon/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ def makeOSM():


def makeElevation():
# TODO LisboaCOPERNICUS_clip.tif doesn't have any errors, but no data seems to get scraped
# TODO LisboaIST_clip_r1.tif is apparently missing a TIF signature?
download(
url="https://github.com/U-Shift/Declives-RedeViaria/raw/main/raster/LisboaCOPERNICUS_clip.tif",
outputFilename="input/LisboaCOPERNICUS_clip.tif",
url="https://assets.od2net.org/input/LisboaIST_10m_4326.tif",
outputFilename="input/LisboaIST_10m_4326.tif",
)


Expand All @@ -52,6 +50,6 @@ def makeDestinations():
checkDependencies()
run(["mkdir", "-p", "input"])
makeOSM()
#makeElevation()
makeElevation()
makeOrigins()
makeDestinations()
10 changes: 9 additions & 1 deletion od2net/src/network/create_from_osm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,20 @@ impl Network {
if let Some(bytes) = geotiff_bytes {
timer.start("Calculate elevation for all edges");
let mut geotiff = GeoTiffElevation::new(Cursor::new(bytes));
let mut succeeded = 0;
let progress = utils::progress_bar_for_count(network.edges.len());
for (_, edge) in &mut network.edges {
progress.inc(1);
edge.apply_elevation(&mut geotiff);
if edge.apply_elevation(&mut geotiff) {
succeeded += 1;
}
}
timer.stop();
println!(
"Got elevation for {} / {} edges",
HumanCount(succeeded as u64),
HumanCount(network.edges.len() as u64)
);
}

timer.start("Calculate cost for all edges");
Expand Down
11 changes: 7 additions & 4 deletions od2net/src/network/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,20 @@ pub struct Edge {
}

impl Edge {
/// Sets `slope` and `slope_factor`.
pub fn apply_elevation<R: Read + Seek + Send>(&mut self, geotiff: &mut GeoTiffElevation<R>) {
/// Sets `slope` and `slope_factor` if true. If false, failed to get data.
pub fn apply_elevation<R: Read + Seek + Send>(
&mut self,
geotiff: &mut GeoTiffElevation<R>,
) -> bool {
let Some(slope) = self.get_slope(geotiff) else {
// Silently return if this fails
return;
return false;
};
self.slope = Some(slope);
self.slope_factor = Some((
calculate_slope_factor(slope, self.length_meters),
calculate_slope_factor(-slope, self.length_meters),
));
true
}

fn get_slope<R: Read + Seek + Send>(&self, geotiff: &mut GeoTiffElevation<R>) -> Option<f64> {
Expand Down
1 change: 1 addition & 0 deletions viewer/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
<option value="london">London</option>
<option value="seattle">Seattle</option>
<option value="york">York</option>
<option value="lisbon">Lisbon</option>
</select>
</label>
</div>
Expand Down

0 comments on commit b86c01a

Please sign in to comment.