package wkbcommon

import "github.com/paulmach/orb/encoding/internal/wkbcommon"

Index

Constants

const (
	// limits so that bad data can't come in and preallocate tons of memory.
	// Well formed data with less elements will allocate the correct amount just fine.
	MaxPointsAlloc = 10000
	MaxMultiAlloc  = 100
)

Variables

var (
	// ErrUnsupportedDataType is returned by Scan methods when asked to scan
	// non []byte data from the database. This should never happen
	// if the driver is acting appropriately.
	ErrUnsupportedDataType = errors.New("wkbcommon: scan value must be []byte")

	// ErrNotWKB is returned when unmarshalling WKB and the data is not valid.
	ErrNotWKB = errors.New("wkbcommon: invalid data")

	// ErrNotWKBHeader is returned when unmarshalling first few bytes and there
	// is an issue.
	ErrNotWKBHeader = errors.New("wkbcommon: invalid header data")

	// ErrIncorrectGeometry is returned when unmarshalling WKB data into the wrong type.
	// For example, unmarshaling linestring data into a point.
	ErrIncorrectGeometry = errors.New("wkbcommon: incorrect geometry")

	// ErrUnsupportedGeometry is returned when geometry type is not supported by this lib.
	ErrUnsupportedGeometry = errors.New("wkbcommon: unsupported geometry")
)
var DefaultByteOrder binary.ByteOrder = binary.LittleEndian

DefaultByteOrder is the order used for marshalling or encoding is none is specified.

Functions

func GeomLength

func GeomLength(geom orb.Geometry, ewkb bool) int

GeomLength helps to do preallocation during a marshal.

func Marshal

func Marshal(geom orb.Geometry, srid int, byteOrder ...binary.ByteOrder) ([]byte, error)

Marshal encodes the geometry with the given byte order.

func MustMarshal

func MustMarshal(geom orb.Geometry, srid int, byteOrder ...binary.ByteOrder) []byte

MustMarshal will encode the geometry and panic on error. Currently there is no reason to error during geometry marshalling.

func Scan

func Scan(g, d interface{}) (orb.Geometry, int, bool, error)

Scan will scan the input []byte data into a geometry. This could be into the orb geometry type pointer or, if nil, the scanner.Geometry attribute.

func ScanCollection

func ScanCollection(data []byte) (orb.Collection, int, error)

ScanCollection takes binary wkb and decodes it into a collection.

func ScanLineString

func ScanLineString(data []byte) (orb.LineString, int, error)

ScanLineString takes binary wkb and decodes it into a line string.

func ScanMultiLineString

func ScanMultiLineString(data []byte) (orb.MultiLineString, int, error)

ScanMultiLineString takes binary wkb and decodes it into a multi-line string.

func ScanMultiPoint

func ScanMultiPoint(data []byte) (orb.MultiPoint, int, error)

ScanMultiPoint takes binary wkb and decodes it into a multi-point.

func ScanMultiPolygon

func ScanMultiPolygon(data []byte) (orb.MultiPolygon, int, error)

ScanMultiPolygon takes binary wkb and decodes it into a multi-polygon.

func ScanPoint

func ScanPoint(data []byte) (orb.Point, int, error)

ScanPoint takes binary wkb and decodes it into a point.

func ScanPolygon

func ScanPolygon(data []byte) (orb.Polygon, int, error)

ScanPolygon takes binary wkb and decodes it into a polygon.

func Unmarshal

func Unmarshal(data []byte) (orb.Geometry, int, error)

Unmarshal will decode the type into a Geometry.

Types

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

Decoder can decoder (E)WKB geometry off of the stream.

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

NewDecoder will create a new (E)WKB decoder.

func (*Decoder) Decode

func (d *Decoder) Decode() (orb.Geometry, int, error)

Decode will decode the next geometry off of the stream.

type Encoder

type Encoder struct {
	// contains filtered or unexported fields
}

An Encoder will encode a geometry as (E)WKB to the writer given at creation time.

func NewEncoder

func NewEncoder(w io.Writer) *Encoder

NewEncoder creates a new Encoder for the given writer.

func (*Encoder) Encode

func (e *Encoder) Encode(geom orb.Geometry, srid int) error

Encode will write the geometry encoded as (E)WKB to the given writer.

func (*Encoder) SetByteOrder

func (e *Encoder) SetByteOrder(bo binary.ByteOrder)

SetByteOrder will override the default byte order set when the encoder was created.

Source Files

collection.go line_string.go point.go polygon.go scan.go wkb.go

Version
v0.11.1 (latest)
Published
Jan 29, 2024
Platform
js/wasm
Imports
8 packages
Last checked
1 day ago

Tools for package owners.