github.com/seeker-insurance/kit@v0.0.13/geojson/polygon.go (about) 1 package geojson 2 3 import "strings" 4 5 type Polygon []Point 6 7 func (poly Polygon) Coordinates() string { 8 coords := make([]string, len(poly)) 9 for i, p := range poly { 10 coords[i] = p.Coordinates() 11 } 12 return "[" + strings.Join(coords, ", ") + "]" 13 } 14 15 func (poly Polygon) Type() string { 16 return PolygonType 17 } 18 19 func (poly Polygon) GeoJSON() []byte { 20 return geoJSON(poly) 21 } 22 23 func (poly Polygon) GetBSON() (interface{}, error) { 24 coords := make([][2]float64, len(poly)) 25 for i, p := range poly { 26 coords[i] = [2]float64{p.Lng(), p.Lat()} 27 } 28 bdoc := map[string]interface{}{ 29 "type": poly.Type(), 30 "coordinates": coords, 31 } 32 return bdoc, nil 33 }