Documentation
¶
Index ¶
- func PrintCacheSizeAnalysisForFile(file string) error
- type Geocoder
- type InfoModel
- type Option
- type PointInRadius
- type PointKind
- type RGeoCoder
- func (f *RGeoCoder) CountryAt(lat, lon float64) (string, bool)
- func (f *RGeoCoder) Find(lat, lon float64) (i InfoModel, ok bool)
- func (f *RGeoCoder) FindInRadius(lat, lon float64, radius float64) (i InfoModel, ok bool)
- func (f *RGeoCoder) ForEachPoint(fn func(cachemodel.Point) bool)
- func (f *RGeoCoder) LoadFromPointsFile(file string) errordeprecated
- func (f *RGeoCoder) Metadata() cachemodel.Metadata
- func (f *RGeoCoder) NumPoints() int
- func (f *RGeoCoder) PointsInRadius(lat, lon, radius float64, limit int, kinds PointKind) ([]PointInRadius, int)
- func (f *RGeoCoder) Zones() []cachemodel.Zone
- type RGeoCoderDisk
- func (f *RGeoCoderDisk) Close() error
- func (f *RGeoCoderDisk) CountryAt(lat, lon float64) (string, bool)
- func (f *RGeoCoderDisk) Find(lat, lon float64) (InfoModel, bool)
- func (f *RGeoCoderDisk) FindInRadius(lat, lon float64, radius float64) (i InfoModel, ok bool)
- func (f *RGeoCoderDisk) ForEachPoint(fn func(cachemodel.Point) bool)
- func (f *RGeoCoderDisk) Metadata() cachemodel.Metadata
- func (f *RGeoCoderDisk) NumPoints() int
- func (f *RGeoCoderDisk) PointsInRadius(lat, lon, radius float64, limit int, kinds PointKind) ([]PointInRadius, int)
- func (f *RGeoCoderDisk) Zones() []cachemodel.Zone
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PrintCacheSizeAnalysisForFile ¶ added in v1.4.0
Types ¶
type Geocoder ¶ added in v1.5.0
type Geocoder interface {
Find(lat, lon float64) (InfoModel, bool)
// PointsInRadius returns up to limit cached points within radius degrees of
// (lat, lon), nearest first, and the total number of points that matched
// (which exceeds len(points) when the result was truncated). The kind
// filter is a bitmask; a zero mask matches nothing.
PointsInRadius(lat, lon, radius float64, limit int, kinds PointKind) ([]PointInRadius, int)
// Metadata returns the cache metadata the geocoder was loaded from; legacy
// caches that carry none yield the zero value.
Metadata() cachemodel.Metadata
}
Geocoder is the common interface for both in-memory and disk-backed geocoders.
type PointInRadius ¶ added in v1.6.0
type PointInRadius struct {
// X is longitude and Y is latitude, in degrees.
X, Y float64
// Info is the point's address; Region and Country are filled from the
// border trees when the stored record left them empty, mirroring what Find
// reports for a lookup at the point's location.
Info geomodel.Info
// Kind is the point's object kind, derived from its weight.
Kind PointKind
}
PointInRadius is one cache point returned by a radius query.
type PointKind ¶ added in v1.6.0
type PointKind uint8
PointKind is the object kind of a cached point, as reported by PointsInRadius. Values are a bitmask, so callers can OR them into a filter.
const ( PointKindBuilding PointKind = 1 << iota PointKindRoad PointKindArea // PointKindsAll matches every kind. PointKindsAll = PointKindBuilding | PointKindRoad | PointKindArea )
func PointKindFromWeight ¶ added in v1.6.0
PointKindFromWeight derives the object kind from a point's generator weight: 5 is a road (highways are resampled), 3/2 are the industrial/protected area sub-kinds, everything else is a building. It is the Go-side fallback because the in-memory geoInfo does not carry the explicit type byte.
type RGeoCoder ¶
type RGeoCoder struct {
// contains filtered or unexported fields
}
func LoadGeoCoderFromFile ¶ added in v1.2.1
func LoadGeoCoderFromReader ¶ added in v1.2.1
func NewGeoCoderFromPoints ¶ added in v1.5.0
func NewGeoCoderFromPoints(points []cachemodel.Point, opts ...Option) *RGeoCoder
NewGeoCoderFromPoints builds an RGeoCoder from pre-constructed cache model points. This is useful for testing with known data. Regions and countries are initialized empty.
func (*RGeoCoder) CountryAt ¶ added in v1.5.0
CountryAt returns the name of the country containing the given coordinates.
func (*RGeoCoder) FindInRadius ¶ added in v1.3.0
func (*RGeoCoder) ForEachPoint ¶ added in v1.5.0
func (f *RGeoCoder) ForEachPoint(fn func(cachemodel.Point) bool)
ForEachPoint calls fn for every cached point. Iteration stops early when fn returns false.
func (*RGeoCoder) LoadFromPointsFile
deprecated
func (*RGeoCoder) Metadata ¶ added in v1.5.0
func (f *RGeoCoder) Metadata() cachemodel.Metadata
Metadata returns the cache metadata. The zero value is returned for legacy caches that carry none.
func (*RGeoCoder) PointsInRadius ¶ added in v1.6.0
func (f *RGeoCoder) PointsInRadius(lat, lon, radius float64, limit int, kinds PointKind) ([]PointInRadius, int)
PointsInRadius returns up to limit cached points within radius degrees of (lat, lon), nearest first, together with the total number of matching points.
func (*RGeoCoder) Zones ¶ added in v1.5.0
func (f *RGeoCoder) Zones() []cachemodel.Zone
Zones returns the cache's region and country zones.
type RGeoCoderDisk ¶ added in v1.5.0
type RGeoCoderDisk struct {
// contains filtered or unexported fields
}
RGeoCoderDisk is a disk-backed reverse geocoder that uses mmap for the spatial index and for lazy string resolution. Strings are read from the mmap'd file only when a point is matched.
func LoadGeoCoderFromFileDisk ¶ added in v1.5.0
func LoadGeoCoderFromFileDisk(file string, opts ...Option) (*RGeoCoderDisk, error)
LoadGeoCoderFromFileDisk loads a v2 cache file using mmap for the spatial index. This is the default loading path for v2 caches — only string tables and zone polygons are loaded into memory; the KD-tree index is accessed via mmap.
The returned RGeoCoderDisk must be closed after use to release the mmap mapping.
func (*RGeoCoderDisk) Close ¶ added in v1.5.0
func (f *RGeoCoderDisk) Close() error
Close releases the mmap resources.
func (*RGeoCoderDisk) CountryAt ¶ added in v1.5.0
func (f *RGeoCoderDisk) CountryAt(lat, lon float64) (string, bool)
CountryAt returns the name of the country containing the given coordinates.
func (*RGeoCoderDisk) Find ¶ added in v1.5.0
func (f *RGeoCoderDisk) Find(lat, lon float64) (InfoModel, bool)
Find returns the closest address for the given coordinates.
func (*RGeoCoderDisk) FindInRadius ¶ added in v1.5.0
func (f *RGeoCoderDisk) FindInRadius(lat, lon float64, radius float64) (i InfoModel, ok bool)
FindInRadius returns the closest address within the given radius.
func (*RGeoCoderDisk) ForEachPoint ¶ added in v1.5.0
func (f *RGeoCoderDisk) ForEachPoint(fn func(cachemodel.Point) bool)
ForEachPoint calls fn for every cached point. Iteration stops early when fn returns false. String IDs are resolved while iterating.
func (*RGeoCoderDisk) Metadata ¶ added in v1.5.0
func (f *RGeoCoderDisk) Metadata() cachemodel.Metadata
Metadata returns the cache metadata.
func (*RGeoCoderDisk) NumPoints ¶ added in v1.5.0
func (f *RGeoCoderDisk) NumPoints() int
NumPoints returns the number of points in the cache.
func (*RGeoCoderDisk) PointsInRadius ¶ added in v1.6.0
func (f *RGeoCoderDisk) PointsInRadius(lat, lon, radius float64, limit int, kinds PointKind) ([]PointInRadius, int)
PointsInRadius returns up to limit cached points within radius degrees of (lat, lon), nearest first, together with the total number of matching points.
func (*RGeoCoderDisk) Zones ¶ added in v1.5.0
func (f *RGeoCoderDisk) Zones() []cachemodel.Zone
Zones returns the cache's region and country zones.