Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrLocationNotFound = errors.New("country not found")
ErrLocationNotFound is returned when no country is found for given coordinates.
Functions ¶
This section is empty.
Types ¶
type Dataset ¶
type Dataset func() []Feature
Dataset provides a Feature slice. It is a function for easier integration into existing rgeo v1 code only.
type Feature ¶
func Countries10 ¶
func Countries10() []Feature
func Countries110 ¶
func Countries110() []Feature
func Provinces10 ¶
func Provinces10() []Feature
type FeatureCollection ¶
type FeatureCollection []Feature
func LoadGeoJSON ¶
func LoadGeoJSON(fc geojson.FeatureCollection) (FeatureCollection, error)
type Location ¶
type Location struct {
// Commonly used country name
Country string `json:"country,omitempty"`
// Formal name of country
CountryLong string `json:"country_long,omitempty"`
// ISO 3166-1 alpha-1 and alpha-2 codes
CountryCode2 string `json:"country_code_2,omitempty"`
CountryCode3 string `json:"country_code_3,omitempty"`
Continent string `json:"continent,omitempty"`
Region string `json:"region,omitempty"`
SubRegion string `json:"subregion,omitempty"`
Province string `json:"province,omitempty"`
// ISO 3166-2 code
ProvinceCode string `json:"province_code,omitempty"`
City string `json:"city,omitempty"`
}
Location is the return type for ReverseGeocode.
type Rgeo ¶
type Rgeo struct {
// contains filtered or unexported fields
}
Rgeo is the type used to hold pre-created polygons for reverse geocoding.
func New ¶
New returns a Rgeo struct which can then be used with ReverseGeocode. It takes any number of datasets as arguments.
The included datasets are:
- Cities10
- Countries10
- Countries110
- Provinces10
func (*Rgeo) Build ¶
func (r *Rgeo) Build()
Build builds the underlying shape index. This ensures that future calls to ReverseGeocode will be fast. If Build is not called, then the first lookup will build the index implicitly and experience a 1s+ delay.
func (*Rgeo) ReverseGeocode ¶
ReverseGeocode returns the country in which the given coordinate is located.
The input is a geom.Coord, which is just a []float64 with the longitude in the zeroth position and the latitude in the first position (i.e. []float64{lon, lat}).
Example ¶
r, err := New(Countries110)
if err != nil {
// Handle error
}
loc, err := r.ReverseGeocode([]float64{0, 52})
if err != nil {
// Handle error
}
fmt.Printf("%s\n", loc.Country)
fmt.Printf("%s\n", loc.CountryLong)
fmt.Printf("%s\n", loc.CountryCode2)
fmt.Printf("%s\n", loc.CountryCode3)
fmt.Printf("%s\n", loc.Continent)
fmt.Printf("%s\n", loc.Region)
fmt.Printf("%s\n", loc.SubRegion)
Output: United Kingdom United Kingdom of Great Britain and Northern Ireland GB GBR Europe Europe Northern Europe
Example (City) ¶
r, err := New(Provinces10, Cities10)
if err != nil {
// Handle error
}
loc, err := r.ReverseGeocode([]float64{141.35, 43.07})
if err != nil {
// Handle error
}
fmt.Println(loc)
Output: <Location> Sapporo, Hokkaidō, Japan (JPN), Asia
Example (Snapping) ¶
r, err := New(Provinces10)
if err != nil {
// Handle error
}
loc, err := r.ReverseGeocodeSnapping(geom.Coord{141.5439, 40.5588})
if err != nil {
// Handle error
}
fmt.Println(loc)
Output: <Location> Aomori, Japan (JPN), Asia
func (*Rgeo) ReverseGeocodeSnapping ¶
func (*Rgeo) SetSnappingDistanceCustom ¶
SetSnappingDistanceCustom recalculates the underlying ChordAngle for the DistanceLimit of nearest-edge queries via ReverseGeocodeSnapping.
The inputs are the snapping distance on the sphere's surface in kilometers, and the radius of the sphere used in the dataset.
func (*Rgeo) SetSnappingDistanceEarth ¶
SetSnappingDistanceEarth sets ReverseGeocodeSnapping snap distance on Earth. Only edges within the defined radius around given points will be considered by ReverseGeocodeSnapping.
The input is the snapping distance in kilometers. Must be positive.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
datagen
command
Command datagen converts GeoJSON files into go files containing functions that return the compressed GeoJSON, it can also merge properties from one GeoJSON file into another using the -merge flag (which it does by matching the country names).
|
Command datagen converts GeoJSON files into go files containing functions that return the compressed GeoJSON, it can also merge properties from one GeoJSON file into another using the -merge flag (which it does by matching the country names). |