Routing in 3D: Blazing Trails with Open Source GIS ???
Finding the optimal path from A to B
- it's a fundamental problem in transportation, logistics, and mobility.
But add an extra dimension to the mix?
Now we're cooking with 3D routing! ??
From planning drone flight paths that clear obstacles,
to identifying autonomous vehicle routes with minimum elevation changes,
to charting hiking trails through mountainous terrain
- 3D routing unlocks a world of high-precision navigation opportunities.
And just like with 3D visualization,
there's an incredible open source software ecosystem we can tap into
for building robust 3D routing engines and visualization frontends.
Let's take a look!
The 3D Routing Engine
At the core is a high-performance routing engine that can calculate paths through 3D terrain data.
Here are some powerful open source options:
To enable 3D routing in GraphHopper,
we load a 3D terrain model alongside the road network data:
// Prepare data
import os
import graphhopper as gh
# Load road network
gh.init_data(os.path.join(os.getcwd(), "road-network.osm.pbf"))
# Load 3D terrain model
gh.import_elevationdata(os.path.join(os.getcwd(), "terrain.tif"))
# Set vehicle profile with 3D support
profile = gh.AlgorithmOptions('automobilehybrid3d|shortest|3D')
With OSRM, we can generate a 3D mesh from elevation data during data preparation:
# Merge road network and height data
osrm-extract -p /opt/truck.lua planet.osrm --meshes elevation.xyz
# Generate 3D routing mesh
osrm-partition planet.osrm
osrm-customize planet.osrm
Now our engines are ready to calculate
3D-aware paths that factor in slope,
elevation changes, obstacles, and more!
The next step is visualizing those 3D routes...
3D Routing Visualization
To render those spatially-optimized 3D routes in a web viewer,
we'll again use the unstoppable CesiumJS engine.
领英推荐
Cesium provides APIs for drawing dynamic polylines representing our calculated routes.
First, we expose a route calculation endpoint from our 3D routing engine:
// server.js
const graphhopper = require('@graphhopper/js-client');
app.get('/route', async (req, res) => {
const { start, end } = req.query;
const route = await graphhopper.route({
point: [start, end],
vehicle: 'automobilehybrid3d'
});
res.json(route);
});
Then in our Cesium viewer, we can fetch and draw the calculated 3D route on the globe:
// Fetch 3D route data
const routeResponse = await fetch(`/route?start=${start}&end=${end}`);
const routeData = await routeResponse.json();
// Draw route on 3D globe
const routeGeometry = Cesium.Cartesian3.fromDegreesArray(routeData.path);
const routeInstance = new Cesium.GeometryInstance({
geometry: new Cesium.GroundPolylineGeometry({
positions: routeGeometry,
width: 5,
vertexFormat: Cesium.EllipsoidGeodesic
}),
attributes: {
color: Cesium.ColorGeometryInstanceAttribute.fromColor(
new Cesium.Color(1.0, 0.5, 0.0, 0.5)
)
}
});
viewer.scene.groundPrimitives.add(new Cesium.GroundPolylinePrimitive({
geometryInstances: routeInstance
}));
The Cesium renderer will automatically drape that route path over the 3D terrain surface!
We can enhance the visualization even further by:
- Color-coding the route by slope, elevation, etc using Cesium's Vector Tile capability
- Animating vehicles along the calculated route
- Integrating turn-by-turn navigation guidance
And since Cesium builds on top of WebGL and WebAssembly,
we get buttery smooth performance for even the largest routing datasets.
The Open Infinity Loop ??
By combining cutting-edge open source routing engines with the power of Cesium's 3D visualization,
we've unlocked robust 3D routing and navigation capabilities for web and mobile apps.
Whether optimizing human navigation experiences or powering next-gen autonomous mobility,
accurate 3D routing intelligence is a crucial enabler.
And now we can bring that spatial intelligence directly into high-fidelity 3D interfaces and digital twins.
The possibilities are endless when you interweave all the brilliant open source projects in geospatial computing.
Have another awesome open source tool for 3D routing you'd suggest?
Let me know in the comments!
With each open source solution we integrate, we unlock new dimensions of innovation. Let's keep looping through this open ecosystem to craft boundary-pushing spatial apps and experiences. The future of mobility is being built on open code! ?????
President at Pacific Spatial Solutions Inc.
9 个月Awesome! I want to try your approach as well as pgrouting. Thank you for your inspiring work.
Geospatial/GIS/IT all rounder currently working as GIS Specialist at Level Crossing Removal Project with Australian Government Baseline Security Clearance
9 个月Interesting blog. What I am not sure about is which function in PDAL creates cross-section profiles as there is no example of it in the blog and I cannot seem to find out in the PDAL documentation.