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 ¶
- type Bounds
- type Feature
- type FeatureCollection
- type Geometry
- type GeometryType
- type LatLong
- func (ll LatLong) Decimal() string
- func (ll LatLong) Equal(other LatLong) bool
- func (ll LatLong) Geometry() Geometry
- func (ll LatLong) MarshalJSON() ([]byte, error)
- func (ll LatLong) MarshalText() ([]byte, error)
- func (ll LatLong) MarshalXMP(key string) map[string]string
- func (ll LatLong) String() string
- func (ll *LatLong) UnmarshalJSON(data []byte) error
- func (ll *LatLong) UnmarshalText(text []byte) error
- func (ll LatLong) Validate() error
- func (ll LatLong) WithAlt(alt float64) LatLong
- type Position
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
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
MarshalJSON returns the feature as GeoJSON, whose geometry and properties are null when it has none
func (Feature) Name ¶ added in v1.1.6
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
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
NewMultiPolygon returns the geometry of more than one polygon, of each one's rings
func NewPoint ¶ added in v1.1.6
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
NewPolygon returns the geometry of a polygon, of its rings, its boundary first, then its holes
func (Geometry) Bounds ¶ added in v1.1.6
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
MarshalJSON returns the geometry as GeoJSON
func (*Geometry) UnmarshalJSON ¶ added in v1.1.6
UnmarshalJSON reads the geometry of GeoJSON, of a Point, Polygon or MultiPolygon, which is valid (see Validate)
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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
Geometry returns the point of the position, with its altitude, when it's known
func (LatLong) MarshalJSON ¶
MarshalJSON returns the position as JSON, such as {"lat":52.472697,"long":13.337869}, with alt when there's an altitude
func (LatLong) MarshalText ¶
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 ¶
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 ¶
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 ¶
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 ¶
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)
type Position ¶ added in v1.1.6
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
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
UnmarshalJSON reads the position of an array of its longitude, latitude, and altitude, when it has one