I have administrative boundary data in geojson/wkt format, which I retrieve from my REST service and display, using mapbox gl. This works well enough, but the data points are (depending on the country) extremely dense, resulting in several megabytes of data for each request, which is simply too much.

Mapbox does a great job at handling and rendering the data once received - the problem is the sheer amount of data transferred. I am ok with reducing the data "fidelity" of my source data, but I would like to do it intelligently, if at all possible. The question is: what tool (preferably cost-free) should I use to reduce the data points ? This question deals with almost the same problem, but is "dropping every n-th data point" really the best/only answer to my problem ? Skim-reading this blog post suggests that there might be more intelligent solutions. I have QGIS 3.0 installed - does it offer some functionality like this ? I also looked at GeoJSON-VT but am not sure if that is fit for the task, either.

  • Sure enough, minutes after posting, I found github.com/jczaplew/geojson-precision – Hiro Protagonist Mar 8 at 10:00
  • I think you are trying to reduce number of node or vertex in your polygon. In QGIS 3.0 it is called Simplify (previously called Simplify geometries). – Kazuhito Mar 8 at 10:13
  • How is your REST service implemented? How are your data stored? – atlefren Mar 8 at 15:24
  • @atlefren It is a Java-based service that returns a StreamingOutput of the geojson features. The data is stored in an object database. Having read this I believe that the answer is not to reduce the number of vertices in my WKT polygons, but rather to reduce the precision. I am "lucky" (in a sense) because my data contains point coordinates which all consist of 16 digits after the comma - which is pointless. So if I reduce to 4 or 5 digits, I get the savings I want. – Hiro Protagonist Mar 9 at 9:57
up vote 0 down vote accepted

The solution I chose was:

  • to load the shapefile data into QGIS, export/save it as geojson with a precision of 5 digits
  • split the single, huge geojson file into smaller chunks
  • convert those chunks to csv files using the "as wkt" option
  • re-join the csv chunks and
  • import the csv into my object database

I ended up writing a powershell script to handle all those steps.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.