polyfetcher

package module
v0.0.0-...-0674c46 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 25, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

README

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.

Documentation

Index

Constants

View Source
const (
	//CoordinatesMaxLength Maximum length of the coordinates array
	CoordinatesMaxLength = 500
	//Polygon constant Polygon
	Polygon = "Polygon"
	//Multipolygon constant MultiPolygon
	Multipolygon = "MultiPolygon"
	//OsmURL Url to fetch the OSM data for an area
	OsmURL = "https://nominatim.openstreetmap.org/search.php?q=%s+&polygon_geojson=1&format=json" // nominatim is a UI for OSM data
	//Administrative is a type of geoJSON
	Administrative = "administrative"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type GeometryUtils

type GeometryUtils struct {
	LogLevel log.Level
}

GeometryUtils struct to configure GeometryUtils

func (*GeometryUtils) CombinePolygons

func (g *GeometryUtils) CombinePolygons(ctx context.Context, areas []string) (schema.GeoJson, error)

CombinePolygons function to combine polygons or multipolygons

func (*GeometryUtils) FetchPolygons

func (g *GeometryUtils) FetchPolygons(ctx context.Context, areas []string) ([]schema.GeoJson, error)

FetchPolygons function gets the definitions from OSM

type IGeometryUtils

type IGeometryUtils interface {
	FetchPolygons(ctx context.Context, areas []string) ([]schema.GeoJson, error)
	CombinePolygons(ctx context.Context, areas []string) (schema.GeoJson, error)
}

IGeometryUtils Program to fetch the polygon data of one or more areas

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL