tidwall 6257ddba78 Faster point in polygon / GeoJSON updates
The big change is that the GeoJSON package has been completely
rewritten to fix a few of geometry calculation bugs, increase
performance, and to better follow the GeoJSON spec RFC 7946.

GeoJSON updates

- A LineString now requires at least two points.
- All json members, even foreign, now persist with the object.
- The bbox member persists too but is no longer used for geometry
  calculations. This is change in behavior. Previously Tile38 would
  treat the bbox as the object's physical rectangle.
- Corrections to geometry intersects and within calculations.

Faster spatial queries

- The performance of Point-in-polygon and object intersect operations
  are greatly improved for complex polygons and line strings. It went
  from O(n) to roughly O(log n).
- The same for all collection types with many children, including
  FeatureCollection, GeometryCollection, MultiPoint, MultiLineString,
  and MultiPolygon.

Codebase changes

- The pkg directory has been renamed to internal
- The GeoJSON internal package has been moved to a seperate repo at
  https://github.com/tidwall/geojson. It's now vendored.

Please look out for higher memory usage for datasets using complex
shapes. A complex shape is one that has 64 or more points. For these
shapes it's expected that there will be increase of least 54 bytes per
point.
2018-10-13 04:30:48 -07:00

73 lines
1.6 KiB
Go

package geohash_test
import (
"fmt"
"github.com/mmcloughlin/geohash"
)
func Example() {
// Uluru in Australian Outback
lat, lng := -25.345457, 131.036192
// Encode a full 12 character string geohash
fmt.Println(geohash.Encode(lat, lng))
// Or at lower precision
fmt.Println(geohash.EncodeWithPrecision(lat, lng, 6))
// As an integer
fmt.Printf("%016x\n", geohash.EncodeInt(lat, lng))
// Decode to a point
fmt.Println(geohash.Decode("qgmpvf18"))
// or to a bounding box
fmt.Println(geohash.BoundingBox("qgmpvf18"))
// Output:
// qgmpvf18h86e
// qgmpvf
// b3e75db828820cd5
// -25.3454 131.036
// {-25.345458984375 -25.345287322998047 131.03599548339844 131.03633880615234}
}
func ExampleEncode() {
fmt.Println(geohash.Encode(48.858, 2.294))
// Output: u09tunq6qp66
}
func ExampleEncodeInt() {
fmt.Printf("%016x\n", geohash.EncodeInt(48.858, 2.294))
// Output: d0139d52c6b54c69
}
func ExampleEncodeIntWithPrecision() {
fmt.Printf("%08x\n", geohash.EncodeIntWithPrecision(48.858, 2.294, 32))
// Output: d0139d52
}
func ExampleEncodeWithPrecision() {
fmt.Println(geohash.EncodeWithPrecision(48.858, 2.294, 5))
// Output: u09tu
}
func ExampleDecode() {
lat, lng := geohash.Decode("u09tunq6")
fmt.Printf("%.3f %.3f\n", lat, lng)
// Output: 48.858 2.294
}
func ExampleDecodeInt() {
lat, lng := geohash.DecodeInt(0xd0139d52c6b54c69)
fmt.Printf("%.3f %.3f\n", lat, lng)
// Output: 48.858 2.294
}
func ExampleDecodeIntWithPrecision() {
lat, lng := geohash.DecodeIntWithPrecision(0xd013, uint(16))
fmt.Printf("%.3f %.3f\n", lat, lng)
// Output: 48.600 2.000
}