Skip to content

Fix getShapesAsGeoJSON returning reversed shape coordinates#203

Merged
brendannee merged 1 commit into
BlinkTagInc:masterfrom
c-tonneslan:fix/shape-geojson-reversed-coordinates
Jul 7, 2026
Merged

Fix getShapesAsGeoJSON returning reversed shape coordinates#203
brendannee merged 1 commit into
BlinkTagInc:masterfrom
c-tonneslan:fix/shape-geojson-reversed-coordinates

Conversation

@c-tonneslan

Copy link
Copy Markdown
Contributor

While using getShapesAsGeoJSON() I noticed the returned line geometry was off — the coordinates come back reordered, with a point duplicated and the last one dropped, so the line doesn't trace the actual shape.

It's in consolidateShapes (src/lib/geojson-utils.ts). When it builds the direction-agnostic dedupe key it calls segment.reverse(), which reverses segment in place. That same segment is then used just below (segment[0], segment[1]) to append points to the line, so every segment ends up added in reverse.

For a shape [P0, P1, P2, P3] you get [P1, P0, P1, P2] instead of [P0, P1, P2, P3]. The existing tests only asserted the coordinate array length, which the bug preserves, so it wasn't caught.

The fix copies the segment before reversing it for the key. I added an ordering assertion to the cal_sf_tam shape test (fails before, passes after); the full suite still passes.

consolidateShapes reversed each segment in place while building its
dedupe key, so the line was then built from the reversed points.

Signed-off-by: Charlie Tonneslan <cst0520@gmail.com>
@brendannee

Copy link
Copy Markdown
Member

Great catch - thanks for documenting this and the pull request!

@brendannee
brendannee merged commit 333acb5 into BlinkTagInc:master Jul 7, 2026
3 checks passed
@brendannee

Copy link
Copy Markdown
Member

The latest version https://github.com/BlinkTagInc/node-gtfs/releases/tag/4.19.3 has this fix included.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants