Decode fails on POINT type (incompatibility with other PBF serializers)
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 1k
- Forks
- 86
- PR merge metrics
- No merged PRs in 30d
Description
By default, C# and Swift (and possibly other) Protobuf libraries do not encode first enum values. If the value is missing when decoded, those libraries assume the first enum value as default. The problem occurs when trying to pass PBFs encoded this way to decode.js. The readCoords function is checking for type, which if it's a POINT, is undefined. Obviously, this impacts anything expecting valid GeoJSON.
I dislike suggesting that something like this be used:
if (type === 'Point' || type === undefined ) geom.coordinates = readPoint(pbf);
It's sloppy because there might be other issues that caused an undefined condition. Perhaps a try-catch block to provisionally attempt to read coordinate data might be a solution. I just did a quick 'n' dirty test using:
else if (type === undefined) {
try {
geom.coordinates = readPoint(pbf);
if (geom.coordinates.length !== 3) {
throw "Invalid geometry for Point.";
}
geom.type = "MultiPolygon";
} catch (err) {
}
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in decode.js at readCoords and readPoint, then inspect how POINT geometry type information is decoded. Determine how missing enum values from C# or Swift serializers can be distinguished from malformed geometry, and verify that valid POINT PBFs produce valid GeoJSON coordinates.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- data
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100