Documentation
¶
Overview ¶
Package geojson implements encoding and decoding of GeoJSON as defined in [RFC 7946](https://tools.ietf.org/html/rfc7946). The mapping between JSON and geom Geometry values are described in the documentation for the Marshal and Unmarshal functions.
At current this package only supports 2D Geometries unless stated otherwise by the documentation of the Marshal and Unmarshal functions
Index ¶
Constants ¶
const ( FieldKeyType = "type" FieldKeyCoordinates = "coordinates" FieldKeyGeometries = "geometries" )
Variables ¶
var (
ErrUnknownFeatureType = fmt.Errorf("unknown feature type")
)
Functions ¶
func Marshal ¶
Marshal returns the geojson encoding of the geojson.Feature, geojson.FeatureCollection, or a geom.Geometry.
If Marshal is given a geom.Geometry, this geometry will be wrapped in a geojson.Feature, with no properties or and ID. If something other than the above is passed in the system will return a geom.ErrUnknownGeometry type. Values in the property map are marshaled according to the type-dependent default encoding as defined by the go's encoding/json package.
func MarshalIndent ¶
MarshalIndent is like Marshal but applies Indent to format the output Each JSON element is the output will begin on a new line beginning with prefix followed by one or more copies of indent according to indentation nesting.
Types ¶
type ErrMissingField ¶
type ErrMissingField string
func (ErrMissingField) Error ¶
func (err ErrMissingField) Error() string
func (ErrMissingField) Is ¶
func (err ErrMissingField) Is(target error) bool
type Feature ¶
type Feature struct { Type featureType `json:"type"` ID *uint64 `json:"id,omitempty"` // Geometry can be null Geometry Geometry `json:"geometry"` // Properties can be null Properties map[string]interface{} `json:"properties"` }
Feature represents as geojson feature
type FeatureCollection ¶
type FeatureCollection struct { Type featureCollectionType `json:"type"` Features []Feature `json:"features"` }
FeatureCollection describes a geoJSON collection feature
type Geometry ¶
Geometry wraps a geom Geometry so that it can be encoded as a GeoJSON feature
func (Geometry) MarshalJSON ¶
func (*Geometry) UnmarshalJSON ¶
UnmarshalJSON will attempt to unmarshal the given bytes into a GeoJSON object. It can produce a variety of json Marshaling errors or encoding.InvalidGeometry if the geometry type in unsupported
type JsonType ¶
type JsonType string
const ( PointType JsonType = "Point" MultiPointType JsonType = "MultiPoint" LineStringType JsonType = "LineString" MultiLineStringType JsonType = "MultiLineString" PolygonType JsonType = "Polygon" MultiPolygonType JsonType = "MultiPolygon" GeometryCollectionType JsonType = "GeometryCollection" FeatureType JsonType = "Feature" FeatureCollectionType JsonType = "FeatureCollection" )