CodeWithAloha / Hawaii-Zoning-Atlas

Interactive map showing how outdated zoning laws make it hard to build diverse, affordable housing in Hawaii.
https://hawaiizoningatlas.com
MIT License
22 stars 11 forks source link

💡 [REQUEST] - Minify geojson files #97

Closed ggordn3r closed 12 months ago

ggordn3r commented 1 year ago

Start Date

8/21/23

Implementation PR

No response

Reference Issues

No response

Summary

Several of the geojson files we use are needlessly detailed and slowing down performance. There are two basic ways to reduce a spatial file:

1) Dissolve many polygons into fewer polygons (sometimes just one), eliminating internal lines. 2) Simplify lines by removing points that don't make a discernable difference at our map's scale. In some cases that can be 90% or more!

In the examples section I list several geojson files that could benefit from one or both of these treatments. For dissolve, you can use built-in geopandas (Python, see link above). For simplifying lines, I recommend Visvalingam’s algorithm, which is not implemented in geopandas, but is in this handy online interface: https://mapshaper.org/

Basic Example

I think it's possible to reduce files <= 4 MB down to 250 KB or less, and the hydro file to < 1 MB with minimal loss of visual detail.

Drawbacks

We may lose a bit of visual detail, but in theory the loading time and lagginess would be cut by 40%--well worth the tradeoff.

Unresolved questions

We are trying to preserve final.geojson at maximum detail, but it is the biggest file (23 MB). If performance problems persist, we may need to reduce that as well.