geo

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2025 License: AGPL-3.0 Imports: 10 Imported by: 1

README

geo 🌎

GeoJSON primitives for Go and MongoDB

https://geojson.org https://datatracker.ietf.org/doc/html/rfc7946

Documentation

Index

Constants

View Source
const AddressPropertyCountry = "country"
View Source
const AddressPropertyFormatted = "formatted"
View Source
const AddressPropertyLatitude = "latitude"
View Source
const AddressPropertyLocality = "locality"
View Source
const AddressPropertyLongitude = "longitude"
View Source
const AddressPropertyName = "name"
View Source
const AddressPropertyPlusCode = "pluscode"
View Source
const AddressPropertyPostalCode = "postalCode"
View Source
const AddressPropertyRegion = "region"
View Source
const AddressPropertyStreet1 = "street1"
View Source
const AddressPropertyStreet2 = "street2"
View Source
const AddressPropertyTimezone = "timezone"
View Source
const PropertyCoordinates = "coordinates"
View Source
const PropertyType = "type"
View Source
const PropertyTypePoint = "Point"
View Source
const PropertyTypePolygon = "Polygon"

Variables

This section is empty.

Functions

func AddressSchema added in v0.0.2

func AddressSchema() schema.Element

Types

type Address added in v0.0.2

type Address struct {
	Name       string  `json:"name"        bson:"name,omitempty"`       // Human-readable name of the address
	Formatted  string  `json:"formatted"   bson:"formatted,omitempty"`  // Full, unparsed value of the address
	Street1    string  `json:"street1"     bson:"street1,omitempty"`    // Parsed street address line 1 of the address
	Street2    string  `json:"street2"     bson:"street2,omitempty"`    // Parsed street address line 2 of the address
	Locality   string  `json:"locality"    bson:"locality,omitempty"`   // Parsed city or town of the address
	Region     string  `json:"region"      bson:"region,omitempty"`     // Parsed state or province of the address
	PostalCode string  `json:"postalCode"  bson:"postalCode,omitempty"` // Parsed postal code of the address
	Country    string  `json:"country"     bson:"country,omitempty"`    // Parsed country of the address
	PlusCode   string  `json:"plusCode"    bson:"plusCode,omitempty"`   // PlusCode for this location https://maps.google.com/pluscodes/
	Timezone   string  `json:"timezone"    bson:"timezone,omitempty"`   // Time zone in tzdatabase format (https://en.wikipedia.org/wiki/Tz_database)
	Latitude   float64 `json:"latitude"    bson:"latitude,omitempty"`   // Latitude of the address
	Longitude  float64 `json:"longitude"   bson:"longitude,omitempty"`  // Longitude of the address
}

Address represents a physical address on the planet It maps to https://www.w3.org/TR/activitystreams-vocabulary/#dfn-address and uses https://schema.org/PostalAddress to match Mobilizion

func NewAddress added in v0.0.2

func NewAddress() Address

func (Address) GeoJSON added in v0.0.2

func (address Address) GeoJSON() mapof.Any

GeoJSON returns a GeoJSON object that matches the geo.GeoJSONer interface https://www.mongodb.com/docs/manual/reference/geojson/

func (Address) GeoPoint added in v0.0.2

func (address Address) GeoPoint() Point

GeoPoint returns a Point representation of this address

func (Address) GetFloat added in v0.0.2

func (address Address) GetFloat(name string) (float64, bool)

func (Address) GetString added in v0.0.3

func (address Address) GetString(name string) string

func (Address) GetStringOK added in v0.0.2

func (address Address) GetStringOK(name string) (string, bool)

func (Address) HasAddress added in v0.0.2

func (address Address) HasAddress() bool

HasAddress returns TRUE if this Address has ANY street adsress information

func (Address) HasGeocode added in v0.0.2

func (address Address) HasGeocode() bool

HasGeocode returns TRUE if this Address has ANY Lat/Long information

func (Address) IsZero added in v0.0.2

func (address Address) IsZero() bool

func (Address) JSONLD added in v0.0.2

func (address Address) JSONLD() mapof.Any

JSONLD returns a JSON-LD representation of this object

func (Address) LatLon added in v0.0.3

func (address Address) LatLon() string

func (Address) LonLat added in v0.0.3

func (address Address) LonLat() string

func (*Address) MarshalMap added in v0.0.2

func (address *Address) MarshalMap() mapof.Any

func (Address) NotZero added in v0.0.2

func (address Address) NotZero() bool

func (*Address) Reset added in v0.0.2

func (address *Address) Reset()

Reset clears all geocoding information from this Address

func (*Address) SetFloat added in v0.0.2

func (address *Address) SetFloat(name string, value float64) bool

func (*Address) SetPoint added in v0.0.2

func (address *Address) SetPoint(point Point)

func (*Address) SetString added in v0.0.2

func (address *Address) SetString(name string, value string) bool

func (*Address) UnmarshalMap added in v0.0.2

func (address *Address) UnmarshalMap(value mapof.Any) error

UnmarshalMap populates this address with the properties in the `value` map

type GeoJSONPoint

type GeoJSONPoint struct {
	Type        string    `json:"type"        bson:"type"`        // This should always be "Point"
	Coordinates []float64 `json:"coordinates" bson:"coordinates"` // Whatevs
}

GeoJSONPoint represents the "strict" format for a Point in GeoJSON

type GeoJSONPolygon

type GeoJSONPolygon struct {
	Type        string        `json:"type"        bson:"type"`        // this should always be "Polygon"
	Coordinates [][][]float64 `json:"coordinates" bson:"coordinates"` // ick. Thanks IETF.
}

GeoJSONPolygon represents the "strict" format for a Polygon in GeoJSON. is is used here to simplify conversion to/from serialization formats

type Point

type Point struct {
	Position
}

Point represents a GeoJSON "Point" object https://datatracker.ietf.org/doc/html/rfc7946#section-3.1.2

func NewPoint

func NewPoint(longitude float64, latitude float64) Point

func NewPointWithAltitude

func NewPointWithAltitude(longitude float64, latitude float64, altitude float64) Point

func (Point) GeoJSON

func (point Point) GeoJSON() map[string]any

func (Point) LatLon added in v0.0.3

func (point Point) LatLon() string

func (Point) LonLat added in v0.0.3

func (point Point) LonLat() string

func (Point) MarshalBSON

func (point Point) MarshalBSON() ([]byte, error)

MarshalBSON is a custom BSON marshaller that serializes this Position into a GeoJSON coordinate pair

func (Point) MarshalJSON

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

MarshalJSON is a custom json.Marshaller that returns this Point as a GeoJSON object. This marshaller works with `omitzero` but not `omitempty`

func (Point) MarshalStruct

func (point Point) MarshalStruct() GeoJSONPoint

func (*Point) UnmarshalBSON

func (point *Point) UnmarshalBSON(data []byte) error

UnmarshalBSON is a custom BSON unmarshaller that deserializes a BSON / GeoJSON coordinate pair into this Position structure.

func (*Point) UnmarshalJSON

func (point *Point) UnmarshalJSON(data []byte) error

UnmarshalJSON is a custom json.Unmarshaller that parses a GeoJSON object into this Point object.

func (*Point) UnmarshalMap

func (point *Point) UnmarshalMap(data mapof.Any) error

UnmarshalMap populates this Point using the values from the provided data. If the data does not fit the correct GeoJSON format, then this method returns an error

type Polygon

type Polygon struct {
	Coordinates sliceof.Object[Position]
}

Polygon represents a GeoJSON "Polygon" object https://datatracker.ietf.org/doc/html/rfc7946#section-3.1.2

func NewPolygon

func NewPolygon(coordinates ...Position) Polygon

func NewPolygonFromString

func NewPolygonFromString(data string) Polygon

func (Polygon) GeoJSON

func (polygon Polygon) GeoJSON() map[string]any

GeoJSON returns a GeoJSON representation of this Polygon

func (Polygon) IsZero

func (polygon Polygon) IsZero() bool

func (Polygon) MarshalBSON

func (polygon Polygon) MarshalBSON() ([]byte, error)

MarshalBSON is a custom BSON marshaller that serializes this Position into a GeoJSON coordinate pair

func (Polygon) MarshalJSON

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

MarshalJSON is a custom json.Marshaller that returns this Polygon as a GeoJSON object.

func (Polygon) MarshalSlice

func (polygon Polygon) MarshalSlice() [][]float64

MarshalSlice returns (a slice of (a slice of floats)), which is the standard way of representing a GeoJSON polygon

func (Polygon) MarshalStruct

func (polygon Polygon) MarshalStruct() GeoJSONPolygon

MarshalMap copies this Polygon into a mapof.Any

func (Polygon) NotZero

func (polygon Polygon) NotZero() bool

func (Polygon) String

func (polygon Polygon) String() string

func (*Polygon) UnmarshalBSON

func (polygon *Polygon) UnmarshalBSON(data []byte) error

UnmarshalBSON is a custom BSON unmarshaller that deserializes a BSON / GeoJSON coordinate pair into this Position structure.

func (*Polygon) UnmarshalJSON

func (polygon *Polygon) UnmarshalJSON(data []byte) error

UnmarshalJSON is a custom json.Unmarshaller that parses a GeoJSON object into this Polygon object.

func (*Polygon) UnmarshalStruct

func (polygon *Polygon) UnmarshalStruct(data GeoJSONPolygon) error

type Position

type Position struct {
	Longitude float64
	Latitude  float64
	Altitude  float64
}

Position represents a Longitude/Latitude pair https://datatracker.ietf.org/doc/html/rfc7946#section-3.1.1

func NewPosition

func NewPosition(longitude float64, latitude float64) Position

func NewPositionWithAltitude

func NewPositionWithAltitude(longitude float64, latitude float64, altitude float64) Position

func (Position) IsZero

func (position Position) IsZero() bool

IsZero returns TRUE if this is a Zero position

func (Position) MarshalBSON

func (position Position) MarshalBSON() ([]byte, error)

MarshalBSON is a custom BSON marshaller that serializes this Position into a GeoJSON coordinate pair

func (Position) MarshalJSON

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

MarshalJSON is a custom JBSON marshaller that serializes this Position into a GeoJSON coordinate pair

func (Position) MarshalSlice

func (position Position) MarshalSlice() []float64

MarshalSlice returns a longitude/latitude coordinate pair

func (Position) NotZero

func (position Position) NotZero() bool

NotZero returns TRUE if this Position is not Zero

func (Position) String

func (position Position) String() string

String returns a string representation of this coordinate pair

func (*Position) UnmarshalBSON

func (position *Position) UnmarshalBSON(data []byte) error

UnmarshalBSON is a custom BSON unmarshaller that deserializes a BSON / GeoJSON coordinate pair into this Position structure.

func (*Position) UnmarshalJSON

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

UnmarshalBSON is a custom BSON unmarshaller that deserializes a BSON / GeoJSON coordinate pair into this Position structure.

func (*Position) UnmarshalSlice

func (position *Position) UnmarshalSlice(coordinates sliceof.Float) error

Jump to

Keyboard shortcuts

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