paulmach / orb

Types and utilities for working with 2d geometry in Golang
MIT License
910 stars 103 forks source link

marshal geojson ids into mvt uint64 if possible #10

Closed paulmach closed 6 years ago

paulmach commented 6 years ago

The encoding/mvt package converts geojson into mapbox vector tiles (mvt). The problem is geojson allows ids of strings and numbers while mvt only allows uint64 (positive numbers). This is a common incompatibility between the two types.

For marshaling, the change is to try to convert the geojson.Feature.ID into an uint64. If it's a number type and positive, it converts to unit64. If it's a string it tries to decode.

Cavets:

Unmarshaling code was also updated to decode ids into float64 to be consistent with what json does with numbers. That way if you have the same data in geojson or mvt the decoded types will be the same.

@jerluc

jerluc commented 6 years ago

@paulmach this looks great, and I definitely appreciate the best-effort approach to encoding the ID properly depending on the original type.

Hopefully in MVT v3, this should conform better to the GeoJSON specification, but for now, this'll be a very helpful bridge.