Developer Notes

Compressing geographical polygon data in Shapefiles

The Shapefile format is a commonly used file format for storing boundaries of geographical areas in maps, which are represented by polygons.

There is a Ruby gem rgeo-shapefile which enables Ruby applications to read data directly from Shapefiles. However, if the boundaries are very precise with a lot of vertices specified:

  1. The Shapefile can grow very large. For example, the SHP file from the TIGER/Line data for postcode areas in the USA is over 800 MB.
  2. Reading data from the Shapefile can take a long time.
  3. Sending data to the UI can also take a long time. We sometimes need to do this to be able to mark geographical areas in a mapping library such as Google Maps.
  4. The browser and the mapping library need to use more resources to render boundaries in the map.

Usually, we do not need the geographical boundaries to be very precise so compressing the polygon data is acceptable.

I was able to sufficiently compress the TIGER/Line SHP file using the free QGIS software. It turns out that not all Shapefile compression algorithms work well with geographical data, but the Douglas-Peucker algorithm had good results.

To compress polygon data in a Shapefile using QGIS:

  1. Go to Vector > Geometry Tools, and use Simplify Geometries. The tolerance I used was 0.0004.
  2. Go to Vector > Geometry Tools, and use Polygons to Lines.
  3. Go to Vector > Geometry Tools, and use Lines to Polygons.

I believe the last two steps above help ensure that the compressed polygons are closed.

See this and this for more information.

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Articles

Want your website to turn up in Google Search results? You can submit your website for indexing in Google Search
Occasionally, we need to bring our website visitors to a maintenance page. Don't worry, you can spin up a Maintenance
When you are deploying changes to a WordPress website, you might encounter an error about PHP's upload_max_filesize. Here is one
After installing Android Studio in Ubuntu, you might experience getting a blank screen instead of the Android Studio Setup Wizard.
It might surprise you how much storage space Snap packages use. You will most likely find that your Snap packages
The Loop Grid widget allows you to set the total number of items to load and display in the Loop

Recent Articles

Topics

Related Topics