go-polyline: github.com/twpayne/go-polyline Index | Examples | Files

package polyline

import "github.com/twpayne/go-polyline"

Package polyline implements a Google Maps Encoding Polyline encoder and decoder.

See https://developers.google.com/maps/documentation/utilities/polylinealgorithm

The default codec encodes and decodes two-dimensional coordinates scaled by 1e5. For other dimensionalities and scales create a custom Codec.

Index

Examples

Package Files

polyline.go

func DecodeCoord Uses

func DecodeCoord(buf []byte) ([]float64, []byte, error)

DecodeCoord decodes a single coordinate from buf using the default codec.

func DecodeCoords Uses

func DecodeCoords(buf []byte) ([][]float64, []byte, error)

DecodeCoords decodes an array of coordinates from buf using the default codec.

Code:

buf := []byte("_p~iF~ps|U_ulLnnqC_mqNvxq`@")
coords, _, _ := DecodeCoords(buf)
fmt.Printf("%v\n", coords)

Output:

[[38.5 -120.2] [40.7 -120.95] [43.252 -126.453]]

func DecodeInt Uses

func DecodeInt(buf []byte) (int, []byte, error)

DecodeInt decodes a single signed integer from buf. It returns the decoded int, the remaining unconsumed bytes of buf, and any error.

func DecodeUint Uses

func DecodeUint(buf []byte) (uint, []byte, error)

DecodeUint decodes a single unsigned integer from buf. It returns the decoded uint, the remaining unconsumed bytes of buf, and any error.

func EncodeCoord Uses

func EncodeCoord(coord []float64) []byte

EncodeCoord returns the encoding of an array of coordinates using the default codec.

func EncodeCoords Uses

func EncodeCoords(coords [][]float64) []byte

EncodeCoords returns the encoding of an array of coordinates using the default codec.

Code:

coords := [][]float64{
    {38.5, -120.2},
    {40.7, -120.95},
    {43.252, -126.453},
}
fmt.Printf("%s\n", EncodeCoords(coords))

Output:

_p~iF~ps|U_ulLnnqC_mqNvxq`@

func EncodeInt Uses

func EncodeInt(buf []byte, i int) []byte

EncodeInt appends the encoding of a single signed integer i to buf.

func EncodeUint Uses

func EncodeUint(buf []byte, u uint) []byte

EncodeUint appends the encoding of a single unsigned integer u to buf.

type Codec Uses

type Codec struct {
    Dim   int     // Dimensionality, normally 2
    Scale float64 // Scale, normally 1e5
}

A Codec represents an encoder.

func (Codec) DecodeCoord Uses

func (c Codec) DecodeCoord(buf []byte) ([]float64, []byte, error)

DecodeCoord decodes a single coordinate from buf. It returns the coordinate, the remaining unconsumed bytes of buf, and any error.

func (Codec) DecodeCoords Uses

func (c Codec) DecodeCoords(buf []byte) ([][]float64, []byte, error)

DecodeCoords decodes an array of coordinates from buf. It returns the coordinates, the remaining unconsumed bytes of buf, and any error.

func (Codec) DecodeFlatCoords Uses

func (c Codec) DecodeFlatCoords(fcs []float64, buf []byte) ([]float64, []byte, error)

DecodeFlatCoords decodes coordinates from buf, appending them to a one-dimensional array. It returns the coordinates, the remaining unconsumed bytes in buf, and any error.

func (Codec) EncodeCoord Uses

func (c Codec) EncodeCoord(buf []byte, coord []float64) []byte

EncodeCoord encodes a single coordinate to buf.

func (Codec) EncodeCoords Uses

func (c Codec) EncodeCoords(buf []byte, coords [][]float64) []byte

EncodeCoords appends the encoding of an array of coordinates coords to buf.

func (Codec) EncodeFlatCoords Uses

func (c Codec) EncodeFlatCoords(buf []byte, fcs []float64) ([]byte, error)

EncodeFlatCoords encodes a one-dimensional array of coordinates to buf.

Package polyline imports 2 packages (graph) and is imported by 1 packages. Updated 2019-09-30. Refresh now. Tools for package owners.