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

90 lines
2.0 KiB
Go

package geojson
import "github.com/tidwall/geojson/geometry"
// Spatial ...
type Spatial interface {
WithinRect(rect geometry.Rect) bool
WithinPoint(point geometry.Point) bool
WithinLine(line *geometry.Line) bool
WithinPoly(poly *geometry.Poly) bool
IntersectsRect(rect geometry.Rect) bool
IntersectsPoint(point geometry.Point) bool
IntersectsLine(line *geometry.Line) bool
IntersectsPoly(poly *geometry.Poly) bool
DistanceRect(rect geometry.Rect) float64
DistancePoint(point geometry.Point) float64
DistanceLine(line *geometry.Line) float64
DistancePoly(poly *geometry.Poly) float64
}
var _ = []Spatial{
&Point{}, &LineString{}, &Polygon{}, &Feature{},
&MultiPoint{}, &MultiLineString{}, &MultiPolygon{},
&GeometryCollection{}, &FeatureCollection{}, &Rect{},
EmptySpatial{},
}
// EmptySpatial ...
type EmptySpatial struct{}
// WithinRect ...
func (s EmptySpatial) WithinRect(rect geometry.Rect) bool {
return false
}
// WithinPoint ...
func (s EmptySpatial) WithinPoint(point geometry.Point) bool {
return false
}
// WithinLine ...
func (s EmptySpatial) WithinLine(line *geometry.Line) bool {
return false
}
// WithinPoly ...
func (s EmptySpatial) WithinPoly(poly *geometry.Poly) bool {
return false
}
// IntersectsRect ...
func (s EmptySpatial) IntersectsRect(rect geometry.Rect) bool {
return false
}
// IntersectsPoint ...
func (s EmptySpatial) IntersectsPoint(point geometry.Point) bool {
return false
}
// IntersectsLine ...
func (s EmptySpatial) IntersectsLine(line *geometry.Line) bool {
return false
}
// IntersectsPoly ...
func (s EmptySpatial) IntersectsPoly(poly *geometry.Poly) bool {
return false
}
// DistanceRect ...
func (s EmptySpatial) DistanceRect(rect geometry.Rect) float64 {
return 0
}
// DistancePoint ...
func (s EmptySpatial) DistancePoint(point geometry.Point) float64 {
return 0
}
// DistanceLine ...
func (s EmptySpatial) DistanceLine(line *geometry.Line) float64 {
return 0
}
// DistancePoly ...
func (s EmptySpatial) DistancePoly(poly *geometry.Poly) float64 {
return 0
}