latlong

package module
v0.0.0-...-3f8c4b7 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2023 License: Apache-2.0 Imports: 19 Imported by: 0

README

go-latlong

Job Status Report Build Status GoDoc

Usage

This is an golang struct for store latitude, longitude and altitude by numerical, GridLocator and GeoHash.

To use the method of this struct, you can get GridLocator and GeoHash which length is considered in precision.

Application
package main

import (
	"fmt"

	"github.com/toyo/go-latlong"
)

func main() {
	l := latlong.NewRect(35, 135, 0.1, 0.1) // N35+-0.05 Deg. E135+-0.05 Deg.

	fmt.Println(l.GridLocator()) // shows GridLocator. https://en.wikipedia.org/wiki/Maidenhead_Locator_System
	fmt.Println(l.GeoHash())     // shows GeoHash. http://geohash.org/
	fmt.Println(l.String())      // shows lat/long in string.
}

Class of this library s2geometry.io GeoJSON memo
Point s2.LatLng (+altitude) Point
MultiPoint (= []Point ) - MultiPoint is for ISO6709
LineString s2.Polyline LineString
Polygon s2.Loop Polygon with no hole
Circle s2.Cap Circle GeoJSON 1.1
Rect s2.Rect -

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Config = config{
	HTTPClient:    http.DefaultClient,
	Lang:          "en",
	YahooJPAPIURL: "https://map.yahooapis.jp/geoapi/V1/reverseGeoCoder",
}

Config is an configuration of environment.

Functions

This section is empty.

Types

type Angle

type Angle struct {
	// contains filtered or unexported fields
}

Angle is Angle with precision.

func AngleFromBytes

func AngleFromBytes(part []byte) (a Angle)

AngleFromBytes creates Angle from []byte to unmarshal.

func NewAngle

func NewAngle(degree, degreeprec float64) (a Angle)

NewAngle is constructor for Angle

func NewAngleFromS1Angle

func NewAngleFromS1Angle(angle, angleprec s1.Angle) (a Angle)

NewAngleFromS1Angle is constructor for Angle

func (Angle) Degrees

func (a Angle) Degrees() float64

Degrees returns Degree

func (Angle) MarshalJSON

func (a Angle) MarshalJSON() ([]byte, error)

MarshalJSON is a marshaler for JSON.

func (Angle) PrecDegrees

func (a Angle) PrecDegrees() float64

PrecDegrees returns precicion Degree

func (Angle) PrecS1Angle

func (a Angle) PrecS1Angle() s1.Angle

PrecS1Angle returns precicion s1.Angle

func (Angle) S1Angle

func (a Angle) S1Angle() s1.Angle

S1Angle returns s1.Angle

func (Angle) String

func (a Angle) String() (s string)

func (*Angle) UnmarshalJSON

func (a *Angle) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON is a unmarshaler for JSON.

type Circle

type Circle struct {
	Point
	s1.ChordAngle
}

Circle is Circle

func NewCircle

func NewCircle(latlng Point, km Km) *Circle

NewCircle is constuctor for Circle

func NewEmptyCircle

func NewEmptyCircle() *Circle

NewEmptyCircle is constructor for Circle with empty.

func NewPointCircle

func NewPointCircle(latlng Point) *Circle

NewPointCircle is constructor for Circle with radius = prec

func (*Circle) CapBound

func (c *Circle) CapBound() s2.Cap

CapBound is for s2.Region interface.

func (*Circle) CellUnionBound

func (c *Circle) CellUnionBound() []s2.CellID

CellUnionBound is for s2.Region interface.

func (*Circle) ContainsCell

func (c *Circle) ContainsCell(cell s2.Cell) bool

ContainsCell is for s2.Region interface.

func (*Circle) ContainsPoint

func (c *Circle) ContainsPoint(p s2.Point) bool

ContainsPoint is for s2.Region interface.

func (Circle) Equal

func (c Circle) Equal(c1 Geometry) bool

Equal return bool

func (*Circle) IntersectsCell

func (c *Circle) IntersectsCell(cell s2.Cell) bool

IntersectsCell is for s2.Region interface.

func (*Circle) MultiPoint

func (c *Circle) MultiPoint(div int) (lls MultiPoint)

MultiPoint is circumference loop by MultiPoint radian is one vertex degree.

func (Circle) NewGeoJSONFeature

func (c Circle) NewGeoJSONFeature(property interface{}) *GeoJSONFeature

NewGeoJSONFeature returns GeoJSONFeature.

func (Circle) NewGeoJSONGeometry

func (c Circle) NewGeoJSONGeometry() *GeoJSONGeometry

NewGeoJSONGeometry returns GeoJSONGeometry.

func (Circle) Radius

func (c Circle) Radius() Km

Radius returns radius of circle.

func (Circle) Radiusp

func (c Circle) Radiusp() *float64

Radiusp is un-used

func (*Circle) RectBound

func (c *Circle) RectBound() s2.Rect

RectBound is for s2.Region interface.

func (Circle) S2Cap

func (c Circle) S2Cap() s2.Cap

S2Cap is getter for s2.Cap.

func (*Circle) S2LatLngs

func (c *Circle) S2LatLngs(div int) (lls []s2.LatLng)

S2LatLngs is circumference loop by []s2.LatLng. radian is one vertex degree.

func (*Circle) S2Loop

func (c *Circle) S2Loop(div int) (loop *s2.Loop)

S2Loop is circumference loop. div is number of vertices.

func (Circle) S2Point

func (c Circle) S2Point() s2.Point

S2Point is Center LatLng

func (Circle) S2Region

func (c Circle) S2Region() s2.Region

S2Region is getter for s2.Region.

func (Circle) String

func (c Circle) String() string

func (Circle) Type

func (Circle) Type() string

Type returns this type

type GeoJSONFeature

type GeoJSONFeature struct {
	Type     string           `json:"type"`
	Geometry *GeoJSONGeometry `json:"geometry"`
	Property interface{}      `json:"properties"`
}

GeoJSONFeature is Feature of GeoJSON

type GeoJSONFeatureCollection

type GeoJSONFeatureCollection struct {
	Type     string           `json:"type"`
	Features []GeoJSONFeature `json:"features"`
}

GeoJSONFeatureCollection is FeatureCollection of GeoJSON

func NewGeoJSONFeatureCollection

func NewGeoJSONFeatureCollection() *GeoJSONFeatureCollection

NewGeoJSONFeatureCollection creates GeoJSONFeatureCollection

func (*GeoJSONFeatureCollection) AddFeature

AddFeature adds GeoJSONFeature

type GeoJSONGeometry

type GeoJSONGeometry struct {
	// contains filtered or unexported fields
}

GeoJSONGeometry is Geometry of GeoJSON

type GeoJSONGeometry struct {
	Type        string          `json:"type"`
	Coordinates json.RawMessage `json:"coordinates"`
	Radius      *float64        `json:"radius,omitempty"` // only for Circle, which is GeoJSON specification 1.1 and leter.
}

func NewGeoJSONGeometry

func NewGeoJSONGeometry(g Geometry) (geom GeoJSONGeometry)

NewGeoJSONGeometry is constructor

func (GeoJSONGeometry) Equal

func (geom GeoJSONGeometry) Equal(geom1 GeoJSONGeometry) bool

Equal return equal or not.

func (GeoJSONGeometry) Geo

func (geom GeoJSONGeometry) Geo() Geometry

Geo returns contents.

func (GeoJSONGeometry) MarshalJSON

func (geom GeoJSONGeometry) MarshalJSON() ([]byte, error)

MarshalJSON is a marshaler for JSON.

func (GeoJSONGeometry) S2LatLng

func (geom GeoJSONGeometry) S2LatLng() s2.LatLng

S2LatLng returns s2.LatLng

func (GeoJSONGeometry) S2Point

func (geom GeoJSONGeometry) S2Point() s2.Point

S2Point is getter for center of s2.Point.

func (GeoJSONGeometry) S2Region

func (geom GeoJSONGeometry) S2Region() s2.Region

S2Region is getter for s2.Region.

func (GeoJSONGeometry) String

func (geom GeoJSONGeometry) String() string

func (*GeoJSONGeometry) UnmarshalJSON

func (geom *GeoJSONGeometry) UnmarshalJSON(data []byte) error

UnmarshalJSON is a unmarshaler for JSON.

type Geometry

type Geometry interface {
	Equal(Geometry) bool
	S2Region() s2.Region
	S2Point() s2.Point
	Radiusp() *float64
	Type() string
	String() string
}

Geometry is interface for each geometry class @ GeoJSON.

type Km

type Km float64

Km is kilo-meter.

func EarthArcFromAngle

func EarthArcFromAngle(angle s1.Angle) Km

EarthArcFromAngle makes Angle to Distance.

func EarthArcFromChordAngle

func EarthArcFromChordAngle(chordangle s1.ChordAngle) Km

EarthArcFromChordAngle makes ChordAngle to Distance.

func (Km) EarthAngle

func (km Km) EarthAngle() s1.Angle

EarthAngle makes Distance to Angle.

func (Km) EarthChordAngle

func (km Km) EarthChordAngle() s1.ChordAngle

EarthChordAngle makes Distance to ChordAngle.

func (Km) String

func (km Km) String() string

type LineString

type LineString struct {
	MultiPoint
}

LineString inherited MultiPoint

func (*LineString) CapBound

func (cds *LineString) CapBound() s2.Cap

CapBound is for s2.Region interface.

func (*LineString) CellUnionBound

func (cds *LineString) CellUnionBound() []s2.CellID

CellUnionBound is for s2.Region interface.

func (*LineString) ContainsCell

func (cds *LineString) ContainsCell(c s2.Cell) bool

ContainsCell is for s2.Region interface.

func (*LineString) ContainsPoint

func (cds *LineString) ContainsPoint(p s2.Point) bool

ContainsPoint is for s2.Region interface.

func (*LineString) IntersectsCell

func (cds *LineString) IntersectsCell(c s2.Cell) bool

IntersectsCell is for s2.Region interface.

func (LineString) MapsLatLng

func (cds LineString) MapsLatLng() (mlls []maps.LatLng)

MapsLatLng convert to google maps.

func (LineString) MarshalJSON

func (cds LineString) MarshalJSON() ([]byte, error)

MarshalJSON is a marshaler for JSON.

func (LineString) NewGeoJSONFeature

func (cds LineString) NewGeoJSONFeature(property interface{}) *GeoJSONFeature

NewGeoJSONFeature returns GeoJSONFeature.

func (LineString) NewGeoJSONGeometry

func (cds LineString) NewGeoJSONGeometry() *GeoJSONGeometry

NewGeoJSONGeometry returns GeoJSONGeometry.

func (*LineString) Polygon

func (cds *LineString) Polygon() Polygon

Polygon make polygon from LineString

func (LineString) Radiusp

func (cds LineString) Radiusp() *float64

Radiusp is un-used

func (*LineString) RectBound

func (cds *LineString) RectBound() s2.Rect

RectBound is for s2.Region interface.

func (LineString) S2Loop

func (cds LineString) S2Loop() *s2.Loop

S2Loop is getter for s2.Loop.

func (LineString) S2Point

func (cds LineString) S2Point() s2.Point

S2Point is Center

func (LineString) S2Polyline

func (cds LineString) S2Polyline() s2.Polyline

S2Polyline is getter for s2.Polyline ([]s2.Point).

func (LineString) S2Region

func (cds LineString) S2Region() s2.Region

S2Region is getter for s2.Polyline ([]s2.Point).

func (LineString) Type

func (LineString) Type() string

Type returns this type

func (*LineString) UnmarshalJSON

func (cds *LineString) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON is a unmarshaler for JSON.

func (*LineString) UnmarshalText

func (cds *LineString) UnmarshalText(b []byte) error

UnmarshalText is from ISO6709 latlongs.

type MultiPoint

type MultiPoint []Point

MultiPoint is slice of *Point

func (MultiPoint) Equal

func (cds MultiPoint) Equal(c1 Geometry) bool

Equal return bool

func (MultiPoint) NewGeoJSONFeature

func (cds MultiPoint) NewGeoJSONFeature(property interface{}) *GeoJSONFeature

NewGeoJSONFeature returns GeoJSONFeature.

func (MultiPoint) NewGeoJSONGeometry

func (cds MultiPoint) NewGeoJSONGeometry() *GeoJSONGeometry

NewGeoJSONGeometry returns GeoJSONGeometry.

func (MultiPoint) Point

func (cds MultiPoint) Point() Point

Point returns the first point.

func (MultiPoint) Radiusp

func (cds MultiPoint) Radiusp() *float64

Radiusp is un-used

func (MultiPoint) Reverse

func (cds MultiPoint) Reverse() MultiPoint

Reverse returns reverse order.

func (MultiPoint) S2Point

func (cds MultiPoint) S2Point() s2.Point

S2Point is Center LatLng

func (MultiPoint) S2Region

func (cds MultiPoint) S2Region() s2.Region

S2Region is nil

func (MultiPoint) String

func (cds MultiPoint) String() string

func (MultiPoint) Type

func (MultiPoint) Type() string

Type returns this type

func (*MultiPoint) UnmarshalJSON

func (cds *MultiPoint) UnmarshalJSON(str []byte) error

UnmarshalJSON is from ISO6709 latlongs.

func (*MultiPoint) UnmarshalText

func (cds *MultiPoint) UnmarshalText(str []byte) error

UnmarshalText is from ISO6709 latlongs.

type Point

type Point struct {
	// contains filtered or unexported fields
}

Point is Latitude & Longitude with precision.

func NewPoint

func NewPoint(lat, lng Angle, altitude *float64) (latlongalt Point)

NewPoint is from latitude, longitude and altitude.

func NewPointFromS2Point

func NewPointFromS2Point(p s2.Point) Point

NewPointFromS2Point is from s2.Point

func (*Point) CurrentPressure

func (ll *Point) CurrentPressure(unit, lang, apikey string) float64

CurrentPressure return a GrndLevel Pressure of the point.

func (*Point) CurrentWeatherData

func (ll *Point) CurrentWeatherData(unit, lang, apikey string) (w *owm.CurrentWeatherData, err error)

CurrentWeatherData return a pointer of struct for CurrentWeatherData

func (Point) DistanceAngle

func (latlong Point) DistanceAngle(latlong1 *Point) s1.Angle

DistanceAngle in radian.

func (Point) DistanceEarthKm

func (latlong Point) DistanceEarthKm(latlong1 *Point) Km

DistanceEarthKm in km at surface.

func (Point) Equal

func (latlong Point) Equal(latlong1 Geometry) bool

Equal is true if coordinate is same.

func (Point) Lat

func (latlong Point) Lat() Angle

Lat is getter for latitude.

func (Point) LatString

func (latlong Point) LatString() (s string)

LatString is string getter for latitude

func (Point) Lng

func (latlong Point) Lng() Angle

Lng is getter for longitude.

func (Point) LngString

func (latlong Point) LngString() (s string)

LngString is string getter for longitude

func (*Point) Locality

func (latlong *Point) Locality(ctx context.Context) (s string, err error)

Locality returns Japanese City, Town, Village name.

func (Point) MapsLatLng

func (latlong Point) MapsLatLng() maps.LatLng

MapsLatLng return maps.LatLng ( "googlemaps.github.io/maps" )

func (Point) MarshalJSON

func (latlong Point) MarshalJSON() ([]byte, error)

MarshalJSON is a marshaler for JSON.

func (Point) NewGeoJSONFeature

func (latlong Point) NewGeoJSONFeature(property interface{}) *GeoJSONFeature

NewGeoJSONFeature returns GeoJSONFeature.

func (Point) NewGeoJSONGeometry

func (latlong Point) NewGeoJSONGeometry() *GeoJSONGeometry

NewGeoJSONGeometry returns GeoJSONGeometry.

func (Point) PrecString

func (latlong Point) PrecString() (s string)

PrecString is Precision String()

func (Point) PrecisionArea

func (latlong Point) PrecisionArea() float64

PrecisionArea returns area size of precicion.

func (Point) Radiusp

func (latlong Point) Radiusp() *float64

Radiusp is un-used

func (Point) S2LatLng

func (latlong Point) S2LatLng() s2.LatLng

S2LatLng is getter for s2.LatLng

func (Point) S2Point

func (latlong Point) S2Point() s2.Point

S2Point is getter for s2.Point

func (Point) S2Region

func (latlong Point) S2Region() s2.Region

S2Region is getter for s2.Loop.

func (Point) SolarAngle

func (latlong Point) SolarAngle(t time.Time) (zenithAngle float64)

SolarAngle returns an solar angle at time t.

func (Point) String

func (latlong Point) String() string

func (Point) Type

func (Point) Type() string

Type returns this type

func (*Point) UnmarshalJSON

func (latlong *Point) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON is a unmarshaler for JSON.

func (*Point) UnmarshalText

func (latlong *Point) UnmarshalText(iso6709 []byte) error

UnmarshalText is from ISO6709 latlongs.

type Polygon

type Polygon struct {
	LineString
}

Polygon inherited MultiPoint

func (*Polygon) CapBound

func (cds *Polygon) CapBound() s2.Cap

CapBound is for s2.Region interface.

func (*Polygon) CellUnionBound

func (cds *Polygon) CellUnionBound() []s2.CellID

CellUnionBound is for s2.Region interface.

func (*Polygon) ContainsCell

func (cds *Polygon) ContainsCell(c s2.Cell) bool

ContainsCell is for s2.Region interface.

func (*Polygon) ContainsPoint

func (cds *Polygon) ContainsPoint(p s2.Point) bool

ContainsPoint is for s2.Region interface.

func (*Polygon) IntersectsCell

func (cds *Polygon) IntersectsCell(c s2.Cell) bool

IntersectsCell is for s2.Region interface.

func (Polygon) MarshalJSON

func (cds Polygon) MarshalJSON() ([]byte, error)

MarshalJSON is a marshaler for JSON.

func (Polygon) NewGeoJSONFeature

func (cds Polygon) NewGeoJSONFeature(property interface{}) *GeoJSONFeature

NewGeoJSONFeature returns GeoJSONFeature.

func (Polygon) NewGeoJSONGeometry

func (cds Polygon) NewGeoJSONGeometry() *GeoJSONGeometry

NewGeoJSONGeometry returns GeoJSONGeometry.

func (Polygon) Radiusp

func (cds Polygon) Radiusp() *float64

Radiusp is un-used

func (*Polygon) RectBound

func (cds *Polygon) RectBound() s2.Rect

RectBound is for s2.Region interface.

func (Polygon) S2Loop

func (cds Polygon) S2Loop() *s2.Loop

S2Loop is getter for s2.Loop.

func (Polygon) S2Point

func (cds Polygon) S2Point() s2.Point

S2Point is Center LatLng

func (Polygon) S2Region

func (cds Polygon) S2Region() s2.Region

S2Region is getter for s2.Region.

func (Polygon) Type

func (Polygon) Type() string

Type returns this type

func (*Polygon) UnmarshalJSON

func (cds *Polygon) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON is a unmarshaler for JSON.

type Rect

type Rect struct {
	s2.Rect
}

Rect is rectangle of latlng.

func NewRect

func NewRect(latitude, longitude, latprec, longprec float64) *Rect

NewRect is from latitude, longitude and altitude.

func NewRectGeoHash

func NewRectGeoHash(geoHash string) (latlong *Rect, err error)

NewRectGeoHash is from GeoHash http://geohash.org/

func NewRectGridLocator

func NewRectGridLocator(gl string) *Rect

NewRectGridLocator is from Grid Locator. https://en.wikipedia.org/wiki/Maidenhead_Locator_System

func (Rect) Center

func (rect Rect) Center() *Point

Center returns center LatLng.

func (*Rect) GeoHash

func (rect *Rect) GeoHash() string

GeoHash returns GeoHash string.

func (*Rect) GeoHash5

func (rect *Rect) GeoHash5() string

GeoHash5 returns GeoHash string.

func (*Rect) GeoHash6

func (rect *Rect) GeoHash6() string

GeoHash6 returns GeoHash string.

func (*Rect) GridLocator

func (rect *Rect) GridLocator() string

GridLocator is from Grid Locator. https://en.wikipedia.org/wiki/Maidenhead_Locator_System

func (*Rect) MarshalJSON

func (rect *Rect) MarshalJSON() (bb []byte, e error)

MarshalJSON is a marshaler for JSON.

func (Rect) PrecString

func (rect Rect) PrecString() (s string)

PrecString is Precision String()

func (*Rect) S2Rect

func (rect *Rect) S2Rect() s2.Rect

S2Rect returns s2.Rect.

func (*Rect) S2Region

func (rect *Rect) S2Region() s2.Region

S2Region is getter for s2.Region.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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