# README
Circle-to-Polygon
A Go library to convert a circle to a polygon (port of https://github.com/gabzim/circle-to-polygon).
Usage
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!
Make a circle
circle := &circletopolygon.Circle{
Centre: &circletopolygon.Point{
Latitude: -41.270634,
Longitude: 173.283966,
},
Radius: 20000, // 20km
}
Convert a circle to a polygon with 32 edges:
polygon, err := circle.ToPolygon(32)
if err != nil {
panic(err)
}
Render a polygon as GeoJSON:
geoJSON, err := polygon.GeoJSON()
if err != nil {
panic(err)
}
Do other things with the polygon:
for _, point := range polygon {
fmt.Printf("Lat, Lon: %f, %f", point.Latitude, point.Longitude)
}
# Variables
ErrPointOutOfBounds is returned a latitude or longitude is outside of the -180 to +180 range:.
ErrPolygonNotClosed is returned when the first and last points don't match:.
# Type aliases
Polygon is a shape made up of points:.