geo

package
v1.1.12 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: Apache-2.0 Imports: 11 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package geo defines a position on the Earth, as a latitude and longitude in decimal degrees, and optionally an altitude in metres, which is text in degrees, minutes and seconds, such as 52°28'21.71"N 13°20'16.33"E 91.5m, or decimal degrees, such as "52.472697,13.337869,91.5", as in a geo URI (RFC 5870), and JSON such as {"lat":52.472697,"long":13.337869,"alt":91.5}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bounds added in v1.1.6

type Bounds struct {
	MinLong float64 `json:"min_long"`
	MinLat  float64 `json:"min_lat"`
	MaxLong float64 `json:"max_long"`
	MaxLat  float64 `json:"max_lat"`
}

Bounds is the box of a geometry, of the least and greatest of its longitudes and latitudes, which a point's is the point

type Feature added in v1.1.6

type Feature struct {
	ID         any            // A string, or a number, as a json.Number, so it's exact, or nil
	Geometry   *Geometry      // Its geometry, or nil
	Properties map[string]any // Its properties, or nil
}

Feature is a feature of GeoJSON (RFC 7946): a geometry, such as a region, with its properties, such as its name, and its identifier, when it has one. Its geometry is nil when it has none, or when it's of a type which a Geometry isn't, such as a LineString, which is read, without it.

func ParseGeoJSON added in v1.1.6

func ParseGeoJSON(data []byte) ([]Feature, error)

ParseGeoJSON returns the features of GeoJSON, which is a feature collection, a feature, or a geometry, which is a feature without properties, or ErrBadParameter when it isn't GeoJSON

func (Feature) MarshalJSON added in v1.1.6

func (f Feature) MarshalJSON() ([]byte, error)

MarshalJSON returns the feature as GeoJSON, whose geometry and properties are null when it has none

func (Feature) Name added in v1.1.6

func (f Feature) Name() string

Name returns the name of the feature, of its name, or title, property, or empty when it has neither

func (*Feature) UnmarshalJSON added in v1.1.6

func (f *Feature) UnmarshalJSON(data []byte) error

UnmarshalJSON reads the feature of GeoJSON, without its geometry when it's of a type which a Geometry isn't, such as a LineString

type FeatureCollection added in v1.1.6

type FeatureCollection struct {
	Features []Feature
}

FeatureCollection is a collection of features of GeoJSON

func (FeatureCollection) Geometries added in v1.1.6

func (c FeatureCollection) Geometries() []Geometry

Geometries returns the geometries of the features which have them

func (FeatureCollection) MarshalJSON added in v1.1.6

func (c FeatureCollection) MarshalJSON() ([]byte, error)

MarshalJSON returns the collection as GeoJSON

func (*FeatureCollection) UnmarshalJSON added in v1.1.6

func (c *FeatureCollection) UnmarshalJSON(data []byte) error

UnmarshalJSON reads the collection of GeoJSON

type Geometry added in v1.1.6

type Geometry struct {
	Type GeometryType

	// The position of a point
	Point Position

	// The polygons, of a polygon, which is one, or of a multipolygon: of
	// each, its rings, the first its boundary, and the others its holes,
	// each of which is closed, as its last position is its first
	Polygons [][][]Position
}

Geometry is a shape of a place, such as where a photo was taken, or a region, of GeoJSON (RFC 7946): a point, or a polygon, or more than one polygon, whose positions are of longitude, then latitude, in degrees (WGS 84), as GeoJSON's are

func NewMultiPolygon added in v1.1.6

func NewMultiPolygon(polygons ...[][]Position) Geometry

NewMultiPolygon returns the geometry of more than one polygon, of each one's rings

func NewPoint added in v1.1.6

func NewPoint(lat, long float64) Geometry

NewPoint returns the geometry of a point, of its latitude and longitude, in that order, as positions usually are, such as of a photo's GPS

func NewPolygon added in v1.1.6

func NewPolygon(rings ...[]Position) Geometry

NewPolygon returns the geometry of a polygon, of its rings, its boundary first, then its holes

func (Geometry) Bounds added in v1.1.6

func (g Geometry) Bounds() Bounds

Bounds returns the box of the geometry, of its points, and of its polygons' boundaries, as their holes are within them

func (Geometry) MarshalJSON added in v1.1.6

func (g Geometry) MarshalJSON() ([]byte, error)

MarshalJSON returns the geometry as GeoJSON

func (Geometry) String added in v1.1.6

func (g Geometry) String() string

String returns the geometry as GeoJSON

func (*Geometry) UnmarshalJSON added in v1.1.6

func (g *Geometry) UnmarshalJSON(data []byte) error

UnmarshalJSON reads the geometry of GeoJSON, of a Point, Polygon or MultiPolygon, which is valid (see Validate)

func (Geometry) Validate added in v1.1.6

func (g Geometry) Validate() error

Validate returns ErrBadParameter when the geometry isn't one of its type: a point, or polygons whose rings are closed, of four positions or more, of positions which are of the earth, whose longitudes are -180 to 180, and latitudes -90 to 90

func (Geometry) WithAlt added in v1.1.6

func (g Geometry) WithAlt(alt float64) Geometry

WithAlt returns the point with its altitude, in metres

type GeometryType added in v1.1.6

type GeometryType string

GeometryType is the type of a geometry, of GeoJSON's

const (
	GeometryPoint        GeometryType = "Point"
	GeometryPolygon      GeometryType = "Polygon"
	GeometryMultiPolygon GeometryType = "MultiPolygon"
)

type LatLong

type LatLong struct {
	Lat  float64  `json:"lat"`
	Long float64  `json:"long"`
	Alt  *float64 `json:"alt,omitempty"`
}

LatLong is a position, as a latitude and longitude in decimal degrees, which are negative in the southern and western hemispheres, and an altitude in metres above sea level, which is negative below it, or nil when it isn't known

func New

func New(lat, long float64) (LatLong, error)

New returns a position without an altitude, or an error when the latitude isn't between -90 and 90, or the longitude between -180 and 180

func Parse

func Parse(text string) (LatLong, error)

Parse returns a position from text, which is the latitude, longitude and optionally the altitude, separated by commas, in that order, as in ISO 6709 and a geo URI (RFC 5870), such as "52.472697,13.337869" or "52.472697,13.337869,91.5", with or without spaces, or in degrees, minutes and seconds, such as 52°28'21.71"N 13°20'16.33"E 91.5m (see DMS)

func ParseISO6709

func ParseISO6709(text string) (LatLong, error)

ParseISO6709 returns a position from text in ISO 6709, in decimal degrees, such as +52.4158+013.5896+035.667/, whose altitude, in metres, is optional, or an error when it isn't one, or it isn't on the Earth

func (LatLong) Decimal

func (ll LatLong) Decimal() string

Decimal returns the position in decimal degrees, such as "52.472697,13.337869", or "52.472697,13.337869,91.5" with an altitude. The latitude is first, as in ISO 6709 and a geo URI (RFC 5870), unlike GeoJSON, whose longitude is first; text in degrees, minutes and seconds (see String) has hemispheres, so isn't ambiguous.

func (LatLong) Equal

func (ll LatLong) Equal(other LatLong) bool

Equal returns true when the positions are the same, with the same altitude, or neither with one

func (LatLong) Geometry added in v1.1.6

func (ll LatLong) Geometry() Geometry

Geometry returns the point of the position, with its altitude, when it's known

func (LatLong) MarshalJSON

func (ll LatLong) MarshalJSON() ([]byte, error)

MarshalJSON returns the position as JSON, such as {"lat":52.472697,"long":13.337869}, with alt when there's an altitude

func (LatLong) MarshalText

func (ll LatLong) MarshalText() ([]byte, error)

MarshalText returns the position in degrees, minutes and seconds, such as 52°28'21.71"N 13°20'16.33"E, with the altitude when there is one, such as 52°28'21.71"N 13°20'16.33"E 91.5m, whose seconds are rounded to a hundredth (see String)

func (LatLong) MarshalXMP

func (ll LatLong) MarshalXMP(key string) map[string]string

MarshalXMP returns the position as the GPS properties of the exif schema of XMP, when the key is in the exif namespace, such as exif:GPSPosition: exif:GPSLatitude and exif:GPSLongitude, as degrees and minutes, with their hemisphere, such as "53,14.053167N", and exif:GPSAltitude, a rational in metres, and exif:GPSAltitudeRef, which is 1 below sea level, when there's an altitude. It returns none for a key in another namespace, such as dc:coverage, which is written as its text (see String).

func (LatLong) String

func (ll LatLong) String() string

String returns the position in degrees, minutes and seconds, such as 52°28'21.71"N 13°20'16.33"E, with the altitude in metres when there is one, such as 52°28'21.71"N 13°20'16.33"E 91.5m. The seconds are rounded to a hundredth, which is about 30cm, and the altitude to a centimetre.

func (*LatLong) UnmarshalJSON

func (ll *LatLong) UnmarshalJSON(data []byte) error

UnmarshalJSON sets the position from JSON, which is an object with both lat and long, and optionally alt, such as {"lat":52.472697,"long":13.337869,"alt":91.5}, or a string of its text, such as "52.472697,13.337869,91.5"

func (*LatLong) UnmarshalText

func (ll *LatLong) UnmarshalText(text []byte) error

UnmarshalText sets the position from text, in degrees, minutes and seconds, such as 52°28'21.71"N 13°20'16.33"E, or decimal degrees, such as "52.472697,13.337869" (see Parse)

func (LatLong) Validate

func (ll LatLong) Validate() error

Validate returns an error when the latitude isn't between -90 and 90, or the longitude between -180 and 180, or either, or the altitude, isn't a finite number

func (LatLong) WithAlt

func (ll LatLong) WithAlt(alt float64) LatLong

WithAlt returns the position with an altitude, in metres above sea level, which is negative below it

type Position added in v1.1.6

type Position struct {
	Long float64
	Lat  float64
	Alt  *float64
}

Position is a position of a geometry, of its longitude, and latitude, in degrees, and its altitude, in metres, when it's known, which is of JSON as an array of them, in that order, as GeoJSON's is

func (Position) MarshalJSON added in v1.1.6

func (p Position) MarshalJSON() ([]byte, error)

MarshalJSON returns the position as an array of its longitude, latitude, and its altitude, when it's known

func (*Position) UnmarshalJSON added in v1.1.6

func (p *Position) UnmarshalJSON(data []byte) error

UnmarshalJSON reads the position of an array of its longitude, latitude, and altitude, when it has one

func (Position) Validate added in v1.1.6

func (p Position) Validate() error

Validate returns ErrBadParameter when the position isn't of the earth

Jump to

Keyboard shortcuts

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