Skip to content

Fix incorrect coordinate length check for parsing polygons#7

Open
bziya wants to merge 1 commit intopiemadd:mainfrom
bziya:fix-polygon-length-check
Open

Fix incorrect coordinate length check for parsing polygons#7
bziya wants to merge 1 commit intopiemadd:mainfrom
bziya:fix-polygon-length-check

Conversation

@bziya
Copy link
Copy Markdown

@bziya bziya commented Oct 19, 2025

This PR introduces a fix for a bug that I found when parsing data from Melbourne Australia. For some reason there is a building in the downloaded data that I guess did not have the correct data to parse properly.

I followed the stack trace below:

error: Each LinearRing of a Polygon must have 4 or more Positions.
at polygon (C:\Users\xxx\Documents\subwaybuilder-patcher\node_modules@turf\helpers\dist\esm\index.js:97:17)
at <anonymous> (C:\Users\xxx\Documents\subwaybuilder-patcher\scripts\process_data.js:288:34)
at forEach (1:11)
at processBuildings (C:\Users\xxx\Documents\subwaybuilder-patcher\scripts\process_data.js:265:16)
at <anonymous> (C:\Users\xxx\Documents\subwaybuilder-patcher\scripts\process_data.js:435:30)

I saw that in the code it is checking that the polygon has at least 3 positions, when the code in the turf module will throw an error if there are <4 positions.

I have modified the code to run a check before the turf.polygon() function is called that there are enough positions, otherwise the building in skipped.

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.

1 participant