[GIS] Rendering TopoJSON in Leaflet from GeoJSON PostGIS output

geojsonleafletpostgistopojson

I'm using the query found here SQL query to have a complete geojson feature from PostGIS to get a geojson that I can display on a leaflet map.

However, the amount of data is kinda big and the performance on Firefox is crappy (okay on Chrome), so I'm wondering if there is a way to convert the result of the query in Postgis into a topojson, in order to get a better performance

Best Answer

I'm not sure TopoJSON is the answer here. Under the covers leaflet-omnivore is converting the TopoJSON to GeoJSON and feeding that to Leaflet. Using d3js-topojson does exactly the same thing. In the end the polygons being rendered are the same wether sourced as TopoJSON or GeoJSON. You might need to consider simplifying your polygons. The only way you can really help the browser is to ask it to do less work. In this case that means fewer vertices so the browser has to draw fewer lines. Simplification can be done dynamically when requesting the data, but that introduces more latency. I'd suggest creating a second geometry columnn in your source table for storing simplified geometries.

Related Question