A Go library to convert a circle to a polygon (port of https://github.com/gabzim/circle-to-polygon).
The library offers some basic geometry components:
- Point: A geographic coordinate (lat/lon)
- Circle: A point with a radius (in metres)
- Polygon: A list of points
Each of these structures offers a Validate()
method which returns an error if the data doesn't make sense (lat/lon out of bounds, or an open polygon).
A working example can be found under cmd/circle. This renders a custom circle as GeoJSON, which you can then load into https://geojson.io to view!
circle := &circletopolygon.Circle{
Centre: &circletopolygon.Point{
Latitude: -41.270634,
Longitude: 173.283966,
},
Radius: 20000, // 20km
}
polygon, err := circle.ToPolygon(32)
if err != nil {
panic(err)
}
geoJSON, err := polygon.GeoJSON()
if err != nil {
panic(err)
}
for _, point := range polygon {
fmt.Printf("Lat, Lon: %f, %f", point.Latitude, point.Longitude)
}