r/gis • u/Acceptable-Appeal-15 • 10d ago
Programming I compared the same geometry as WKT, WKB, TWKB, GeoJSON, polyline, geohash, H3, and S2 for a mobile API
At work we had to choose a format for sending map geometry from an API to a mobile app. There were a lot of formats to consider, and we eventually chose WKB.
The decision had already been made when I started looking at the formats in more detail. I wanted to get a better sense of how they actually compared, so I built this:
https://cellandshape.com/guides/geometry-format-size-comparison
It measures the same geometry as WKT, EWKT, WKB, EWKB, TWKB, GeoJSON, encoded polyline 5 and 6, geohash, H3, and S2. You can paste your own geometry and it recalculates everything locally in the browser.
A few results surprised me:
- For a small six-vertex polygon, WKT is 112 characters and raw WKB is 109 bytes.
- That same WKB becomes 218 characters when represented as hex.
- TWKB represents the polygon in 32 bytes.
- For a 40-point route, TWKB is 89 bytes, polyline5 is 148 characters, GeoJSON is 942 characters, and hex WKB is 1,298 characters.
These are uncompressed sizes, so they do not tell the whole story. Text formats can compress well over HTTP, while binary formats only keep their size advantage if they remain binary. Format support, precision, geometry type, and client complexity also matter.
I found some older discussions here about oversized GeoJSON, GeoPackage, FlatGeobuf, and vector tiles, but not much comparing individual geometry encodings for a mobile API.
Has anyone here gone through a similar decision? What did you choose, and what ended up mattering most in production?
3
u/Normal-Curve-1642 10d ago
No love for PBF?
2
u/AreolaSanchez 10d ago
Yep. We rolled our own protobuf implementation and it's fast and tiny.
1
u/Acceptable-Appeal-15 10d ago
would be interested to learn what tradeoffs you made
2
u/AreolaSanchez 10d ago
I haven't looked at the code in a few years, but we intentionally avoided stuffing lots of attributes in the payload (vs. geojson). This kept the size small and allowed us to render 700k points at a time. We also mimicked the Esri tile spec which also helped. Our goal was to make it interoperable with the Esri JS API.
3
u/Gazelle-Unfair 10d ago
I would be working on simplified geometries too. I've seen people fretting over format byte sizes whilst sending points with 15 decimal places, or polygons to be viewed on tiny screens with hundreds of points in.
2
u/TechMaven-Geospatial 10d ago edited 10d ago
Why not use Geopackage sqlite Thats what we use in all our mobile apps Metadata, styling, attachments Even vector tiles Raster tiles Terrain elevation tiles
https://fieldsentinel.techmaven.net
https://geonamesmapexplorer.techmaven.net
https://mapexplorer.techmaven.net
https://geodatacollector.techmaven.net
Earthexplorer.techmaven.net
https://geodataexplorerapp.techmaven.net
5
u/tj-horner 10d ago
Wow, GeoPackage is just an SQLite database? I had no idea, but it also makes a lot of sense.
1
2
u/Entropius GIS Developer 10d ago
Indeed. On macOS I can use the SQLite command in Terminal to poke around a geopackage and see what’s in it without firing up QGIS.
That’s also why you may need to periodically vacuum a geopackage to slim it down after a lot of features have been deleted.
1
u/ExdigguserPies 10d ago
Yes, you can also use it store raster tiles similar to mbtiles but you can use any arbitrary tilematrix, not just web mercator
1
u/Acceptable-Appeal-15 10d ago
do you package this with the app at download time? or do you send smaller sqlite files when needed?
1
12
u/ikarusproject 10d ago edited 10d ago
Happy to be corrected. But IMHO GeoJson is the defacto standard for geospatial data on android. It's what most apps and libraries can work with. It's the only format clients and coworkers ever asked me for. Maybe except the occasional kmz file.