xgeo

package module
v0.0.0-...-0d60f71 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnumGeoType

func EnumGeoType() (e struct {
	Point           GeoType
	LineString      GeoType
	Polygon         GeoType
	MultiPoint      GeoType
	MultiLineString GeoType
	MultiPolygon    GeoType
})

EnumGeoType Example: if geoType == EnumGeoType().xxx {...}

func EnumGeoTypeExampleSwitch

func EnumGeoTypeExampleSwitch()

func EnumGeoTypeSwitch

func EnumGeoTypeSwitch() (
	point struct{ Point GeoType },
	lineString struct{ LineString GeoType },
	polygon struct{ Polygon GeoType },
	multiPoint struct{ MultiPoint GeoType },
	multiLineString struct{ MultiLineString GeoType },
	multiPolygon struct{ MultiPolygon GeoType },
)

EnumGeoTypeSwitch safe switch of all values example: m.EnumGeoTypeExampleSwitch()

Types

type BD09

type BD09 struct {
	Longitude float64 `json:"longitude" note:"经度"`
	Latitude  float64 `json:"latitude" note:"纬度"`
}

func (BD09) GCJ02

func (data BD09) GCJ02() GCJ02

func (BD09) Validator

func (data BD09) Validator() (err error)

func (BD09) WGS84

func (data BD09) WGS84() WGS84

type GCJ02

type GCJ02 struct {
	Longitude float64 `json:"longitude" note:"经度"`
	Latitude  float64 `json:"latitude" note:"纬度"`
}

func (GCJ02) BD09

func (data GCJ02) BD09() BD09

func (GCJ02) LatCommaLngString

func (data GCJ02) LatCommaLngString() (latCommaLng string)

LatCommaLngString 返回 "纬度,经度" 格式字符串 可能所有人都至少一次踩过这个坑:地理坐标点用字符串形式表示时是纬度在前,经度在后( "latitude,longitude" ), 而数组形式表示时是经度在前,纬度在后( [longitude,latitude] )—顺序刚好相反。

func (GCJ02) Validator

func (data GCJ02) Validator() (err error)

func (GCJ02) WGS84

func (data GCJ02) WGS84() WGS84

type GeoType

type GeoType string

GeoType Source enums: {"name":"GeoType","type":"string","items":[{"field":"Point","value":"Point","tailed":", ","label":"点"},{"field":"LineString","value":"LineString","label":"线","tailed":", "},{"field":"Polygon","value":"Polygon","label":"面","tailed":", "},{"field":"MultiPoint","value":"MultiPoint","label":"多点","tailed":", "},{"field":"MultiLineString","value":"MultiLineString","label":"多线","tailed":", "},{"field":"MultiPolygon","value":"MultiPolygon","label":"多面"}]}

func NewGeoType

func NewGeoType(v string) (geoType GeoType, err error)

NewGeoType Create GeoType by string

func (GeoType) IsZero

func (v GeoType) IsZero() bool

IsZero

func (GeoType) String

func (v GeoType) String() string

String return GeoType basic types

func (GeoType) Validator

func (v GeoType) Validator(custom ...error) error

Validator Verify data

type LineString

type LineString struct {
	Type        string       `json:"type" bson:"type"`
	Coordinates [][2]float64 `json:"coordinates" bson:"coordinates"`
}

LineString GeoJSON 支持 mongo bson mysql GeoJson规范(RFC 7946)全文翻译: https://zhuanlan.zhihu.com/p/141554586 xgeo.NewLineString()

func NewLineString

func NewLineString(points []Point) LineString

func NewLineStringFormRaw

func NewLineStringFormRaw(lngAndLat [][2]float64) LineString

func (*LineString) Scan

func (p *LineString) Scan(data interface{}) (err error)

Scan implements the SQL driver.Scanner interface and will scan the

func (LineString) String

func (p LineString) String() string

String returns the WKT (Well Known Text) representation of the point. LINESTRING(1.5 2.45,3.21 4)

func (LineString) Validator

func (p LineString) Validator(custom ...error) (err error)

func (LineString) Value

func (p LineString) Value() (value driver.Value, err error)

type Point

type Point struct {
	Type string `json:"type" bson:"type"`
	// []float64{longitude, latitude} []float64{经度, 纬度}
	// 可能所有人都至少一次踩过这个坑:地理坐标点用字符串形式表示时是纬经( "latitude,longitude" ),
	// 而数组形式表示时是经度在前,纬度在后( [longitude,latitude] )—顺序刚好相反。
	Coordinates [2]float64 `json:"coordinates" bson:"coordinates"`
}

Point GeoJSON 支持 mongo bson mysql GeoJson规范(RFC 7946)全文翻译: https://zhuanlan.zhihu.com/p/141554586 xgeo.NewPoint(xgeo.WGS84{121.48294,31.2328}) // WGS84{经度,纬度}

func NewPoint

func NewPoint(data WGS84) Point

func NewPointFormRaw

func NewPointFormRaw(lngAndLat [2]float64) Point

func (Point) DistanceInMeters

func (p Point) DistanceInMeters(target Point) float64

func (*Point) Scan

func (p *Point) Scan(data interface{}) (err error)

Scan implements the SQL driver.Scanner interface and will scan the

func (Point) String

func (p Point) String() string

String returns the WKT (Well Known Text) representation of the point. POINT(1 2)

func (Point) Validator

func (p Point) Validator(custom ...error) (err error)

func (Point) Value

func (p Point) Value() (value driver.Value, err error)

func (Point) WGS84

func (p Point) WGS84() WGS84

type Polygon

type Polygon struct {
	Type        string         `json:"type" bson:"type"`
	Coordinates [][][2]float64 `json:"coordinates" bson:"coordinates"`
}

Polygon GeoJSON 支持 mongo bson GeoJson规范(RFC 7946)全文翻译: https://zhuanlan.zhihu.com/p/141554586 xgeo.NewPolygon([]xgeo.WGS84{{-1,-1}, {1, -1}, {1, 1}, {-1, -1}) // WGS84{经度,纬度}

func NewPolygon

func NewPolygon(lineStrings []LineString) Polygon

NewPolygon new Polygon

func NewPolygonFormRaw

func NewPolygonFormRaw(lngAndLat [][][2]float64) Polygon

func (*Polygon) Scan

func (p *Polygon) Scan(data interface{}) (err error)

Scan implements the SQL driver.Scanner interface and will scan the

func (Polygon) String

func (p Polygon) String() string

String returns the WKT (Well Known Text) representation of the point. POLYGON((1 2,1 4,3 4,3 2,1 2))

func (Polygon) Validator

func (p Polygon) Validator(custom ...error) (err error)

func (Polygon) Value

func (p Polygon) Value() (value driver.Value, err error)

type WGS84

type WGS84 struct {
	Longitude float64 `json:"longitude" note:"经度"`
	Latitude  float64 `json:"latitude" note:"纬度"`
}

WGS84 实现了 sql 接口 driver.Valuer sql.Scanner

func (WGS84) BD09

func (data WGS84) BD09() BD09

func (WGS84) GCJ02

func (data WGS84) GCJ02() GCJ02

func (WGS84) Validator

func (data WGS84) Validator() (err error)

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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