geojson

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2023 License: MIT Imports: 6 Imported by: 0

README

orb/geojson Godoc Reference

This package encodes and decodes GeoJSON into Go structs using the geometries in the orb package.

Supports both the json.Marshaler and json.Unmarshaler interfaces. The package also provides helper functions such as UnmarshalFeatureCollection and UnmarshalFeature.

The types also support BSON via the bson.Marshaler and bson.Unmarshaler interfaces. These types can be used directly when working with MongoDB.

Unmarshalling (JSON -> Go)

rawJSON := []byte(`
  { "type": "FeatureCollection",
    "features": [
      { "type": "Feature",
        "geometry": {"type": "Point", "coordinates": [102.0, 0.5]},
        "properties": {"prop0": "value0"}
      }
    ]
  }`)

fc, _ := geojson.UnmarshalFeatureCollection(rawJSON)

// or

fc := geojson.NewFeatureCollection()
err := json.Unmarshal(rawJSON, &fc)

// Geometry will be unmarshalled into the correct geo.Geometry type.
point := fc.Features[0].Geometry.(orb.Point)

Marshalling (Go -> JSON)

fc := geojson.NewFeatureCollection()
fc.Append(geojson.NewFeature(orb.Point{1, 2}))

rawJSON, _ := fc.MarshalJSON()

// or
blob, _ := json.Marshal(fc)

Foreign/extra members in a feature collection

rawJSON := []byte(`
  { "type": "FeatureCollection",
    "generator": "myapp",
    "timestamp": "2020-06-15T01:02:03Z",
    "features": [
      { "type": "Feature",
        "geometry": {"type": "Point", "coordinates": [102.0, 0.5]},
        "properties": {"prop0": "value0"}
      }
    ]
  }`)

fc, _ := geojson.UnmarshalFeatureCollection(rawJSON)

fc.ExtraMembers["generator"] // == "myApp"
fc.ExtraMembers["timestamp"] // == "2020-06-15T01:02:03Z"

// Marshalling will include values in `ExtraMembers` in the
// base featureCollection object.

Performance

For performance critical applications, consider a third party replacement of "encoding/json" like github.com/json-iterator/go

This can be enabled with something like this:

import (
  jsoniter "github.com/json-iterator/go"
  "github.com/TucarApp/orb"
)

var c = jsoniter.Config{
  EscapeHTML:              true,
  SortMapKeys:             false,
  MarshalFloatWith6Digits: true,
}.Froze()

CustomJSONMarshaler = c
CustomJSONUnmarshaler = c

The above change can have dramatic performance implications, see the benchmarks below on a 100k feature collection file:

benchmark                             old ns/op     new ns/op     delta
BenchmarkFeatureMarshalJSON-12        2694543       733480        -72.78%
BenchmarkFeatureUnmarshalJSON-12      5383825       2738183       -49.14%
BenchmarkGeometryMarshalJSON-12       210107        62789         -70.12%
BenchmarkGeometryUnmarshalJSON-12     691472        144689        -79.08%

benchmark                             old allocs     new allocs     delta
BenchmarkFeatureMarshalJSON-12        7818           2316           -70.38%
BenchmarkFeatureUnmarshalJSON-12      23047          31946          +38.61%
BenchmarkGeometryMarshalJSON-12       2              3              +50.00%
BenchmarkGeometryUnmarshalJSON-12     2042           18             -99.12%

benchmark                             old bytes     new bytes     delta
BenchmarkFeatureMarshalJSON-12        794088        490251        -38.26%
BenchmarkFeatureUnmarshalJSON-12      766354        1068497       +39.43%
BenchmarkGeometryMarshalJSON-12       24787         18650         -24.76%
BenchmarkGeometryUnmarshalJSON-12     79784         51374         -35.61%

Feature Properties

GeoJSON features can have properties of any type. This can cause issues in a statically typed language such as Go. Included is a Properties type with some helper methods that will try to force convert a property. An optional default, will be used if the property is missing or the wrong type.

f.Properties.MustBool(key string, def ...bool) bool
f.Properties.MustFloat64(key string, def ...float64) float64
f.Properties.MustInt(key string, def ...int) int
f.Properties.MustString(key string, def ...string) string

Documentation

Overview

Package geojson is a library for encoding and decoding GeoJSON into Go structs using the geometries in the orb package. Supports both the json.Marshaler and json.Unmarshaler interfaces as well as helper functions such as `UnmarshalFeatureCollection` and `UnmarshalFeature`.

Example (Centroid)
package main

import (
	"fmt"
	"log"

	"github.com/TucarApp/orb"
	"github.com/TucarApp/orb/geojson"
	"github.com/TucarApp/orb/planar"
	"github.com/TucarApp/orb/quadtree"
)

type CentroidPoint struct {
	*geojson.Feature
}

func (cp CentroidPoint) Point() orb.Point {
	// this is where you would decide how to define
	// the representative point of the feature.
	c, _ := planar.CentroidArea(cp.Geometry)
	return c
}

func main() {
	qt := quadtree.New(orb.Bound{Min: orb.Point{0, 0}, Max: orb.Point{1, 1}})

	// feature with center {0.5, 0.5} but centroid {0.25, 0.25}
	f := geojson.NewFeature(orb.MultiPoint{{0, 0}, {0, 0}, {0, 0}, {1, 1}})
	f.Properties["centroid"] = "0.25"
	err := qt.Add(CentroidPoint{f})
	if err != nil {
		log.Fatalf("unexpected error: %v", err)
	}

	// feature with centroid {0.6, 0.6}
	f = geojson.NewFeature(orb.Point{0.6, 0.6})
	f.Properties["centroid"] = "0.6"
	err = qt.Add(CentroidPoint{f})
	if err != nil {
		log.Fatalf("unexpected error: %v", err)
	}

	feature := qt.Find(orb.Point{0.5, 0.5}).(CentroidPoint).Feature
	fmt.Printf("centroid=%s", feature.Properties["centroid"])

}
Output:

centroid=0.6
Example (Unmarshal)
package main

import (
	"encoding/json"
	"fmt"
	"log"

	"github.com/TucarApp/orb"
	"github.com/TucarApp/orb/geojson"
)

func main() {
	rawJSON := []byte(`
	  { "type": "FeatureCollection",
	    "features": [
	      { "type": "Feature",
	        "geometry": {"type": "Point", "coordinates": [102.0, 0.5]},
	        "properties": {"prop0": "value0"}
	      }
	    ]
	  }`)

	fc := geojson.NewFeatureCollection()
	err := json.Unmarshal(rawJSON, &fc)
	if err != nil {
		log.Fatalf("invalid json: %v", err)
	}

	// Geometry will be unmarshalled into the correct geo.Geometry type.
	point := fc.Features[0].Geometry.(orb.Point)
	fmt.Println(point)

}
Output:

[102 0.5]

Index

Examples

Constants

View Source
const (
	TypePoint           = "Point"
	TypeMultiPoint      = "MultiPoint"
	TypeLineString      = "LineString"
	TypeMultiLineString = "MultiLineString"
	TypePolygon         = "Polygon"
	TypeMultiPolygon    = "MultiPolygon"
)

A list of the geojson types that are currently supported.

Variables

View Source
var CustomJSONMarshaler interface {
	Marshal(v interface{}) ([]byte, error)
} = nil

CustomJSONMarshaler can be set to have the code use a different json marshaler than the default in the standard library. One use case in enabling `github.com/json-iterator/go` with something like this:

import (
  jsoniter "github.com/json-iterator/go"
  "github.com/TucarApp/orb"
)

var c = jsoniter.Config{
  EscapeHTML:              true,
  SortMapKeys:             false,
  MarshalFloatWith6Digits: true,
}.Froze()

orb.CustomJSONMarshaler = c
orb.CustomJSONUnmarshaler = c

Note that any errors encountered during marshaling will be different.

View Source
var CustomJSONUnmarshaler interface {
	Unmarshal(data []byte, v interface{}) error
} = nil

CustomJSONUnmarshaler can be set to have the code use a different json unmarshaler than the default in the standard library. One use case in enabling `github.com/json-iterator/go` with something like this:

import (
  jsoniter "github.com/json-iterator/go"
  "github.com/TucarApp/orb"
)

var c = jsoniter.Config{
  EscapeHTML:              true,
  SortMapKeys:             false,
  MarshalFloatWith6Digits: true,
}.Froze()

orb.CustomJSONMarshaler = c
orb.CustomJSONUnmarshaler = c

Note that any errors encountered during unmarshaling will be different.

View Source
var ErrInvalidGeometry = errors.New("geojson: invalid geometry")

ErrInvalidGeometry will be returned if a the json of the geometry is invalid.

Functions

This section is empty.

Types

type BBox

type BBox []float64

BBox is for the geojson bbox attribute which is an array with all axes of the most southwesterly point followed by all axes of the more northeasterly point.

func NewBBox

func NewBBox(b orb.Bound) BBox

NewBBox creates a bbox from a a bound.

func (BBox) Bound

func (bb BBox) Bound() orb.Bound

Bound returns the orb.Bound for the BBox.

func (BBox) Valid

func (bb BBox) Valid() bool

Valid checks if the bbox is present and has at least 4 elements.

type Feature

type Feature struct {
	ID         interface{}  `json:"id,omitempty"`
	Type       string       `json:"type"`
	BBox       BBox         `json:"bbox,omitempty"`
	Geometry   orb.Geometry `json:"geometry"`
	Properties Properties   `json:"properties"`
}

A Feature corresponds to GeoJSON feature object

func NewFeature

func NewFeature(geometry orb.Geometry) *Feature

NewFeature creates and initializes a GeoJSON feature given the required attributes.

func UnmarshalFeature

func UnmarshalFeature(data []byte) (*Feature, error)

UnmarshalFeature decodes the data into a GeoJSON feature. Alternately one can call json.Unmarshal(f) directly for the same result.

func (Feature) MarshalBSON

func (f Feature) MarshalBSON() ([]byte, error)

MarshalBSON converts the feature object into the proper JSON. It will handle the encoding of all the child geometries. Alternately one can call json.Marshal(f) directly for the same result.

func (Feature) MarshalJSON

func (f Feature) MarshalJSON() ([]byte, error)

MarshalJSON converts the feature object into the proper JSON. It will handle the encoding of all the child geometries. Alternately one can call json.Marshal(f) directly for the same result.

func (*Feature) Point

func (f *Feature) Point() orb.Point

Point implements the orb.Pointer interface so that Features can be used with quadtrees. The point returned is the center of the Bound of the geometry. To represent the geometry with another point you must create a wrapper type.

Example
package main

import (
	"fmt"
	"log"

	"github.com/TucarApp/orb"
	"github.com/TucarApp/orb/geojson"
	"github.com/TucarApp/orb/quadtree"
)

func main() {
	f := geojson.NewFeature(orb.Point{1, 1})
	f.Properties["key"] = "value"

	qt := quadtree.New(f.Geometry.Bound().Pad(1))
	err := qt.Add(f) // add the feature to a quadtree
	if err != nil {
		log.Fatalf("unexpected error: %v", err)
	}

	// type assert the feature back into a Feature from
	// the orb.Pointer interface.
	feature := qt.Find(orb.Point{0, 0}).(*geojson.Feature)
	fmt.Printf("key=%s", feature.Properties["key"])

}
Output:

key=value

func (*Feature) UnmarshalBSON

func (f *Feature) UnmarshalBSON(data []byte) error

UnmarshalBSON will unmarshal a BSON document created with bson.Marshal.

func (*Feature) UnmarshalJSON

func (f *Feature) UnmarshalJSON(data []byte) error

UnmarshalJSON handles the correct unmarshalling of the data into the orb.Geometry types.

type FeatureCollection

type FeatureCollection struct {
	Type     string     `json:"type"`
	BBox     BBox       `json:"bbox,omitempty"`
	Features []*Feature `json:"features"`

	// ExtraMembers can be used to encoded/decode extra key/members in
	// the base of the feature collection. Note that keys of "type", "bbox"
	// and "features" will not work as those are reserved by the GeoJSON spec.
	ExtraMembers Properties `json:"-"`
}

A FeatureCollection correlates to a GeoJSON feature collection.

Example (ForeignMembers)
package main

import (
	"encoding/json"
	"fmt"
	"log"

	"github.com/TucarApp/orb/geojson"
)

func main() {
	rawJSON := []byte(`
	  { "type": "FeatureCollection",
	    "features": [
	      { "type": "Feature",
	        "geometry": {"type": "Point", "coordinates": [102.0, 0.5]},
	        "properties": {"prop0": "value0"}
	      }
	    ],
	    "title": "Title as Foreign Member"
	  }`)

	fc := geojson.NewFeatureCollection()
	err := json.Unmarshal(rawJSON, &fc)
	if err != nil {
		log.Fatalf("invalid json: %v", err)
	}

	fmt.Println(fc.Features[0].Geometry)
	fmt.Println(fc.ExtraMembers["title"])

	data, _ := json.Marshal(fc)
	fmt.Println(string(data))

}
Output:

[102 0.5]
Title as Foreign Member
{"features":[{"type":"Feature","geometry":{"type":"Point","coordinates":[102,0.5]},"properties":{"prop0":"value0"}}],"title":"Title as Foreign Member","type":"FeatureCollection"}
Example (ForeignMembersCustom)
package main

import (
	"encoding/json"
	"fmt"
	"log"

	"github.com/TucarApp/orb/geojson"
)

// MyFeatureCollection is a depricated/no longer supported way to extract
// foreign/extra members from a feature collection. Now an UnmarshalJSON
// method, like below, is required for it to work.
type MyFeatureCollection struct {
	geojson.FeatureCollection
	Title string `json:"title"`
}

// UnmarshalJSON implemented as below is now required for the extra members
// to be decoded directly into the type.
func (fc *MyFeatureCollection) UnmarshalJSON(data []byte) error {
	err := json.Unmarshal(data, &fc.FeatureCollection)
	if err != nil {
		return err
	}

	fc.Title = fc.ExtraMembers.MustString("title", "")
	return nil
}

func main() {
	// Note: this approach to handling foreign/extra members requires
	// implementing an `UnmarshalJSON` method on the new type.
	// See MyFeatureCollection type and its UnmarshalJSON function above.

	rawJSON := []byte(`
	  { "type": "FeatureCollection",
	    "features": [
	      { "type": "Feature",
	        "geometry": {"type": "Point", "coordinates": [102.0, 0.5]},
	        "properties": {"prop0": "value0"}
	      }
	    ],
	    "title": "Title as Foreign Member"
	  }`)

	fc := &MyFeatureCollection{}
	err := json.Unmarshal(rawJSON, &fc)
	if err != nil {
		log.Fatalf("invalid json: %v", err)
	}

	fmt.Println(fc.FeatureCollection.Features[0].Geometry)
	fmt.Println(fc.Features[0].Geometry)
	fmt.Println(fc.Title)
}
Output:

[102 0.5]
[102 0.5]
Title as Foreign Member

func NewFeatureCollection

func NewFeatureCollection() *FeatureCollection

NewFeatureCollection creates and initializes a new feature collection.

func UnmarshalFeatureCollection

func UnmarshalFeatureCollection(data []byte) (*FeatureCollection, error)

UnmarshalFeatureCollection decodes the data into a GeoJSON feature collection. Alternately one can call json.Unmarshal(fc) directly for the same result.

Example
package main

import (
	"fmt"

	"github.com/TucarApp/orb"
	"github.com/TucarApp/orb/geojson"
)

func main() {
	rawJSON := []byte(`
	  { "type": "FeatureCollection",
	    "features": [
	      { "type": "Feature",
	        "geometry": {"type": "Point", "coordinates": [102.0, 0.5]},
	        "properties": {"prop0": "value0"}
	      }
	    ]
	  }`)

	fc, _ := geojson.UnmarshalFeatureCollection(rawJSON)

	// Geometry will be unmarshalled into the correct geo.Geometry type.
	point := fc.Features[0].Geometry.(orb.Point)
	fmt.Println(point)

}
Output:

[102 0.5]

func (*FeatureCollection) Append

func (fc *FeatureCollection) Append(feature *Feature) *FeatureCollection

Append appends a feature to the collection.

func (FeatureCollection) MarshalBSON

func (fc FeatureCollection) MarshalBSON() ([]byte, error)

MarshalBSON converts the feature collection object into a BSON document represented by bytes. It will handle the encoding of all the child features and geometries. Items in the ExtraMembers map will be included in the base of the feature collection object.

func (FeatureCollection) MarshalJSON

func (fc FeatureCollection) MarshalJSON() ([]byte, error)

MarshalJSON converts the feature collection object into the proper JSON. It will handle the encoding of all the child features and geometries. Alternately one can call json.Marshal(fc) directly for the same result. Items in the ExtraMembers map will be included in the base of the feature collection object.

Example
package main

import (
	"encoding/json"
	"fmt"
	"log"

	"github.com/TucarApp/orb"
	"github.com/TucarApp/orb/geojson"
)

func main() {
	fc := geojson.NewFeatureCollection()
	fc.Append(geojson.NewFeature(orb.Point{1, 2}))

	_, err := fc.MarshalJSON()
	if err != nil {
		log.Fatalf("marshal error: %v", err)
	}

	// standard lib encoding/json package will also work
	data, err := json.MarshalIndent(fc, "", " ")
	if err != nil {
		log.Fatalf("marshal error: %v", err)
	}

	fmt.Println(string(data))

}
Output:

{
 "features": [
  {
   "type": "Feature",
   "geometry": {
    "type": "Point",
    "coordinates": [
     1,
     2
    ]
   },
   "properties": null
  }
 ],
 "type": "FeatureCollection"
}

func (*FeatureCollection) UnmarshalBSON

func (fc *FeatureCollection) UnmarshalBSON(data []byte) error

UnmarshalBSON will unmarshal a BSON document created with bson.Marshal. Extra/foreign members will be put into the `ExtraMembers` attribute.

func (*FeatureCollection) UnmarshalJSON

func (fc *FeatureCollection) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes the data into a GeoJSON feature collection. Extra/foreign members will be put into the `ExtraMembers` attribute.

type Geometry

type Geometry struct {
	Type        string       `json:"type"`
	Coordinates orb.Geometry `json:"coordinates,omitempty"`
	Geometries  []*Geometry  `json:"geometries,omitempty"`
}

A Geometry matches the structure of a GeoJSON Geometry.

func NewGeometry

func NewGeometry(g orb.Geometry) *Geometry

NewGeometry will create a Geometry object but will convert the input into a GoeJSON geometry. For example, it will convert Rings and Bounds into Polygons.

func UnmarshalGeometry

func UnmarshalGeometry(data []byte) (*Geometry, error)

UnmarshalGeometry decodes the JSON data into a GeoJSON feature. Alternately one can call json.Unmarshal(g) directly for the same result.

func (*Geometry) Geometry

func (g *Geometry) Geometry() orb.Geometry

Geometry returns the orb.Geometry for the geojson Geometry. This will convert the "Geometries" into a orb.Collection if applicable.

func (*Geometry) MarshalBSON

func (g *Geometry) MarshalBSON() ([]byte, error)

MarshalBSON will convert the geometry into a BSON document with the structure of a GeoJSON Geometry. This function is used when the geometry is the top level document to be marshalled.

func (*Geometry) MarshalBSONValue

func (g *Geometry) MarshalBSONValue() (bsontype.Type, []byte, error)

MarshalBSONValue will marshal the geometry into a BSON value with the structure of a GeoJSON Geometry.

func (*Geometry) MarshalJSON

func (g *Geometry) MarshalJSON() ([]byte, error)

MarshalJSON will marshal the geometry into the correct JSON structure.

func (*Geometry) UnmarshalBSON

func (g *Geometry) UnmarshalBSON(data []byte) error

UnmarshalBSON will unmarshal a BSON document created with bson.Marshal.

func (*Geometry) UnmarshalJSON

func (g *Geometry) UnmarshalJSON(data []byte) error

UnmarshalJSON will unmarshal the correct geometry from the JSON structure.

type LineString

type LineString orb.LineString

A LineString is a helper type that will marshal to/from a GeoJSON LineString geometry.

func (LineString) Geometry

func (ls LineString) Geometry() orb.Geometry

Geometry will return the orb.Geometry version of the data.

func (LineString) MarshalBSON

func (ls LineString) MarshalBSON() ([]byte, error)

MarshalBSON will convert the LineString into a GeoJSON LineString geometry.

func (LineString) MarshalJSON

func (ls LineString) MarshalJSON() ([]byte, error)

MarshalJSON will convert the LineString into a GeoJSON LineString geometry.

func (*LineString) UnmarshalBSON

func (ls *LineString) UnmarshalBSON(data []byte) error

UnmarshalBSON will unmarshal the GeoJSON MultiPoint geometry.

func (*LineString) UnmarshalJSON

func (ls *LineString) UnmarshalJSON(data []byte) error

UnmarshalJSON will unmarshal the GeoJSON MultiPoint geometry.

type MultiLineString

type MultiLineString orb.MultiLineString

A MultiLineString is a helper type that will marshal to/from a GeoJSON MultiLineString geometry.

func (MultiLineString) Geometry

func (mls MultiLineString) Geometry() orb.Geometry

Geometry will return the orb.Geometry version of the data.

func (MultiLineString) MarshalBSON

func (mls MultiLineString) MarshalBSON() ([]byte, error)

MarshalBSON will convert the MultiLineString into a GeoJSON MultiLineString geometry.

func (MultiLineString) MarshalJSON

func (mls MultiLineString) MarshalJSON() ([]byte, error)

MarshalJSON will convert the MultiLineString into a GeoJSON MultiLineString geometry.

func (*MultiLineString) UnmarshalBSON

func (mls *MultiLineString) UnmarshalBSON(data []byte) error

UnmarshalBSON will unmarshal the GeoJSON MultiPoint geometry.

func (*MultiLineString) UnmarshalJSON

func (mls *MultiLineString) UnmarshalJSON(data []byte) error

UnmarshalJSON will unmarshal the GeoJSON MultiPoint geometry.

type MultiPoint

type MultiPoint orb.MultiPoint

A MultiPoint is a helper type that will marshal to/from a GeoJSON MultiPoint geometry.

func (MultiPoint) Geometry

func (mp MultiPoint) Geometry() orb.Geometry

Geometry will return the orb.Geometry version of the data.

func (MultiPoint) MarshalBSON

func (mp MultiPoint) MarshalBSON() ([]byte, error)

MarshalBSON will convert the MultiPoint into a GeoJSON MultiPoint geometry BSON.

func (MultiPoint) MarshalJSON

func (mp MultiPoint) MarshalJSON() ([]byte, error)

MarshalJSON will convert the MultiPoint into a GeoJSON MultiPoint geometry.

func (*MultiPoint) UnmarshalBSON

func (mp *MultiPoint) UnmarshalBSON(data []byte) error

UnmarshalBSON will unmarshal the GeoJSON MultiPoint geometry.

func (*MultiPoint) UnmarshalJSON

func (mp *MultiPoint) UnmarshalJSON(data []byte) error

UnmarshalJSON will unmarshal the GeoJSON MultiPoint geometry.

type MultiPolygon

type MultiPolygon orb.MultiPolygon

A MultiPolygon is a helper type that will marshal to/from a GeoJSON MultiPolygon geometry.

func (MultiPolygon) Geometry

func (mp MultiPolygon) Geometry() orb.Geometry

Geometry will return the orb.Geometry version of the data.

func (MultiPolygon) MarshalBSON

func (mp MultiPolygon) MarshalBSON() ([]byte, error)

MarshalBSON will convert the MultiPolygon into a GeoJSON MultiPolygon geometry.

func (MultiPolygon) MarshalJSON

func (mp MultiPolygon) MarshalJSON() ([]byte, error)

MarshalJSON will convert the MultiPolygon into a GeoJSON MultiPolygon geometry.

func (*MultiPolygon) UnmarshalBSON

func (mp *MultiPolygon) UnmarshalBSON(data []byte) error

UnmarshalBSON will unmarshal the GeoJSON MultiPolygon geometry.

func (*MultiPolygon) UnmarshalJSON

func (mp *MultiPolygon) UnmarshalJSON(data []byte) error

UnmarshalJSON will unmarshal the GeoJSON MultiPolygon geometry.

type Point

type Point orb.Point

A Point is a helper type that will marshal to/from a GeoJSON Point geometry.

func (Point) Geometry

func (p Point) Geometry() orb.Geometry

Geometry will return the orb.Geometry version of the data.

func (Point) MarshalBSON

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

MarshalBSON will convert the Point into a BSON value following the GeoJSON Point structure.

func (Point) MarshalJSON

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

MarshalJSON will convert the Point into a GeoJSON Point geometry.

func (*Point) UnmarshalBSON

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

UnmarshalBSON will unmarshal GeoJSON Point geometry.

func (*Point) UnmarshalJSON

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

UnmarshalJSON will unmarshal the GeoJSON Point geometry.

type Polygon

type Polygon orb.Polygon

A Polygon is a helper type that will marshal to/from a GeoJSON Polygon geometry.

func (Polygon) Geometry

func (p Polygon) Geometry() orb.Geometry

Geometry will return the orb.Geometry version of the data.

func (Polygon) MarshalBSON

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

MarshalBSON will convert the Polygon into a GeoJSON Polygon geometry.

func (Polygon) MarshalJSON

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

MarshalJSON will convert the Polygon into a GeoJSON Polygon geometry.

func (*Polygon) UnmarshalBSON

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

UnmarshalBSON will unmarshal the GeoJSON Polygon geometry.

func (*Polygon) UnmarshalJSON

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

UnmarshalJSON will unmarshal the GeoJSON Polygon geometry.

type Properties

type Properties map[string]interface{}

Properties defines the feature properties with some helper methods.

func (Properties) Clone

func (p Properties) Clone() Properties

Clone returns a shallow copy of the properties.

func (Properties) MustBool

func (p Properties) MustBool(key string, def ...bool) bool

MustBool guarantees the return of a `bool` (with optional default). This function useful when you explicitly want a `bool` in a single value return context, for example:

myFunc(f.Properties.MustBool("param1"), f.Properties.MustBool("optional_param", true))

This function will panic if the value is present but not a bool.

func (Properties) MustFloat64

func (p Properties) MustFloat64(key string, def ...float64) float64

MustFloat64 guarantees the return of a `float64` (with optional default) This function useful when you explicitly want a `float64` in a single value return context, for example:

myFunc(f.Properties.MustFloat64("param1"), f.Properties.MustFloat64("optional_param", 10.1))

This function will panic if the value is present but not a number.

func (Properties) MustInt

func (p Properties) MustInt(key string, def ...int) int

MustInt guarantees the return of an `int` (with optional default). This function useful when you explicitly want a `int` in a single value return context, for example:

myFunc(f.Properties.MustInt("param1"), f.Properties.MustInt("optional_param", 123))

This function will panic if the value is present but not a number.

func (Properties) MustString

func (p Properties) MustString(key string, def ...string) string

MustString guarantees the return of a `string` (with optional default) This function useful when you explicitly want a `string` in a single value return context, for example:

myFunc(f.Properties.MustString("param1"), f.Properties.MustString("optional_param", "default"))

This function will panic if the value is present but not a string.

Jump to

Keyboard shortcuts

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