Slices of Slices of Slices in Go

Ardan Labs Blog on ·

I am working on building code to load polygons for the different Marine Forecast areas in the United States. These polygons need to be stored in MongoDB and there is a special way that needs to be done. It would not have been a big deal if it wasn’t for this fact. There isn’t just one polygon for each area. There is an external polygon and then zero to many interior polygons that need to be stored in relationship.

After staring at the problem for a bit I realized that I needed to create a slice of Marine Forecast areas, each of which contained a slice of polygons. To store each polygon ring I needed a slice of geographic coordinates. Finally each coordinate needed to be stored in a two dimensional array of floats.

A picture is worth a thousand words: