mapbox / mapbox/geobuf

Decode fails on POINT type (incompatibility with other PBF serializers)

Open
#77 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.