Documentation
¶
Overview ¶
Package geojson is for working with GeoJSON in Go.
Index ¶
- Constants
- func LineStringToS2(linestring LineString) (*s2.Polyline, error)
- func LoopToS2(loop []Position) *s2.Loop
- func PolygonToS2(polygon Polygon) (*s2.Polygon, error)
- type BoundingBox
- type Feature
- func (f Feature[G]) BoundingBox() *BoundingBox
- func (f Feature[G]) Geometry() Geometry
- func (f Feature[G]) MarshalJSON() ([]byte, error)
- func (f Feature[G]) Properties() PropertyList
- func (f *Feature[G]) UnmarshalJSON(data []byte) error
- func (f Feature[G]) Validate() error
- func (f Feature[G]) WithProperties(properties ...Property) Feature[G]
- type FeatureCollection
- type Geometry
- type GeometryCollection
- type GeometryType
- type LineString
- type MultiLineString
- type MultiPoint
- type MultiPolygon
- type Point
- type Polygon
- type Position
- type Property
- type PropertyList
Constants ¶
const ( TypePropFeature = "Feature" TypePropFeatureCollection = "FeatureCollection" )
"type" properties.
Variables ¶
This section is empty.
Functions ¶
func LineStringToS2 ¶
func LineStringToS2(linestring LineString) (*s2.Polyline, error)
LineStringToS2 returns an S2 Geometry polyline.
Types ¶
type BoundingBox ¶
BoundingBox represents a bounding box in either 2D or 3D space.
func (BoundingBox) MarshalJSON ¶
func (b BoundingBox) MarshalJSON() ([]byte, error)
MarshalJSON returns the JSON encoding of the box. It is an error if only 1 elevation value is set - either both positions or neither must have it.
func (*BoundingBox) UnmarshalJSON ¶
func (b *BoundingBox) UnmarshalJSON(data []byte) error
UnmarshalJSON parses the JSON-encoded data and stores the results.
type Feature ¶
type Feature[G Geometry] struct { // contains filtered or unexported fields }
Feature consists of a specific geometry type and a list of properties.
func NewFeature ¶
NewFeature creates a new feature.
func NewFeatureWithBoundingBox ¶
func NewFeatureWithBoundingBox[G Geometry](geometry G, box BoundingBox, properties ...Property) Feature[G]
NewFeatureWithBoundingBox creates a new feature with the supplied bounding box.
func (Feature[G]) BoundingBox ¶
func (f Feature[G]) BoundingBox() *BoundingBox
BoundingBox returns the stored bounding box.
func (Feature[G]) MarshalJSON ¶
MarshalJSON returns the JSON encoding of the Feature.
func (Feature[G]) Properties ¶
func (f Feature[G]) Properties() PropertyList
Properties returns the stored properties.
func (*Feature[G]) UnmarshalJSON ¶
UnmarshalJSON parses the JSON-encoded data and stores the result.
func (Feature[G]) WithProperties ¶ added in v3.1.0
WithProperties returns a copy of f with the supplied properties appended.
type FeatureCollection ¶
type FeatureCollection struct {
// contains filtered or unexported fields
}
FeatureCollection is a list of Features.
func NewFeatureCollection ¶
func NewFeatureCollection(features ...Feature[Geometry]) FeatureCollection
NewFeatureCollection creates a new feature collection.
func NewFeatureCollectionWithBoundingBox ¶
func NewFeatureCollectionWithBoundingBox(box BoundingBox, features ...Feature[Geometry]) FeatureCollection
NewFeatureCollectionWithBoundingBox creates a new feature collection with the supplied bounding box.
func (FeatureCollection) MarshalJSON ¶
func (c FeatureCollection) MarshalJSON() ([]byte, error)
MarshalJSON returns the JSON encoding of the FeatureCollection.
func (*FeatureCollection) UnmarshalJSON ¶
func (c *FeatureCollection) UnmarshalJSON(data []byte) error
UnmarshalJSON parses the JSON-encoded data and stores the result.
type Geometry ¶
type Geometry interface { json.Marshaler json.Unmarshaler Type() GeometryType Validate() error }
Geometry contains the points represented by a particular geometry type.
type GeometryCollection ¶
type GeometryCollection []Geometry
GeometryCollection is a heterogeneous collection of Geometry objects.
func NewGeometryCollection ¶
func NewGeometryCollection(geometries ...Geometry) *GeometryCollection
NewGeometryCollection returns a GeometryCollection Feature.
func (GeometryCollection) MarshalJSON ¶
func (c GeometryCollection) MarshalJSON() ([]byte, error)
MarshalJSON returns the JSON encoding of the GeometryCollection.
func (GeometryCollection) Type ¶
func (c GeometryCollection) Type() GeometryType
Type returns the geometry type.
func (*GeometryCollection) UnmarshalJSON ¶
func (c *GeometryCollection) UnmarshalJSON(data []byte) error
UnmarshalJSON parses the JSON-encoded data and stores the result.
func (GeometryCollection) Validate ¶
func (c GeometryCollection) Validate() error
Validate the GeometryCollection.
type GeometryType ¶
type GeometryType string
GeometryType is a supported geometry type.
const ( PointGeometryType GeometryType = "Point" MultiPointGeometryType GeometryType = "MultiPoint" LineStringGeometryType GeometryType = "LineString" MultiLineStringGeometryType GeometryType = "MultiLineString" PolygonGeometryType GeometryType = "Polygon" MultiPolygonGeometryType GeometryType = "MultiPolygon" GeometryCollectionType GeometryType = "GeometryCollection" )
Types of geometry.
type LineString ¶
type LineString []Position
LineString is a set of two or more Positions.
func NewLineString ¶
func NewLineString(pos1, pos2 Position, others ...Position) *LineString
NewLineString returns a LineString from the supplied positions.
func (LineString) MarshalJSON ¶
func (l LineString) MarshalJSON() ([]byte, error)
MarshalJSON returns the JSON encoding of the LineString.
func (*LineString) UnmarshalJSON ¶
func (l *LineString) UnmarshalJSON(data []byte) error
UnmarshalJSON parses the JSON-encoded data and stores the result.
type MultiLineString ¶
type MultiLineString [][]Position
MultiLineString is a set of LineStrings.
func NewMultiLineString ¶
func NewMultiLineString(pos ...[]Position) *MultiLineString
NewMultiLineString returns a new MultiLineString from the supplied position "strings".
func (MultiLineString) MarshalJSON ¶
func (m MultiLineString) MarshalJSON() ([]byte, error)
MarshalJSON returns the JSON encoding of the MultiLineString.
func (MultiLineString) Type ¶
func (m MultiLineString) Type() GeometryType
Type returns the geometry type.
func (*MultiLineString) UnmarshalJSON ¶
func (m *MultiLineString) UnmarshalJSON(data []byte) error
UnmarshalJSON parses the JSON-encoded data and stores the result.
func (MultiLineString) Validate ¶
func (m MultiLineString) Validate() error
Validate the MultiLineString.
type MultiPoint ¶
type MultiPoint []Position
MultiPoint is a set of Position.
func NewMultiPoint ¶
func NewMultiPoint(pos ...Position) *MultiPoint
NewMultiPoint returns a multipoint with the specified set of positions.
func (MultiPoint) MarshalJSON ¶
func (m MultiPoint) MarshalJSON() ([]byte, error)
MarshalJSON returns the JSON encoding of the MultiPoint.
func (*MultiPoint) UnmarshalJSON ¶
func (m *MultiPoint) UnmarshalJSON(data []byte) error
UnmarshalJSON parses the JSON-encoded data and stores the result.
type MultiPolygon ¶
type MultiPolygon [][][]Position
MultiPolygon is a set of Polygons.
func NewMultiPolygon ¶
func NewMultiPolygon(p ...[][]Position) *MultiPolygon
NewMultiPolygon returns a new MultiPolygon from the supplied polygons.
func (MultiPolygon) MarshalJSON ¶
func (m MultiPolygon) MarshalJSON() ([]byte, error)
MarshalJSON returns the JSON encoding of the MultiPolygon.
func (MultiPolygon) Type ¶
func (m MultiPolygon) Type() GeometryType
Type returns the geometry type.
func (*MultiPolygon) UnmarshalJSON ¶
func (m *MultiPolygon) UnmarshalJSON(data []byte) error
UnmarshalJSON parses the JSON-encoded data and stores the result.
type Point ¶
type Point Position
Point is a single set of Position.
func NewPointWithElevation ¶
NewPointWithElevation returns a Point Feature with the specified longitude, latitude and elevation.
func (Point) MarshalJSON ¶
MarshalJSON returns the JSON encoding of the Point.
func (*Point) UnmarshalJSON ¶
UnmarshalJSON parses the JSON-encoded data and stores the result.
type Polygon ¶
type Polygon [][]Position
Polygon is a set of linear rings (closed LineStrings).
func NewPolygon ¶
NewPolygon returns a new Polygon from the supplied linear rings.
func (Polygon) MarshalJSON ¶
MarshalJSON returns the JSON encoding of the Polygon.
func (*Polygon) UnmarshalJSON ¶
UnmarshalJSON parses the JSON-encoded data and stores the result.
type Position ¶
type Position struct {
// contains filtered or unexported fields
}
Position represents a longitude and latitude with optional elevation/altitude.
func MakePosition ¶
MakePosition from longitude and latitude.
func MakePositionWithElevation ¶
MakePositionWithElevation from longitude, latitude and elevation.
func (Position) MarshalJSON ¶
MarshalJSON returns the JSON encoding of the Position. The JSON encoding is an array of numbers with the longitude followed by the latitude, and optional elevation.
func (*Position) UnmarshalJSON ¶
UnmarshalJSON parses the JSON-encoded data and stores the results.
type Property ¶
type Property struct { Name string Value interface{} }
Property represents a single property of arbitrary type.
type PropertyList ¶
type PropertyList []Property
PropertyList is a list of Properties.
func NewPropertyList ¶
func NewPropertyList(props ...Property) PropertyList
NewPropertyList creates a new PropertyList from the supplied Properties.
func (*PropertyList) Get ¶
func (l *PropertyList) Get(name string) (*Property, bool)
Get a Property from the list.
func (*PropertyList) GetValue ¶
func (l *PropertyList) GetValue(name string, dest interface{}) error
GetValue assigns a named property to dest if the types are equal.
func (PropertyList) MarshalJSON ¶
func (l PropertyList) MarshalJSON() ([]byte, error)
MarshalJSON returns the JSON encoding of the PropertyList.
func (*PropertyList) UnmarshalJSON ¶
func (l *PropertyList) UnmarshalJSON(data []byte) error
UnmarshalJSON parses the JSON-encoded data and stores the result.