geo

package module
v2.1.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2018 License: MIT Imports: 5 Imported by: 0

README

geo

GoDoc

Customized types and functions for our geo needs.

NOTE: If you want a full-fledged geo library we recommend using https://github.com/twpayne/go-geom instead.

Install
go get github.com/altipla-consulting/geo

This library has no external dependencies outside the Go standard library.

Usage

You can use the types of this package in your models structs when working with database/sql:

type MyModel struct {
  ID          int64      `db:"id,pk"`
  Location        geo.Point `db:"location"`
}
Contributing

You can make pull requests or create issues in GitHub. Any code you send should be formatted using gofmt.

Running tests

Start the test database:

docker-compose up -d database

Install test libs:

go get github.com/stretchr/testify

Run the tests:

go test

Shutdown the database when finished testing:

docker-compose stop database
License

MIT License

Documentation

Overview

Package geo implements customized types and functions for our geo needs.

If you want a full-fledged geo library we recommend using https://github.com/twpayne/go-geom instead.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DistanceToPoint

func DistanceToPoint(column string, point Point) database.Sorter

DistanceToPoint orders by distance to a geographic point.

Types

type NearCondition added in v1.2.0

type NearCondition struct {
	// contains filtered or unexported fields
}

NearCondition stores the point and distance to filter around

func Near added in v1.2.0

func Near(column string, point Point, value float64) *NearCondition

Near filters by distance around a geographic point

func (*NearCondition) SQL added in v1.2.0

func (cond *NearCondition) SQL() string

SQL returns the built SQL to apply the filter.

func (*NearCondition) Values added in v1.2.0

func (cond *NearCondition) Values() []interface{}

Values returns the SQL placeholders to apply the filter

type Point

type Point struct {
	Lng float64
	Lat float64
}

Point maps against MySQL geographical point.

func (*Point) Scan

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

Scan implements the SQL driver.Scanner interface and will scan the MySQL POINT(x y) into the Point struct.

func (Point) String

func (p Point) String() string

String returns the WKT (Well Known Text) representation of the point.

func (Point) Valid added in v1.1.0

func (p Point) Valid() bool

Valid returns whether a GeoPoint is within [-90, 90] latitude and [-180, 180] longitude.

func (Point) Value

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

Value implements the SQL driver.Valuer interface and will return the string representation of the Point struct by calling the String() method

Jump to

Keyboard shortcuts

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