in h3.go [573:637]
func CellsToMultiPolygon(cells []Cell) ([]GeoPolygon, error) {
if len(cells) == 0 {
return nil, nil
}
h3Indexes := cellsToC(cells)
cLinkedGeoPolygon := new(C.LinkedGeoPolygon)
if err := toErr(C.cellsToLinkedMultiPolygon(&h3Indexes[0], C.int(len(h3Indexes)), cLinkedGeoPolygon)); err != nil {
return nil, err
}
currPoly := cLinkedGeoPolygon
var countPoly int
for currPoly != nil {
countPoly++
currPoly = currPoly.next
}
ret := make([]GeoPolygon, countPoly)
// traverse polygons for linked list of polygons
currPoly = cLinkedGeoPolygon
countPoly = 0
for currPoly != nil {
currLoop := currPoly.first
var countLoop int
for currLoop != nil {
countLoop++
currLoop = currLoop.next
}
loops := make([]GeoLoop, countLoop)
// traverse loops for a polygon
currLoop = currPoly.first
countLoop = 0
for currLoop != nil {
currPt := currLoop.first
var countPt int
for currPt != nil {
countPt++
currPt = currPt.next
}
loop := make([]LatLng, countPt)
// traverse points for a loop
currPt = currLoop.first
countPt = 0
for currPt != nil {
loop[countPt] = latLngFromC(currPt.vertex)
countPt++
currPt = currPt.next
}
loops[countLoop] = loop
countLoop++
currLoop = currLoop.next
}
ret[countPoly] = GeoPolygon{GeoLoop: loops[0], Holes: loops[1:]}
countPoly++
currPoly = currPoly.next
}
C.destroyLinkedMultiPolygon(cLinkedGeoPolygon)
return ret, nil
}