A Go Package can fetch polygon definitions from OpenStreet maps and it can also combine one or more polygons into one.
- It can fetch Polygon definitions from
OpenstreetMaps
by taking an area name, throw error if the area is not in OSM database - Combine one or more polygons into one single
Multipolygon
go get github.com/jinagamvasubabu/polyfetcher
- get
polyfetcher
go get github.com/jinagamvasubabu/polyfetcher
- import and use it like below:
import "github.com/jinagamvasubabu/polyfetcher"
import "github.com/sirupsen/logrus"
p := polyfetcher.GeometryUtils{}
resp, err := p.FetchPolygons(context.Background(), []string{"germany", "belgium"})
fmt.Println(resp)
- get
polyfetcher
go get github.com/jinagamvasubabu/polyfetcher
- import and use it like below:
import "github.com/jinagamvasubabu/polyfetcher"
import "github.com/sirupsen/logrus"
p := polyfetcher.GeometryUtils{}
resp, err := p.CombinePolygons(context.Background(), []string{"germany", "belgium"})
fmt.Println(resp)
//GeoJson Open street map response structure
type GeoJson struct {
Name string `json:"name"`
Type string `json:"type"`
Coordinates []interface{} `json:"coordinates"`
}
- Pass logrus
LogLevel:logrus.DebugLevel
toGeometryUtils
struct
import "github.com/jinagamvasubabu/polyfetcher"
p := polyfetcher.GeometryUtils{LogLevel:logrus.DebugLevel}
resp, err := p.CombinePolygons(context.Background(), []string{"germany", "belgium"})
Response type is schema.GeoJson, you can marshal the response to string and use geojsonlint to validate the geojson.
Note: If you get an error like Polygons and MultiPolygons should follow the right-hand rule then follow this below article to fix it. https://dev.to/jinagamvasubabu/solution-polygons-and-multipolygons-should-follow-the-right-hand-rule-2c8i
- If one of the area is invalid area then it can fetch the other areas if they are valid
- If all areas which were passed are invalid then it will throw error
error while fetching the polygon
Goroutines support to fetch areas concurrently instead of synchronously
JinagamVasubabu
Apache 2.0.