wkb

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2021 License: LGPL-2.1 Imports: 11 Imported by: 0

Documentation

Overview

Package wkb is for decoding ESRI's Well Known Binary (WKB) format specification at https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry#Well-known_binary

Package wkb is for decoding ESRI's Well Known Binary (WKB) format specification at https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry#Well-known_binary

Package wkb is for decoding ESRI's Well Known Binary (WKB) format specification at https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry#Well-known_binary

Index

Constants

This section is empty.

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("wkb: scan value must be []byte")

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

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

	// ErrUnsupportedGeometry is returned when geometry type is not supported by this lib.
	ErrUnsupportedGeometry = errors.New("wkb: unsupported geometry")
)

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

View Source
var ErrAttempt = fmt.Errorf("Attempt to read past end of input")

ErrAttempt ...

View Source
var ErrUnknownWKBType = fmt.Errorf("Unknown WKB type ")

ErrUnknownWKBType ...

Functions

func BufferedReader added in v1.0.1

func BufferedReader(bufferedReader io.Reader) []space.Geometry

BufferedReader returns []Geometry from reader.

func BufferedWriter added in v1.0.1

func BufferedWriter(bufferedWriter io.Writer, geoms []space.Geometry)

BufferedWriter returns []Geometry from reader.

func GeomFromWKBHexStr added in v1.0.1

func GeomFromWKBHexStr(wkbHex string) (space.Geometry, error)

GeomFromWKBHexStr convert hex string to GEOSGeometry

func GeomToWKBHexStr added in v1.0.2

func GeomToWKBHexStr(geom space.Geometry) (wkbHex string, err error)

func HexToBytes added in v1.0.1

func HexToBytes(hex string) []byte

HexToBytes Converts a hexadecimal string to a byte array. The hexadecimal digit symbols are case-insensitive.

func Marshal

func Marshal(geom space.Geometry, bo ...byteOrder) ([]byte, error)

Marshal encodes the geometry with the given byte order.

func MustMarshal

func MustMarshal(geom space.Geometry, bo ...byteOrder) []byte

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

func Unmarshal

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

Unmarshal will decode the type into a Geometry.

func Value

func Value(g space.Geometry) driver.Valuer

Value will create a driver.Valuer that will WKB the geometry into the database query.

Types

type Decoder

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

Decoder can decoder WKB geometry off of the stream.

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

NewDecoder will create a new WKB decoder.

func (*Decoder) Decode

func (d *Decoder) Decode() (space.Geometry, error)

Decode will decode the next geometry off of the stream.

type EWKBDecoder added in v1.0.1

type EWKBDecoder struct {
	Srid uint32
	// contains filtered or unexported fields
}

EWKBDecoder Decoder can decoder EWKB geometry off of the stream.

func (*EWKBDecoder) Decode added in v1.0.1

func (d *EWKBDecoder) Decode() (space.Geometry, error)

Decode returns geometry,it will decode the next geometry off of the stream.

type EWKBEncoder added in v1.0.1

type EWKBEncoder struct {
	*Encoder
	Srid uint32
}

EWKBEncoder Decoder can decoder EWKB geometry off of the stream.

func (*EWKBEncoder) Encode added in v1.0.1

func (e *EWKBEncoder) Encode(geom space.Geometry) error

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

type Encoder

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

An Encoder will encode a geometry as 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 space.Geometry) error

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

type GeometryScanner

type GeometryScanner struct {
	Geometry space.Geometry
	Valid    bool // Valid is true if the geometry is not NULL
	// contains filtered or unexported fields
}

GeometryScanner is a thing that can scan in sql query results. It can be used as a scan destination:

var s wkb.GeometryScanner
err := db.QueryRow("SELECT latlon FROM foo WHERE id=?", id).Scan(&s)
...
if s.Valid {
  // use s.Geometry
} else {
  // NULL value
}

func Scanner

func Scanner(g interface{}) *GeometryScanner

Scanner will return a GeometryScanner that can scan sql query results. The geometryScanner.Geometry attribute will be set to the value. If g is non-nil, it MUST be a pointer to an space.Geometry type like a Point or LineString. In that case the value will be written to g and the Geometry attribute.

var p space.Point
err := db.QueryRow("SELECT latlon FROM foo WHERE id=?", id).Scan(wkb.Scanner(&p))
...
// use p

If the value may be null check Valid first:

var point space.Point
s := wkb.Scanner(&point)
err := db.QueryRow("SELECT latlon FROM foo WHERE id=?", id).Scan(&s)
...
if s.Valid {
  // use p
} else {
  // NULL value
}

Scanning directly from MySQL columns is supported. By default MySQL returns geometry data as WKB but prefixed with a 4 byte SRID. To support this, if the data is not valid WKB, the code will strip the first 4 bytes and try again. This works for most use cases.

func (*GeometryScanner) Scan

func (s *GeometryScanner) Scan(d interface{}) error

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

Jump to

Keyboard shortcuts

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