ewkb

package
v0.0.0-...-1491eae Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2018 License: BSD-2-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package ewkb 实现了 扩展的著名二进制编码和解码。 See https://github.com/postgis/postgis/blob/2.1.0/doc/ZMSgeoms.txt.

如果你正在将几何图形编码成 EWKB ,并存进 PostgreSQL/PostGIS。你必须设置 binary_parameters=yes,在 你向 sql.Open传递的数据资源中

Example (Scan)
type City struct {
	Name     string
	Location ewkb.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", geomtest.MustHexDecode("0101000020e610000052b81e85eb51c03f45f0bf95ecc04940")),
	)

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 ewkb.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", geomtest.MustHexDecode("0101000020e610000052b81e85eb51c03f45f0bf95ecc04940")).
	WillReturnResult(sqlmock.NewResult(1, 1))

c := City{
	Name:     "London",
	Location: ewkb.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函数 向 a []byte中编码任意几何类型.

func Read

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

Read函数 从 r 中读取任意几何图形.

func Unmarshal

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

Unmarshal函数 从data []byte中解码任意图形.

func Write

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

Write函数 向 w写入任意的几何图形.

Types

type ErrExpectedByteSlice

type ErrExpectedByteSlice struct {
	Value interface{}
}

ErrExpectedByteSlice 将被返回,当 []byte 是正确的.

func (ErrExpectedByteSlice) Error

func (e ErrExpectedByteSlice) Error() string

type GeometryCollection

type GeometryCollection struct {
	*geom.GeometryCollection
}

A GeometryCollection 是 WEKB 编码的几何图形集合,它实现了sql.Scanner 和 driver.Value 接口

func (*GeometryCollection) Scan

func (gc *GeometryCollection) Scan(src interface{}) error

Scan scans from a []byte.

func (*GeometryCollection) Valid

func (gc *GeometryCollection) Valid() bool

Valid returns true if gc has a value.

func (*GeometryCollection) Value

func (gc *GeometryCollection) Value() (driver.Value, error)

Value returns the EWKB encoding of gc.

type LineString

type LineString struct {
	*geom.LineString
}

A LineString 是 EWKB编码的单线,它实现了sql.Scanner 和 driver.Value 接口

func (*LineString) Scan

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

Scan scans from a []byte.

func (*LineString) Valid

func (ls *LineString) Valid() bool

Valid return true if ls has a value.

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 是 WEKB 编码的多线集合,它实现了sql.Scanner 和 driver.Value 接口

func (*MultiLineString) Scan

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

Scan scans from a []byte.

func (*MultiLineString) Valid

func (mls *MultiLineString) Valid() bool

Valid returns true if mls has a value.

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 是 EWKB编码的多点集合,它实现了sql.Scanner 和 driver.Value 接口

func (*MultiPoint) Scan

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

Scan scans from a []byte.

func (*MultiPoint) Valid

func (mp *MultiPoint) Valid() bool

Valid returns true if mp has a value.

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 是 WEKB 编码的多边行集合对象,它实现了sql.Scanner 和 driver.Value 接口

func (*MultiPolygon) Scan

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

Scan scans from a []byte.

func (*MultiPolygon) Valid

func (mp *MultiPolygon) Valid() bool

Valid returns true if mp has a value.

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 是 EWKB编码的 点,它实现了sql.Scanner 和 driver.Value 接口

func (*Point) Scan

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

Scan方法 从 a []byte中扫描(遍历).

func (*Point) Valid

func (p *Point) Valid() bool

Valid方法 返回true,如果 p 有值

func (*Point) Value

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

Value方法 返回 p 对象的 EWKB编码.

type Polygon

type Polygon struct {
	*geom.Polygon
}

A Polygon 是 EWKB编码的多边形对象,它实现了sql.Scanner 和 driver.Value 接口

func (*Polygon) Scan

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

Scan scans from a []byte.

func (*Polygon) Valid

func (p *Polygon) Valid() bool

Valid returns true if p has a value.

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