Outputting and consuming TopoJSON
Since we're consuming vectors in a browser, let's have a look at TopoJSON too. TopoJSON is an extension of GeoJSON--the main difference is it encodes geometries shared by multiple features only once, so it is possible to reduce the footprint of the returned data. It is a popular format when it comes to serving vector tiles too. We will not get into detail on how to set up our own tile server; instead we will make our PostGIS output the data for us.
Note
There is a GeoServer plugin for exposing TopoJSON called vector tiles; some Node modules that can do the job are also available--just search npm for TopoJSON.
Let's get some data into the database first: download http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/50m/cultural/ne_50m_admin_0_countries.zip and load it into the webgis.countries
table:
shp2pgsql -s 4326 ne_50m_admin_0_countries webgis.countries | psql -h localhost -p 5434 -U postgres -d mastering_postgis
We will need to process...