Skip to content

Gets the Polygon definitions from OpenStreetMaps and able to combine one or more polygons into one single Multipolygon

Notifications You must be signed in to change notification settings

jinagamvasubabu/polyfetcher

Repository files navigation

polyfetcher

A Go Package can fetch polygon definitions from OpenStreet maps and it can also combine one or more polygons into one. alt text

Overview

Build Status Go Report Card GoDoc License Visits Badge Maintainability

What it does?

  • 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

Install

go get github.com/jinagamvasubabu/polyfetcher

How to use Fetch Polygons?

  • 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)

How to use Combine Polygons?

  • 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)

Response:

//GeoJson Open street map response structure
type GeoJson struct {
	Name        string        `json:"name"`
	Type        string        `json:"type"`
	Coordinates []interface{} `json:"coordinates"`
}

How to enable Debug logs?

  • Pass logrus LogLevel:logrus.DebugLevel to GeometryUtils struct
  import "github.com/jinagamvasubabu/polyfetcher"

 
  p := polyfetcher.GeometryUtils{LogLevel:logrus.DebugLevel}
  resp, err := p.CombinePolygons(context.Background(), []string{"germany", "belgium"})

How to validate the data ?

Response type is schema.GeoJson, you can marshal the response to string and use geojsonlint to validate the geojson. alt text

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

Errors:

  • 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:

Goroutines support to fetch areas concurrently instead of synchronously

Author

JinagamVasubabu

License

Apache 2.0.

About

Gets the Polygon definitions from OpenStreetMaps and able to combine one or more polygons into one single Multipolygon

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published