geojson

package
v0.0.0-...-3cd2f5a Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2022 License: MIT Imports: 6 Imported by: 11

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

View Source
const (
	FieldKeyType        = "type"
	FieldKeyCoordinates = "coordinates"
	FieldKeyGeometries  = "geometries"
)

Variables

View Source
var (
	ErrUnknownFeatureType = fmt.Errorf("unknown feature type")
)

Functions

func Marshal

func Marshal(v interface{}) ([]byte, error)

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

func MarshalIndent(v interface{}, prefix, indent string) ([]byte, error)

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.

func Unmarshal

func Unmarshal(data []byte) (feature interface{}, err error)

Unmarshal parses the GeoJSON-encoded data and returns the result or an error. The result can be either a geojson.Features or geojson.FeatureCollection. If the encoded data is not one of the above then function will return the error json.InvalidUnmarshalError.

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

type Geometry struct {
	geom.Geometry
}

Geometry wraps a geom Geometry so that it can be encoded as a GeoJSON feature

func (Geometry) MarshalJSON

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

func (*Geometry) UnmarshalJSON

func (geo *Geometry) UnmarshalJSON(b []byte) (err error)

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"
)

Jump to

Keyboard shortcuts

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