polyline

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2018 License: BSD-2-Clause Imports: 2 Imported by: 43

README

polyline

Build Status GoDoc Report Card

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

Encoding example:

func ExampleEncodeCoords() {
	var 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`@
}

Decoding example:

func ExampleDecodeCoords() {
	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]]
}

License

Documentation

Overview

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeCoord

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

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

func DecodeCoords

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

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

Example
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

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

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

func EncodeCoord(coord []float64) []byte

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

func EncodeCoords

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

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

Example
var 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

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

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

func EncodeUint

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

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

Types

type Codec

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

A Codec represents an encoder.

func (Codec) DecodeCoord

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

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

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

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

EncodeCoord encodes a single coordinate to buf.

func (Codec) EncodeCoords

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

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

func (Codec) EncodeFlatCoords

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

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

Jump to

Keyboard shortcuts

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