GWeather.Location¶
- Subclasses:
None
Methods¶
- Inherited:
- Structs:
class |
|
class |
|
class |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
Properties¶
None
Signals¶
- Inherited:
Fields¶
- Inherited:
Class Details¶
- class GWeather.Location(**kwargs)¶
- Bases:
- Abstract:
No
- Structure:
A
GWeatherLocation
represents a “location” of some type known to libgweather; anything from a single weather station to the entire world.See [enum`GWeather`.LocationLevel] for information about how the hierarchy of locations works.
- classmethod detect_nearest_city_finish(result)¶
- Parameters:
result (
Gio.AsyncResult
) – the result of the asynchronous operation- Raises:
- Returns:
Customized
GWeather.Location
- Return type:
Fetches the location from result.
- classmethod get_world()¶
- Returns:
a
GWEATHER_LOCATION_WORLD
location, orNULL
if the locations data could not be found or could not be parsed.- Return type:
Obtains the shared
GWeatherLocation
of typeGWEATHER_LOCATION_WORLD
, representing a hierarchy containing all of the locations from the location data.
- classmethod new_detached(name, icao, latitude, longitude)¶
- Parameters:
- Returns:
the newly created detached location
- Return type:
Construct a new location from the given data, supplementing any missing information from the static database.
- deserialize(serialized)¶
- Parameters:
serialized (
GLib.Variant
) – theGLib.Variant
representing theGWeather.Location
- Returns:
the deserialized location.
- Return type:
This call undoes the effect of
GWeather.Location.serialize
(), that is, it turns aGLib.Variant
into aGWeather.Location
. The conversion happens in the context of self (i.e, for a city or weather station, the resulting location will be attached to a administrative division, country and region as appropriate).
- detect_nearest_city(lat, lon, cancellable, callback, *user_data)¶
- Parameters:
lat (
float
) – Latitude, in degreeslon (
float
) – Longitude, in degreescancellable (
Gio.Cancellable
orNone
) – a cancellable instancecallback (
Gio.AsyncReadyCallback
orNone
) – callback function
Initializes geocode reversing to find place for (lat, lon) coordinates.
Calls the callback function passed by user when the result is ready.
The given location must be at most a
GWeather.LocationLevel.ADM1
location; this restriction may be lifted in a future version.
- equal(two)¶
- Parameters:
two (
GWeather.Location
) – anotherGWeather.Location
- Returns:
True
if the two locations represent the same place as far as libgweather can tell, andFalse
otherwise.- Return type:
Compares two
GWeather.Location
and sees if they represent the same place. It is only legal to call this for cities, weather stations or detached locations. Note that this function only checks for geographical characteristics, such as coordinates and METAR code. It is still possible that the two locations belong to different worlds (in which case care must be taken when passing them GWeatherLocationEntry andGWeather.Info
), or if one is them is detached it could have a custom name.
- find_by_country_code(country_code)¶
- Parameters:
country_code (
str
) – a country code- Returns:
a country level
GWeather.Location
, orNone
.- Return type:
Retrieves the country identified by the specified ISO 3166 code, if present in the database.
- find_by_station_code(station_code)¶
- Parameters:
station_code (
str
) – a 4 letter METAR code- Returns:
a weather station level location for the given station code, or
NULL
if none exists in the database- Return type:
Retrieves the weather station identifier by station_code.
Note that multiple instances of the same weather station can exist in the database, and this function will return any of them, so this not usually what you want.
See [method`GWeather`.Location.deserialize] to recover a stored location.
- find_nearest_city(lat, lon)¶
- Parameters:
- Returns:
the city closest to (lat, lon), in the region or administrative district of self.
- Return type:
Finds the nearest city to the passed latitude and longitude, among the descendants of self.
The given location must be at most a
GWeather.LocationLevel.ADM1
location. This restriction may be lifted in a future version.Note that this function does not check if (lat, lon) fall inside self, or are in the same region and time zone as the return value.
- find_nearest_city_full(lat, lon, func, *user_data)¶
- Parameters:
lat (
float
) – Latitude, in degreeslon (
float
) – Longitude, in degreesfunc (
GWeather.FilterFunc
orNone
) – a function to iterate over the locations; the function must returnTRUE
to continue checking for the location, andFALSE
to filter the location out
- Returns:
the city closest to (lat, lon), in the region or administrative district of self with validation of filter function
- Return type:
Finds the nearest city to the passed latitude and longitude, among the descendants of self.
Supports the use of own filter function to filter out locations.
Geocoding should be done on the application side if needed.
self must be at most a
GWeather.LocationLevel.ADM1
location. This restriction may be lifted in a future version.
- free_timezones(zones)¶
- Parameters:
zones ([
GLib.TimeZone
]) – an array of timezones returned by [method`GWeather`.Location.get_timezones]
Frees the array of timezones returned by
GWeather.Location.get_timezones
().
- get_city_name()¶
-
Retrieves the city name for the given location.
For a
GWEATHER_LOCATION_CITY
orGWEATHER_LOCATION_DETACHED
location, this method is equivalent to [method`GWeather`.Location.get_name].For a
GWEATHER_LOCATION_WEATHER_STATION
location, this is equivalent to calling [method`GWeather`.Location.get_name] on the location’s parent.For other locations this method will return
NULL
.
- get_code()¶
-
Gets the METAR station code associated with a
GWEATHER_LOCATION_WEATHER_STATION
location.
- get_coords()¶
- Returns:
- latitude:
the return location for the latitude
- longitude:
the return location for the longitude
- Return type:
Gets self's coordinates.
You must call [method`GWeather`.Location.has_coords] before calling this function.
- get_country()¶
-
Gets the ISO 3166 country code of the given location.
For
GWEATHER_LOCATION_WORLD
andGWEATHER_LOCATION_REGION
, this function returnsNULL
.
- get_country_name()¶
-
Retrieves the country name for the given location.
For a
GWEATHER_LOCATION_COUNTRY
location, this is equivalent to [method`GWeather`.Location.get_name].For a
GWEATHER_LOCATION_REGION
andGWEATHER_LOCATION_WORLD
location, this method will returnNULL
.For other location levels, this method will find the parent
GWEATHER_LOCATION_COUNTRY
and return its name.
- get_distance(loc2)¶
- Parameters:
loc2 (
GWeather.Location
) – a secondGWeather.Location
- Returns:
the distance between self and loc2.
- Return type:
Determines the distance in kilometers between self and loc2.
- get_english_sort_name()¶
-
Gets the location’s name, in a representation useful for comparisons.
The “sort name” is the location’s name after having
GLib.utf8_normalize
() (withG_NORMALIZE_ALL
) andGLib.utf8_casefold
() called on it. You can use this to sort locations, or to comparing user input against a location name.
- get_level()¶
- Returns:
self's level
- Return type:
Gets self's level, from
GWeather.LocationLevel.WORLD
, toGWeather.LocationLevel.WEATHER_STATION
.
- get_name()¶
-
Gets the location’s name, localized into the current language.
- get_parent()¶
- Returns:
the location’s parent
- Return type:
Gets the location’s parent.
- get_sort_name()¶
-
Gets the location’s name, localized into the current language, in a representation useful for comparisons.
The “sort name” is the location’s name after having
GLib.utf8_normalize
() (withG_NORMALIZE_ALL
) andGLib.utf8_casefold
() called on it. You can use this to sort locations, or to comparing user input against a location name.
- get_timezone()¶
- Returns:
the location’s timezone
- Return type:
Gets the timezone associated with self, if known.
- get_timezone_str()¶
-
Gets the timezone associated with self, if known, as a string.
- get_timezones()¶
- Returns:
the timezones associated with the location
- Return type:
Gets an array of all timezones associated with any location under self.
Use
GWeather.Location.free_timezones
() to free this array.
- has_coords()¶
-
Checks if self has valid latitude and longitude.
- has_timezone()¶
- Returns:
true if the location has a timezone; false otherwise
- Return type:
Checks whether the location has a timezone.
- next_child(child)¶
- Parameters:
child (
GWeather.Location
orNone
) – the next child- Returns:
The next child, if one exists
- Return type:
Allows iterating all children of a location.
Pass
NULL
to get the first child, and any child to get the next one.Note that the reference to child is taken, meaning iterating all children is as simple as:
- ``c
g_autoptr (GWeatherLocation) child = NULL; while ((child = gweather_location_next_child (location, child)))
- {
// Do something with child
}
- serialize()¶
- Returns:
the serialization of location.
- Return type:
Transforms a
GWeather.Location
into aGLib.Variant
, in a way that callingGWeather.Location.deserialize
() will hold an equivalentGWeather.Location
. The resulting variant can then be stored intoGio.Settings
or on disk. This call is only valid for cities, weather stations and detached locations. The format of the resultingGLib.Variant
is private to libgweather, and it is subject to change. You should use the “v” format inGio.Settings
, to ensure maximum compatibility with future versions of the library.