Invalid `LineString` is not reported and breaks further
- Dominant language
- JavaScript
- Stars
- 1k
- Forks
- 86
- PR merge metrics
- No merged PRs in 30d
Description
One of our GeoJSON features violates https://tools.ietf.org/html/rfc7946#section-3.1.4:
> For type "LineString", the "coordinates" member is an array of two or more positions.
Our feature looks like this:
```
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "LineString",
"coordinates": []
}
}
```
We normally generate the coordinates from a list of recorded locations, so if there aren't enough recorded locations, we violate the spec. Similar to this mapbox sample, which also runs into the same issue: https://docs.mapbox.com/mapbox-gl-js/example/animate-a-line/
However, mapbox-gl-js (internally geojson-vt) happily accepts this GeoJSON.
When we run geobuf on this, the generated feature looks like this:
```
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "LineString"
}
}
```
So the entire coordinates field is removed.
Suddenly mapbox-gl-js (internally geojson-vt) trips on this.
[It's assumed to exist here](https://github.com/mapbox/geojson-vt/blob/35f4ad75feed64e80ff2cd02994976c6335859cd/src/convert.js#L28) and then accessed during conversion, which leads to errors.
I did not check if a similar issue exists for other types, but I'd assume so.
Contributor guide
Research direction
Start by reproducing the geobuf conversion with the invalid LineString shown in the issue, then trace the encoding path that removes its empty coordinates field. Compare the result with geojson-vt's expected input and verify that invalid LineStrings no longer produce a downstream conversion failure, including any similar geometry types identified during investigation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- data
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100