Skip to content

Commit

Permalink
Fix very silly problem in GeoJSON importer
Browse files Browse the repository at this point in the history
  • Loading branch information
dabreegster committed Apr 5, 2024
1 parent 36a7cd5 commit d65a21d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ changes.

- Removed `fetchWithProgress`, which is a general-purpose utility method that
should come from another library
- Improved the tool that makes graphs from GeoJSON files by splitting
LineStrings that touch at interior points

## 0.4.0

Expand Down
15 changes: 8 additions & 7 deletions geojson-to-route-snapper/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ pub fn convert_geojson(input_string: String) -> Result<RouteSnapperMap> {
// Split each LineString into edges
let mut node_id_lookup: HashMap<(isize, isize), NodeID> = HashMap::new();
for edge in input {
let mut point1 = *edge.geometry.coords().next().unwrap();
let mut point1 = edge.geometry.0[0];
let mut pts = Vec::new();

let num_points = edge.geometry.coords_count();

for (idx, pt) in edge.geometry.into_inner().into_iter().enumerate() {
pts.push(pt);
// Edges start/end at intersections between two LineStrings. The endpoints of the
Expand All @@ -49,12 +50,12 @@ pub fn convert_geojson(input_string: String) -> Result<RouteSnapperMap> {
let node1_id = *node_id_lookup
.entry(hashify_point(point1))
.or_insert_with(|| {
map.nodes.push(geometry.0[0]);
map.nodes.push(point1);
next_id
});
let next_id = NodeID(node_id_lookup.len() as u32);
let node2_id = *node_id_lookup.entry(hashify_point(pt)).or_insert_with(|| {
map.nodes.push(*geometry.0.last().unwrap());
map.nodes.push(pt);
next_id
});
map.edges.push(Edge {
Expand All @@ -69,11 +70,11 @@ pub fn convert_geojson(input_string: String) -> Result<RouteSnapperMap> {
});
map.override_forward_costs.push(edge.forward_cost);
map.override_backward_costs.push(edge.backward_cost);
}

// Start the next edge
point1 = pt;
pts.push(pt);
// Start the next edge
point1 = pt;
pts.push(pt);
}
}
}

Expand Down
13 changes: 9 additions & 4 deletions user_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,18 @@ cd geojson-to-route-snapper
cargo run --release -- --input path_to_network.geojson
```

The LineStrings must represent edges, meaning the ends need to have the same
coordinate as other LineStrings. Each LineString has some properties:
For routing to work, the LineStrings must share points with other LineStrings.
If you have one long LineString touching many others and the points are the
same, these will be split into edges automatically. LineStrings that cross but
don't share points (within 7 decimal places) won't connect.

Each LineString has some properties:

- an optional numeric `forward_cost` and `backward_cost`.

Costs **must** be specified for some of the edges in the file.
If a cost is missing, the edge won't be routable in that direction.
Costs **must** be specified for some of the edges in the file. If a cost is
missing, the edge won't be routable in that direction. Use `null` to indicate
the edge isn't routable at all in that direction.

- an optional string `name`.

Expand Down

0 comments on commit d65a21d

Please sign in to comment.