ewkb

package
v0.0.0-...-0627f11 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2017 License: BSD-2-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package ewkb implements Extended Well Known Binary encoding and decoding. See https://github.com/postgis/postgis/blob/2.1.0/doc/ZMSgeoms.txt.

Example (Scan)
type City struct {
	Name     string
	Location Point
}

db, mock, err := sqlmock.New()
if err != nil {
	log.Fatal(err)
}
defer db.Close()

mock.ExpectQuery(`SELECT name, ST_AsEWKB\(location\) FROM cities WHERE name = \?;`).
	WithArgs("London").
	WillReturnRows(
		sqlmock.NewRows([]string{"name", "location"}).
			AddRow("London", []byte("\x01\x01\x00\x00\x20\xe6\x10\x00\x00\x52\xb8\x1e\x85\xeb\x51\xc0\x3f\x45\xf0\xbf\x95\xec\xc0\x49\x40")),
	)

var c City
if err := db.QueryRow(`SELECT name, ST_AsEWKB(location) FROM cities WHERE name = ?;`, "London").Scan(&c.Name, &c.Location); err != nil {
	log.Fatal(err)
}

fmt.Printf("Longitude: %v\n", c.Location.X())
fmt.Printf("Latitude: %v\n", c.Location.Y())
fmt.Printf("SRID: %v\n", c.Location.SRID())
Output:

Longitude: 0.1275
Latitude: 51.50722
SRID: 4326
Example (Value)
type City struct {
	Name     string
	Location Point
}

db, mock, err := sqlmock.New()
if err != nil {
	log.Fatal(err)
}
defer db.Close()

mock.ExpectExec(`INSERT INTO cities \(name, location\) VALUES \(\?, \?\);`).
	WithArgs("London", []byte("\x01\x01\x00\x00\x20\xe6\x10\x00\x00\x52\xb8\x1e\x85\xeb\x51\xc0\x3f\x45\xf0\xbf\x95\xec\xc0\x49\x40")).
	WillReturnResult(sqlmock.NewResult(1, 1))

c := City{
	Name:     "London",
	Location: Point{geom.NewPoint(geom.XY).MustSetCoords(geom.Coord{0.1275, 51.50722}).SetSRID(4326)},
}

result, err := db.Exec(`INSERT INTO cities (name, location) VALUES (?, ?);`, c.Name, &c.Location)
if err != nil {
	log.Fatal(err)
}
rowsAffected, _ := result.RowsAffected()
fmt.Printf("%d rows affected", rowsAffected)
Output:

1 rows affected

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// XDR is big endian.
	XDR = wkbcommon.XDR
	// NDR is little endian.
	NDR = wkbcommon.NDR
)

Functions

func Marshal

func Marshal(g geom.T, byteOrder binary.ByteOrder) ([]byte, error)

Marshal marshals an arbitrary geometry to a []byte.

func Read

func Read(r io.Reader) (geom.T, error)

Read reads an arbitrary geometry from r.

func Unmarshal

func Unmarshal(data []byte) (geom.T, error)

Unmarshal unmrshals an arbitrary geometry from a []byte.

func Write

func Write(w io.Writer, byteOrder binary.ByteOrder, g geom.T) error

Write writes an arbitrary geometry to w.

Types

type ErrExpectedByteSlice

type ErrExpectedByteSlice struct {
	Value interface{}
}

ErrExpectedByteSlice is returned when a []byte is expected.

func (ErrExpectedByteSlice) Error

func (e ErrExpectedByteSlice) Error() string

type LineString

type LineString struct {
	*geom.LineString
}

A LineString is a EWKB-encoded LineString that implements the sql.Scanner and driver.Value interfaces.

func (*LineString) Scan

func (ls *LineString) Scan(src interface{}) error

Scan scans from a []byte.

func (*LineString) Value

func (ls *LineString) Value() (driver.Value, error)

Value returns the EWKB encoding of ls.

type MultiLineString

type MultiLineString struct {
	*geom.MultiLineString
}

A MultiLineString is a EWKB-encoded MultiLineString that implements the sql.Scanner and driver.Value interfaces.

func (*MultiLineString) Scan

func (mls *MultiLineString) Scan(src interface{}) error

Scan scans from a []byte.

func (*MultiLineString) Value

func (mls *MultiLineString) Value() (driver.Value, error)

Value returns the EWKB encoding of mls.

type MultiPoint

type MultiPoint struct {
	*geom.MultiPoint
}

A MultiPoint is a EWKB-encoded MultiPoint that implements the sql.Scanner and driver.Value interfaces.

func (*MultiPoint) Scan

func (mp *MultiPoint) Scan(src interface{}) error

Scan scans from a []byte.

func (*MultiPoint) Value

func (mp *MultiPoint) Value() (driver.Value, error)

Value returns the EWKB encoding of mp.

type MultiPolygon

type MultiPolygon struct {
	*geom.MultiPolygon
}

A MultiPolygon is a EWKB-encoded MultiPolygon that implements the sql.Scanner and driver.Value interfaces.

func (*MultiPolygon) Scan

func (mp *MultiPolygon) Scan(src interface{}) error

Scan scans from a []byte.

func (*MultiPolygon) Value

func (mp *MultiPolygon) Value() (driver.Value, error)

Value returns the EWKB encoding of mp.

type Point

type Point struct {
	*geom.Point
}

A Point is a EWKB-encoded Point that implements the sql.Scanner and driver.Value interfaces.

func (*Point) Scan

func (p *Point) Scan(src interface{}) error

Scan scans from a []byte.

func (*Point) Value

func (p *Point) Value() (driver.Value, error)

Value returns the EWKB encoding of p.

type Polygon

type Polygon struct {
	*geom.Polygon
}

A Polygon is a EWKB-encoded Polygon that implements the sql.Scanner and driver.Value interfaces.

func (*Polygon) Scan

func (p *Polygon) Scan(src interface{}) error

Scan scans from a []byte.

func (*Polygon) Value

func (p *Polygon) Value() (driver.Value, error)

Value returns the EWKB encoding of p.

Jump to

Keyboard shortcuts

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