Documentation ¶
Overview ¶
Package ewkb decodes Extended Well-Known Byte format.
EWKB is encoded in hexadecimal. There are 2 parts:
The header
The data
HEADER ¶
Byte 0: 0 means big endian, 1 means little endian.
Bytes 1-4:
bit 64 means with Z.
bit 63 means with M.
bit 62 means with SRID (System Reference ID).
bits 0-61 are for the type of the geometry.
If SRID bit is 1, then the 4 following bytes are the SRID (32bit unsigned integer).
After that, come the data part.
DATA ¶
- Point: depending on the format (XY, XYM or XYZM), there are 2, 3 or 4 float64 (8 bytes).
- LineString: It's an array of Point. First of all, there is a uint32 (4 bytes) for the dimension of the array. The points are read as below.
Index ¶
- Constants
- func IsEWKB(data interface{}) bool
- func Marshal(geoShape Marshaler) ([]byte, error)
- func Unmarshal(geoShape Unmarshaler, value interface{}) error
- type CircularString
- func (c CircularString) Layout() Layout
- func (c CircularString) MarshalEWBK(byteOrder binary.ByteOrder) ([]byte, error)
- func (c CircularString) SystemReferenceID() *SystemReferenceID
- func (c CircularString) Type() GeometryType
- func (c *CircularString) UnmarshalEWBK(record ExtendedWellKnownBytes) error
- type Coordinate
- type CoordinateGroup
- type CoordinateSet
- type Decoder
- type Encoder
- type Error
- type ExtendedWellKnownBytes
- type ExtendedWellKnownBytesHeader
- type Geometry
- type GeometryCollection
- func (g GeometryCollection) Layout() Layout
- func (g GeometryCollection) MarshalEWBK(byteOrder binary.ByteOrder) ([]byte, error)
- func (g GeometryCollection) SystemReferenceID() *SystemReferenceID
- func (g GeometryCollection) Type() GeometryType
- func (g *GeometryCollection) UnmarshalEWBK(record ExtendedWellKnownBytes) error
- type GeometryType
- type Layout
- type LineString
- type Marshaler
- type MultiLineString
- func (m MultiLineString) Layout() Layout
- func (m MultiLineString) MarshalEWBK(byteOrder binary.ByteOrder) ([]byte, error)
- func (m MultiLineString) SystemReferenceID() *SystemReferenceID
- func (m MultiLineString) Type() GeometryType
- func (m *MultiLineString) UnmarshalEWBK(record ExtendedWellKnownBytes) error
- type MultiPoint
- type MultiPolygon
- type Point
- type Polygon
- type SystemReferenceID
- type Triangle
- type Unmarshaler
Constants ¶
const ( // ErrWrongByteOrder occurs when byte order is not recognized. ErrWrongByteOrder = Error("wrong byte order") // ErrIncompatibleFormat occurs when geometry formats are incompatible. ErrIncompatibleFormat = Error("incompatible format") // ErrWrongGeometryType occurs when geometry type is not the expected one. ErrWrongGeometryType = Error("wrong geometry type") )
const ( // ErrCircularStringWrongSize occurs when the number of verticies is not odd or is less than 3. ErrCircularStringWrongSize = Error("circularstring has a wrong size (odd number of vertices >1)") )
const ( // ErrMissingWellKnownGeometry is when no well known geometries were specified. ErrMissingWellKnownGeometry = Error("missing well known geometries") )
const ( // ErrTriangleWrongSize occurs when a triangle has more than 1 polygon, // or the polygon hasn't 3 vertices. ErrTriangleWrongSize = Error("triangle has a wrong size") )
Variables ¶
This section is empty.
Functions ¶
func IsEWKB ¶ added in v0.0.1
func IsEWKB(data interface{}) bool
IsEWKB checks if data is potentially Extended Well Known Bytes.
func Unmarshal ¶
func Unmarshal(geoShape Unmarshaler, value interface{}) error
Unmarshal converts EWKB array of bytes to Geometry.
Types ¶
type CircularString ¶ added in v0.0.8
type CircularString struct { SRID *SystemReferenceID CoordinateSet }
CircularString is a CIRCULARSTRING in database.
CircularString is the basic curve type, similar to a LineString in the linear world. A single arc segment is specified by three points: the start and end points (first and third) and some other point on the arc. To specify a closed circle the start and end points are the same and the middle point is the opposite point on the circle diameter (which is the center of the arc). In a sequence of arcs the end point of the previous arc is the start point of the next arc, just like the segments of a LineString. This means that a CircularString must have an odd number of points greater than 1.
func (CircularString) Layout ¶ added in v0.0.8
func (c CircularString) Layout() Layout
Layout implements the Marshaler interface.
func (CircularString) MarshalEWBK ¶ added in v0.0.8
func (c CircularString) MarshalEWBK(byteOrder binary.ByteOrder) ([]byte, error)
MarshalEWBK implements the Marshaler interface.
func (CircularString) SystemReferenceID ¶ added in v0.0.8
func (c CircularString) SystemReferenceID() *SystemReferenceID
SystemReferenceID implements the Marshaler interface.
func (CircularString) Type ¶ added in v0.0.8
func (c CircularString) Type() GeometryType
Type implements the Geometry interface.
func (*CircularString) UnmarshalEWBK ¶ added in v0.0.8
func (c *CircularString) UnmarshalEWBK(record ExtendedWellKnownBytes) error
UnmarshalEWBK implements the Unmarshaler interface.
type Coordinate ¶ added in v0.0.1
Coordinate is coordinate system.
func NewNullCoordinate ¶ added in v0.0.1
func NewNullCoordinate(layout Layout) Coordinate
NewNullCoordinate creates a null coordinate system.
func (Coordinate) IsNull ¶ added in v0.0.1
func (c Coordinate) IsNull() bool
IsNull checks if coordinate is null.
func (Coordinate) Layout ¶ added in v0.0.1
func (c Coordinate) Layout() Layout
Layout implements the Marshaler interface.
func (Coordinate) MarshalEWBK ¶ added in v0.0.1
func (c Coordinate) MarshalEWBK(byteOrder binary.ByteOrder) ([]byte, error)
MarshalEWBK implements the Marshaler interface.
func (*Coordinate) UnmarshalEWBK ¶ added in v0.0.1
func (c *Coordinate) UnmarshalEWBK(record ExtendedWellKnownBytes) error
UnmarshalEWBK implements the Unmarshaler interface.
type CoordinateGroup ¶ added in v0.0.1
type CoordinateGroup []CoordinateSet
CoordinateGroup is a group of set of coordinates.
func (CoordinateGroup) MarshalEWBK ¶ added in v0.0.1
func (c CoordinateGroup) MarshalEWBK(byteOrder binary.ByteOrder) ([]byte, error)
MarshalEWBK implements the Marshaler interface.
func (*CoordinateGroup) UnmarshalEWBK ¶ added in v0.0.1
func (c *CoordinateGroup) UnmarshalEWBK(record ExtendedWellKnownBytes) error
UnmarshalEWBK implements the Unmarshaler interface.
type CoordinateSet ¶ added in v0.0.1
type CoordinateSet []Coordinate
CoordinateSet is a set of coordinates.
func (CoordinateSet) MarshalEWBK ¶ added in v0.0.1
func (c CoordinateSet) MarshalEWBK(byteOrder binary.ByteOrder) ([]byte, error)
MarshalEWBK implements the Marshaler interface.
func (*CoordinateSet) UnmarshalEWBK ¶ added in v0.0.1
func (c *CoordinateSet) UnmarshalEWBK(record ExtendedWellKnownBytes) error
UnmarshalEWBK implements the Unmarshaler interface.
type Decoder ¶ added in v0.0.1
type Decoder struct {
// contains filtered or unexported fields
}
Decoder is a Extended Well Known Byte decoder.
func NewDecoder ¶ added in v0.0.1
NewDecoder creates a EWKB decoder.
func (*Decoder) Decode ¶ added in v0.0.1
func (d *Decoder) Decode(geoShape Unmarshaler) error
Decode decodes to a Geometry.
type Encoder ¶ added in v0.0.1
type Encoder struct {
// contains filtered or unexported fields
}
Encoder is a Extended Well Known Byte encoder.
func NewEncoder ¶ added in v0.0.1
NewEncoder creates a EWKB encoder.
type ExtendedWellKnownBytes ¶
type ExtendedWellKnownBytes struct { ExtendedWellKnownBytesHeader DataStream io.Reader IsNil bool }
ExtendedWellKnownBytes is the EWKB.
func DecodeHeader ¶
func DecodeHeader(reader io.Reader) (*ExtendedWellKnownBytes, error)
DecodeHeader decodes EWKB header.
func (ExtendedWellKnownBytes) ReadFloat64 ¶
func (e ExtendedWellKnownBytes) ReadFloat64() (float64, error)
ReadFloat64 reads 64-bit float from the stream.
func (ExtendedWellKnownBytes) ReadUint32 ¶
func (e ExtendedWellKnownBytes) ReadUint32() (uint32, error)
ReadUint32 reads 32-bit unsigned integer from the stream.
type ExtendedWellKnownBytesHeader ¶
type ExtendedWellKnownBytesHeader struct { SRID *SystemReferenceID ByteOrder binary.ByteOrder Type GeometryType Layout Layout }
ExtendedWellKnownBytesHeader is the header from EWKB data.
type Geometry ¶
type Geometry interface { Unmarshaler Marshaler }
Geometry is a geometrical shape.
func DefaultWellKnownGeometry ¶ added in v1.1.0
func DefaultWellKnownGeometry() []Geometry
DefaultWellKnownGeometry is the default well known geometry set.
type GeometryCollection ¶ added in v1.1.0
type GeometryCollection struct { SRID *SystemReferenceID Collection []Geometry // contains filtered or unexported fields }
GeometryCollection is a heterogeneous (mixed) collection of geometries.
func NewGeometryCollection ¶ added in v1.1.0
func NewGeometryCollection(wellknownGeometry ...Geometry) *GeometryCollection
NewGeometryCollection creates a new empty collection of geometries.
func (GeometryCollection) Layout ¶ added in v1.1.0
func (g GeometryCollection) Layout() Layout
Layout implements the Marshaler interface.
func (GeometryCollection) MarshalEWBK ¶ added in v1.1.0
func (g GeometryCollection) MarshalEWBK(byteOrder binary.ByteOrder) ([]byte, error)
MarshalEWBK implements the Marshaler interface.
func (GeometryCollection) SystemReferenceID ¶ added in v1.1.0
func (g GeometryCollection) SystemReferenceID() *SystemReferenceID
SystemReferenceID implements the Marshaler interface.
func (GeometryCollection) Type ¶ added in v1.1.0
func (g GeometryCollection) Type() GeometryType
Type implements the Geometry interface.
func (*GeometryCollection) UnmarshalEWBK ¶ added in v1.1.0
func (g *GeometryCollection) UnmarshalEWBK(record ExtendedWellKnownBytes) error
UnmarshalEWBK implements the Unmarshaler interface.
type GeometryType ¶
type GeometryType uint8
GeometryType is the type of the geometry (bits 0-61 of the bytes 1-4 of the header).
const ( // GeometryTypePoint stands for point. GeometryTypePoint GeometryType = 1 // GeometryTypeLineString stands for lineString. GeometryTypeLineString GeometryType = 2 // GeometryTypePolygon stands for polygon. GeometryTypePolygon GeometryType = 3 // GeometryTypeMultiPoint stands for multiPoint. GeometryTypeMultiPoint GeometryType = 4 // GeometryTypeMultiLineString stands for multiLineString. GeometryTypeMultiLineString GeometryType = 5 // GeometryTypeMultiPolygon stands for multiPolygon. GeometryTypeMultiPolygon GeometryType = 6 // GeometryTypeGeometryCollection stands for geometryCollection. GeometryTypeGeometryCollection GeometryType = 7 // GeometryTypeCircularString stands for a curved string. GeometryTypeCircularString GeometryType = 8 // GeometryTypeCompound stands for compound. GeometryTypeCompound GeometryType = 9 // GeometryTypeCurvePoly stands for curvepoly. GeometryTypeCurvePoly GeometryType = 10 // GeometryTypeMultiCurve stands for multicurve. GeometryTypeMultiCurve GeometryType = 11 // GeometryTypeMultiSurface stands for multisurface. GeometryTypeMultiSurface GeometryType = 12 // GeometryTypePolyhedralSurface stands for polyhedralSurface. GeometryTypePolyhedralSurface GeometryType = 13 // GeometryTypeTin stands for tin. GeometryTypeTin GeometryType = 15 // GeometryTypeTriangle stands for triangle. GeometryTypeTriangle GeometryType = 17 )
type LineString ¶ added in v0.0.5
type LineString struct { SRID *SystemReferenceID CoordinateSet }
LineString is a set of lines.
A LineString is a 1-dimensional line formed by a contiguous sequence of line segments. Each line segment is defined by two points, with the end point of one segment forming the start point of the next segment. An OGC-valid LineString has either zero or two or more points, but PostGIS also allows single-point LineStrings. LineStrings may cross themselves (self-intersect). A LineString is closed if the start and end points are the same. A LineString is simple if it does not self-intersect.
func (LineString) Layout ¶ added in v0.0.5
func (l LineString) Layout() Layout
Layout implements the Marshaler interface.
func (LineString) MarshalEWBK ¶ added in v0.0.5
func (l LineString) MarshalEWBK(byteOrder binary.ByteOrder) ([]byte, error)
MarshalEWBK implements the Marshaler interface.
func (LineString) SystemReferenceID ¶ added in v0.0.5
func (l LineString) SystemReferenceID() *SystemReferenceID
SystemReferenceID implements the Marshaler interface.
func (LineString) Type ¶ added in v0.0.5
func (l LineString) Type() GeometryType
Type implements the Geometry interface.
func (*LineString) UnmarshalEWBK ¶ added in v0.0.5
func (l *LineString) UnmarshalEWBK(record ExtendedWellKnownBytes) error
UnmarshalEWBK implements the Unmarshaler interface.
type Marshaler ¶
type Marshaler interface { // MarshalEWBK must only generate the data part of the EWKB (not the header part). MarshalEWBK(binary.ByteOrder) ([]byte, error) // SystemReferenceID is the optional SRID. SystemReferenceID() *SystemReferenceID // Layout is the Layout used by the geometry. Layout() Layout // Type is the type of geometry. Type() GeometryType }
Marshaler is the Geometry to byte array converter.
type MultiLineString ¶ added in v0.0.5
type MultiLineString struct { SRID *SystemReferenceID LineStrings []LineString }
MultiLineString is a MULTILINESTRING in database.
A MultiLineString is a collection of LineStrings. A MultiLineString is closed if each of its elements is closed.
func (MultiLineString) Layout ¶ added in v0.0.5
func (m MultiLineString) Layout() Layout
Layout implements the Marshaler interface.
func (MultiLineString) MarshalEWBK ¶ added in v0.0.5
func (m MultiLineString) MarshalEWBK(byteOrder binary.ByteOrder) ([]byte, error)
MarshalEWBK implements the Marshaler interface.
func (MultiLineString) SystemReferenceID ¶ added in v0.0.5
func (m MultiLineString) SystemReferenceID() *SystemReferenceID
SystemReferenceID implements the Marshaler interface.
func (MultiLineString) Type ¶ added in v0.0.5
func (m MultiLineString) Type() GeometryType
Type implements the Geometry interface.
func (*MultiLineString) UnmarshalEWBK ¶ added in v0.0.5
func (m *MultiLineString) UnmarshalEWBK(record ExtendedWellKnownBytes) error
UnmarshalEWBK implements the Unmarshaler interface.
type MultiPoint ¶ added in v0.0.2
type MultiPoint struct { SRID *SystemReferenceID Points []Point }
MultiPoint is a MULTIPOINT in database.
A MultiPoint is a collection of Points.
func (MultiPoint) Layout ¶ added in v0.0.2
func (m MultiPoint) Layout() Layout
Layout implements the Marshaler interface.
func (MultiPoint) MarshalEWBK ¶ added in v0.0.2
func (m MultiPoint) MarshalEWBK(byteOrder binary.ByteOrder) ([]byte, error)
MarshalEWBK implements the Marshaler interface.
func (MultiPoint) SystemReferenceID ¶ added in v0.0.2
func (m MultiPoint) SystemReferenceID() *SystemReferenceID
SystemReferenceID implements the Marshaler interface.
func (MultiPoint) Type ¶ added in v0.0.2
func (m MultiPoint) Type() GeometryType
Type implements the Geometry interface.
func (*MultiPoint) UnmarshalEWBK ¶ added in v0.0.2
func (m *MultiPoint) UnmarshalEWBK(record ExtendedWellKnownBytes) error
UnmarshalEWBK implements the Unmarshaler interface.
type MultiPolygon ¶ added in v0.0.6
type MultiPolygon struct { SRID *SystemReferenceID Polygons []Polygon }
MultiPolygon is a MULTILINESTRING in database.
A MultiPolygon is a collection of non-overlapping, non-adjacent Polygons. Polygons in the collection may touch only at a finite number of points.
func (MultiPolygon) Layout ¶ added in v0.0.6
func (m MultiPolygon) Layout() Layout
Layout implements the Marshaler interface.
func (MultiPolygon) MarshalEWBK ¶ added in v0.0.6
func (m MultiPolygon) MarshalEWBK(byteOrder binary.ByteOrder) ([]byte, error)
MarshalEWBK implements the Marshaler interface.
func (MultiPolygon) SystemReferenceID ¶ added in v0.0.6
func (m MultiPolygon) SystemReferenceID() *SystemReferenceID
SystemReferenceID implements the Marshaler interface.
func (MultiPolygon) Type ¶ added in v0.0.6
func (m MultiPolygon) Type() GeometryType
Type implements the Geometry interface.
func (*MultiPolygon) UnmarshalEWBK ¶ added in v0.0.6
func (m *MultiPolygon) UnmarshalEWBK(record ExtendedWellKnownBytes) error
UnmarshalEWBK implements the Unmarshaler interface.
type Point ¶
type Point struct { SRID *SystemReferenceID Coordinate }
Point is a POINT in database.
A Point is a 0-dimensional geometry that represents a single location in coordinate space.
func (Point) MarshalEWBK ¶
MarshalEWBK implements the Marshaler interface.
func (Point) SystemReferenceID ¶ added in v0.0.1
func (p Point) SystemReferenceID() *SystemReferenceID
SystemReferenceID implements the Marshaler interface.
func (*Point) UnmarshalEWBK ¶
func (p *Point) UnmarshalEWBK(record ExtendedWellKnownBytes) error
UnmarshalEWBK implements the Unmarshaler interface.
type Polygon ¶ added in v0.0.1
type Polygon struct { SRID *SystemReferenceID CoordinateGroup }
Polygon is a POLYGON in database.
A Polygon is a 2-dimensional planar region, delimited by an exterior boundary (the shell) and zero or more interior boundaries (holes). Each boundary is a LinearRing.
func (Polygon) MarshalEWBK ¶ added in v0.0.1
MarshalEWBK implements the Marshaler interface.
func (Polygon) SystemReferenceID ¶ added in v0.0.1
func (p Polygon) SystemReferenceID() *SystemReferenceID
SystemReferenceID implements the Marshaler interface.
func (Polygon) Type ¶ added in v0.0.1
func (p Polygon) Type() GeometryType
Type implements the Geometry interface.
func (*Polygon) UnmarshalEWBK ¶ added in v0.0.1
func (p *Polygon) UnmarshalEWBK(record ExtendedWellKnownBytes) error
UnmarshalEWBK implements the Unmarshaler interface.
type SystemReferenceID ¶
type SystemReferenceID uint32
SystemReferenceID is the identifier of the system reference for projection.
const ( // SystemReferenceWGS84 stands for GCS WGS 84. SystemReferenceWGS84 SystemReferenceID = 4326 // SystemReferenceUTMZone stands for UTM Zone 17N NAD 27. SystemReferenceUTMZone SystemReferenceID = 26717 // SystemReferenceTennesseeZone stands for SPCS Tennessee Zone NAD 83. SystemReferenceTennesseeZone SystemReferenceID = 6576 )
func WithSRID ¶
func WithSRID(srid SystemReferenceID) *SystemReferenceID
WithSRID converts SystemReferenceID to pointer.
type Triangle ¶ added in v0.0.7
type Triangle struct { SRID *SystemReferenceID CoordinateSet }
Triangle is a TRIANGLE in database.
func (Triangle) MarshalEWBK ¶ added in v0.0.7
MarshalEWBK implements the Marshaler interface.
func (Triangle) SystemReferenceID ¶ added in v0.0.7
func (t Triangle) SystemReferenceID() *SystemReferenceID
SystemReferenceID implements the Marshaler interface.
func (Triangle) Type ¶ added in v0.0.7
func (t Triangle) Type() GeometryType
Type implements the Geometry interface.
func (*Triangle) UnmarshalEWBK ¶ added in v0.0.7
func (t *Triangle) UnmarshalEWBK(record ExtendedWellKnownBytes) error
UnmarshalEWBK implements the Unmarshaler interface.
type Unmarshaler ¶
type Unmarshaler interface { // UnmarshalEWBK is to extract Geometry information from the EWKB record. UnmarshalEWBK(ExtendedWellKnownBytes) error }
Unmarshaler is the byte array to Geometry converter.