Git Product home page Git Product logo

go-bbox's Introduction

go-bbox

Build Status Coverage Status Go Report Card GoDoc

This package is an implementation of a geospatial bounding box algorithm located here.

go get -u github.com/umpc/go-bbox
  • Earth's equatorial radius of 6,378,137 meters is used for compatibility with online mapping services such as:
    • Google Maps
    • Bing Maps
    • Mapbox
  • Bounds that cross the antimeridian are represented using two bounding boxes.
  • Bounds that cross the poles are represented using a single bounding box that has:
    • a min longitude of -180 degrees
    • a max longitude of 180 degrees

Example usage

package main

import (
  "fmt"

  "github.com/umpc/go-bbox"
)

func main() {
  // Finds the min/max points for a rectangular area, which will be 276.49km
  // southwest and northeast of the center point.
  bboxes := bbox.New(276.494742, bbox.Point{
    Latitude:  -14.2436432,
    Longitude: -178.1795257,
  })
  for _, bbox := range bboxes {
    fmt.Printf("%+v\n", bbox)
  }
}

Example output

{Min:{Latitude:-16.727437727172838 Longitude:179.2578499517392} Max:{Latitude:-11.759848672827163 Longitude:180}}
{Min:{Latitude:-16.727437727172838 Longitude:-180} Max:{Latitude:-11.759848672827163 Longitude:-175.61690135173924}}

This example shows how bounds that cross the antimeridian are represented.

Benchmark results

$ go test -bench=.
goos: linux
goarch: amd64
pkg: github.com/umpc/go-bbox
BenchmarkNewEmpty-8             10000000               181 ns/op
BenchmarkNYC-8                   5000000               263 ns/op
BenchmarkLondon-8                5000000               267 ns/op
BenchmarkMontevideo-8            5000000               268 ns/op
BenchmarkToloke-8                5000000               320 ns/op
BenchmarkSuva-8                  5000000               322 ns/op
BenchmarkNorthPole-8            10000000               200 ns/op
BenchmarkSouthPole-8            10000000               202 ns/op
PASS
ok      github.com/umpc/go-bbox 15.109s
  • CPU: Intel Core i7-4790k
  • Memory: DDR3-1600
  • Go: 1.10.2

References:

  • Bronshtein, Semendyayev, Musiol, Mühlig: Handbook of Mathematics. Springer, Berlin. ISBN-13: 978-3817120079.

go-bbox's People

Contributors

umpc avatar

Watchers

 avatar  avatar  avatar

Forkers

cih-y2k

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.