News for hackers. Stuff that matters.
Re:How to Make Maps Using Leaflet.js, PostGIS and Chicago Op... by dbetteridge on Monday April 29, 2019 @10:38PM (#19784658)
A fun tip, if you're using PostGIS you can actually generate the Geojson directly in the SQL query with http://www.postgis.org/docs/ST_AsGeoJSON.html

and if you're running a version of PostGIS with protobuffers enabled (Not AWS RDS) you can generate vector tiles on the fly with https://postgis.net/docs/ST_AsMVT.html which are great for displaying large datasets.

Re:How to Make Maps Using Leaflet.js, PostGIS and Chicago Op... by dylrich on Monday April 29, 2019 @10:58PM (#19784758)
RDS now supports libprotobuf-c, so AsMVT will work (at least on some postgres versions)
Re:How to Make Maps Using Leaflet.js, PostGIS and Chicago Op... by dbetteridge on Monday April 29, 2019 @11:03PM (#19784783)
Well thats the best news i've had today. Thanks!

https://dba.stackexchange.com/questions/202049/support-for-l...

v10.5 of postgres by the looks of it, don't know how I missed that.

Re:How to Make Maps Using Leaflet.js, PostGIS and Chicago Op... by samblogs on Monday April 29, 2019 @10:44PM (#19784684)
The vector file seems really useful. I ran a query that resulted in a 1.5 GB geojson file... much too big for Leaflet. Maybe the Vector tile would be compact enough? Thanks!
Re:How to Make Maps Using Leaflet.js, PostGIS and Chicago Op... by mr_toad on Tuesday April 30, 2019 @05:04AM (#19786254)
Re:How to Make Maps Using Leaflet.js, PostGIS and Chicago Op... by dbetteridge on Monday April 29, 2019 @10:51PM (#19784729)
Yeah I know that pain.

You'll need the MapboxVectorTiles plugin for leaflet but you can definitely improve the sizes by a fair bit.

Re:How to Make Maps Using Leaflet.js, PostGIS and Chicago Op... by Demiurge on Tuesday April 30, 2019 @08:07AM (#19787156)
When you're doing tiles, you need to simplify to highest resolution actually discernible in that tile. So, for each zoom level, generate bbox tile bounds, and then simplify or cluster everything in each tile for the pixel resolution you want. That way you will never have 1.5GB tile. After all, all that data is wasted space if it can't be seen.

I've done this for GeoJSON tiles for a long time, before the MVT tiles. The MVT tiles pack way more data though, but are not a solution to the O(n2) problem.

Re:How to Make Maps Using Leaflet.js, PostGIS and Chicago Op... by gloflo on Tuesday April 30, 2019 @05:25AM (#19786345)
Reduce the precision, 15 decimal places are useful for picometers, not a web map. Try 5-6.
Re:How to Make Maps Using Leaflet.js, PostGIS and Chicago Op... by Demiurge on Tuesday April 30, 2019 @08:16AM (#19787217)
It never seems worth the effort in my testing, as you have to come up with your own loop to do the truncating, and the benefit is marginal. In this case he’d have 1.2gb file, I doubt that fixes the problem.
Re:How to Make Maps Using Leaflet.js, PostGIS and Chicago Op... by durkie on Tuesday April 30, 2019 @08:43AM (#19787382)
for what it's worth, ST_AsGeoJSON lets you specify decimal precision as an optional argument, so you at least don't have to write a truncating loop.

Another good option with many polygon geometries is Base64 encoding the output of ST_AsGeobuf -- it is many times smaller than GeoJSON and still pretty easy to handle from Javascript. (Needs libprotobuf-c on the PostGIS side and geobuf.js+pbf.js on the JS side)

Re:How to Make Maps Using Leaflet.js, PostGIS and Chicago Op... by Demiurge on Tuesday April 30, 2019 @09:24AM (#19787654)
Thats cool, I should try AsGeobuf as a soft upgrade to one of the older tile GeoJSON site :)
Re:How to Make Maps Using Leaflet.js, PostGIS and Chicago Op... by chippy on Tuesday April 30, 2019 @06:35AM (#19786704)
Does GCP Cloud SQL have protobuffers enabled?