Documentation
¶
Index ¶
- Constants
- Variables
- func ApproximateDistance(lat1, lon1, lat2, lon2 float64) float64
- func ApproximateDistanceGeo(lat1, lon1, lat2, lon2 GeoType) float64
- func AreaInKm(lat1, lon1, lat2, lon2 float64) float64
- func AreaInMiles(lat1, lon1, lat2, lon2 float64) float64
- func Bestest(g GeoPoints, pt Point, deltaKm float64) (int, float64)
- func Closest(g GeoPoints, pt Point, deltaKm float64) (int, float64)
- func Distance(lat1, lon1, lat2, lon2 float64) float64
- func Distance32(lat1, lon1, lat2, lon2 float32) float64
- func DistanceGeoType(lat1, lon1, lat2, lon2 GeoType) float64
- func LoadLines(filename string, fn func(string) error) error
- func LonKilos(lat float64) float64
- func LongitudeKilometerDegrees(lat, kilometers float64) float64
- func LongitudeKilometers(lat, lon float64) float64
- func LookupLonKmPerLat(lat float64) float64
- func SquareKmInMiles(k float64) float64
- func Within(lat, lon, minLat, minLon, maxLat, maxLon GeoType) bool
- type Container
- type Decoder
- type GeoPoints
- type GeoType
- type Iter
- type LineInfo
- type MFile
- type Pair
- type Point
- type Rect
Constants ¶
const ( // DegreeToKilometer is a "constant" for latitude but varies for longitude DegreeToKilometer = 111.111 //111.321 MilesToKilometer = 1.609344 EarthRadiusInKM = 6371.1 // 6378.1 SquareKmPerSquareMile = 0.386102 )
const Radian = math.Pi / 180.0
Variables ¶
var (
ErrInvalidCoordinates = errors.New("invalid coordinates")
)
var ErrNotFound = errors.New("not found")
Functions ¶
func ApproximateDistance ¶
ApproximateDistanceGeo returns the approximate distance between 2 points It uses the pythagarean distance calc which is meant for 2d operations but is "good enough" for shorter distances (which we primarily care about) It is about 7 times faster than the "proper way"
func ApproximateDistanceGeo ¶
ApproximateDistanceGeo returns the approximate distance between 2 points It uses the pythagarean distance calc which is meant for 2d operations but is "good enough" for shorter distances (which we primarily care about) It is about 7 times faster than the "proper way"
func AreaInMiles ¶
func Bestest ¶
Bestest searches for a matching point within the distance (in Km) of the specified point. It returns the index of the closest point and the distance from the target If nothing is found, it returns the Len() of the points list and -1 distance
NOTE: this is an adaptation of Bestest, but distances are approximated to
minimize computational load
TODO: the len return is in line w/ Go sort.Search, but perhaps -1 would be better? TODO part too: use distance func to share same routine w/ approx and haversine calcs?
func Closest ¶
Closest searches for a matching point within the distance (in Km) of the specified point. It returns the index of the closest point and the distance from the target If nothing is found, it returns the Len() of the points list and -1 distance
NOTE: this is an adaptation of Bestest, but distances are approximated to
minimize computational load
TODO: the len return is in line w/ Go sort.Search, but perhaps -1 would be better? TODO part too: use distance func to share same routine w/ approx and haversine calcs?
func Distance ¶
Distance returns the distance in kM between 2 geographic points It uses the Haversine formula for spherical calculations
func Distance32 ¶
func DistanceGeoType ¶
func LongitudeKilometerDegrees ¶
LongitudeKilometerDegrees converts the distance given in kilometers at that latitude to degrees
func LongitudeKilometers ¶
LongitudeKilometers returns the distance of the degrees lon, at latitude lat
func LookupLonKmPerLat ¶
LookupLonKmPerLat returns the ratio of kilometers to degrees longitude at the given latitude.
Accuracy is with 1% under 80 degrees, which is good enough for most work
func SquareKmInMiles ¶
Types ¶
type GeoType ¶
type GeoType float32
GeoType for coordinates with slightly less accuracy a float32 has 7 digits of precision, which is within ~11cm
Virtually all geo data is "close enough" using this, and for data that heavily comprises these points, one can reduce memory footprint by one half (for points)
type Iter ¶
type Iter struct {
// contains filtered or unexported fields
}
func (*Iter) IndexPoint ¶
type Point ¶
type Point struct {
Lat, Lon GeoType
}