wkbcommon

package
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
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

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

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.

Jump to

Keyboard shortcuts

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