GeoJSON is a great format, easy to read/view/use but one thing that really stands out is the verbosity of numbers and its effects on file size.  Yeah in rare cases it “may” be needed but I’m pretty sure a length that is precise to, well less than a millimeter (example: stream length: 6849.41980435 meters) is never needed.  And the other pink elephant in GeoJSON is the number of sig figs used for geometry!

	"type": "FeatureCollection", 
	"features": [{
		"geometry": {
		"type": "Polygon",
		"coordinates": [[[-120.37273534694833, 50.67716016936108], [-120.37080246306458, 50.67707673658443], [-120.36562460360317, 50.675414824845106]...

I’m sure there’s lots of techniques to decrease the size of a GeoJSON file for transport but one of the more popular is TopoJSON.  I guess technically not a GeoJSON format but worth mentioning.  It reduces file size by not replicating geometry(simplifying a lot here) similar to the old ESRI Coverage files.  But what I wanted to see is, what if we stuck with the GeoJSON format but ran the geometry through the Encoded Polyline Algorithm (EPA) and then throw the results up on a map to see how much faster it would be if any.

How To

Firstly, I need to convert the shapefile to geojson and to do that I’ll use the script.

pixel:data dustin$ -e Neighbourhoods.shp Neighbourhoods.egeojson 

The script does a couple things, first it transforms the coordinates to WGS84 and second by adding the -e option the EPA is applied to the geometry. The new geometry structure will look something like this…

	"type": "FeatureCollection",
	"features": [{
		"geometry": {
			"type": "Polygon",
			"coordinates": ["g{htHphu}UPaKjIk_...","}eitHrex}[email protected]", ...] NOT SO PINK ANYMORE!!

Well, now I have this GeoJSON file, let’s see if it draws!  We’ll employ leaflet to do this since it’s super easy to make a map and has a great plugin called Leaflet.encoded that can read encoded geometry.  I’ve also added some extra code to read regular geojson geometry so I could generate some simple metrics to see how things perform.  All the code is available on github if you want to take it for a spin!


Although the drawing times were slower in my simple tests, load times more than made up for the difference.  Below is my test results on using three different shapefiles.  Would be interesting to see the comparison to TopoJSON ;).

# of features2631,147143
Shapefile (in kB) *80663,409595
GeoJSON GZipped (in kB)**707.117,948551
GeoJSON (in kB)2,11168,7281,540
Load (ms)3,467.516,116.11,690.8
Draw (ms)187.210,367.7189
GeoJSON Enc. Geom. GZipped (in kB)** 563,221.370
GeoJSON Enc. Geometry (in kB)11023,750124
Load (ms)536.14,599614.6
Draw (ms)256.110,421223.3

* includes shp, dbf, shx, prj

** GZip command used: gzip -c Neighbourhood.geojson > Neighbourhood.geojson.gz

Technologies Used

Shp2json script uses:

Map uses:

Sharing options

Observations • Brian Bancroft

Convert Data to GeoJSON in a JavaScript App

Geospatial data conversion is a task that is well-covered by many tools. In the open-source world, there’s our beloved GDAL. GDAL is a command-line utility that converts data…

teal and red abstract painting

Observations • Will Cadell

/quick-map for Slack Update

Sometimes a chat needs a map, sometimes a map needs a chat. Either way, we created /quick-map last year to provide that functionality in Slack, the leading corporate…

Observations • Julien Jacques

Coral Reef Dataset Pipeline

Facing climate change and severe coral reef bleaching, which causes coral reefs to die off, coral reef scientists have been embracing new technologies to help diagnose the overall…

Need a geospatial partner?

Our team complements organizations like yours—by providing on-tap access to geospatial, analytics, and mapping expertise.

Let’s talk

Join our team?

We’re always looking for skilled technologists to help us build the future of geospatial. Got a minute to find out more about us?

Working Here

Sharing options