func Intersection(js geojson.GeoJSON) (*geojson.FeatureCollection, error) { polygons, err := geometryToPolygonList(js) if err != nil { return nil, err } var intersections []*s2.Polygon for i := 0; i < len(polygons); i++ { a := polygons[i] for j := i + 1; j < len(polygons); j++ { var c s2.Polygon b := polygons[j] c.InitToIntersection(a, b) intersections = append(intersections, &c) } } a := intersections[0] for i := 1; i < len(intersections); i++ { b := intersections[i] var c s2.Polygon c.InitToUnion(a, b) a = &c } return featureCollectionFromS2Polygon(a), nil }