GWeather.Location

g GObject.Object GObject.Object GWeather.Location GWeather.Location GObject.Object->GWeather.Location

Subclasses:

None

Methods

Inherited:

GObject.Object (37)

Structs:

GObject.ObjectClass (5)

class

detect_nearest_city_finish (result)

class

get_world ()

class

new_detached (name, icao, latitude, longitude)

deserialize (serialized)

detect_nearest_city (lat, lon, cancellable, callback, *user_data)

equal (two)

find_by_country_code (country_code)

find_by_station_code (station_code)

find_nearest_city (lat, lon)

find_nearest_city_full (lat, lon, func, *user_data)

free_timezones (zones)

get_city_name ()

get_code ()

get_coords ()

get_country ()

get_country_name ()

get_distance (loc2)

get_english_name ()

get_english_sort_name ()

get_level ()

get_name ()

get_parent ()

get_sort_name ()

get_timezone ()

get_timezone_str ()

get_timezones ()

has_coords ()

has_timezone ()

next_child (child)

serialize ()

Virtual Methods

Inherited:

GObject.Object (7)

Properties

None

Signals

Inherited:

GObject.Object (1)

Fields

Inherited:

GObject.Object (1)

Class Details

class GWeather.Location(**kwargs)
Bases:

GObject.Object

Abstract:

No

Structure:

GWeather.LocationClass

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:

GLib.Error

Returns:

Customized GWeather.Location

Return type:

GWeather.Location

Fetches the location from result.

classmethod get_world()
Returns:

a GWEATHER_LOCATION_WORLD location, or NULL if the locations data could not be found or could not be parsed.

Return type:

GWeather.Location or None

Obtains the shared GWeatherLocation of type GWEATHER_LOCATION_WORLD, representing a hierarchy containing all of the locations from the location data.

classmethod new_detached(name, icao, latitude, longitude)
Parameters:
  • name (str) – the user visible location name

  • icao (str or None) – the ICAO code of the location

  • latitude (float) – the latitude of the location

  • longitude (float) – the longitude of the location

Returns:

the newly created detached location

Return type:

GWeather.Location

Construct a new location from the given data, supplementing any missing information from the static database.

deserialize(serialized)
Parameters:

serialized (GLib.Variant) – the GLib.Variant representing the GWeather.Location

Returns:

the deserialized location.

Return type:

GWeather.Location

This call undoes the effect of GWeather.Location.serialize(), that is, it turns a GLib.Variant into a GWeather.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:

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) – another GWeather.Location

Returns:

True if the two locations represent the same place as far as libgweather can tell, and False otherwise.

Return type:

bool

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 and GWeather.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, or None.

Return type:

GWeather.Location

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:

GWeather.Location or None

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:
  • lat (float) – Latitude, in degrees

  • lon (float) – Longitude, in degrees

Returns:

the city closest to (lat, lon), in the region or administrative district of self.

Return type:

GWeather.Location

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 degrees

  • lon (float) – Longitude, in degrees

  • func (GWeather.FilterFunc or None) – a function to iterate over the locations; the function must return TRUE to continue checking for the location, and FALSE to filter the location out

  • user_data (object or None) – for customization

Returns:

the city closest to (lat, lon), in the region or administrative district of self with validation of filter function

Return type:

GWeather.Location

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()
Returns:

the city name of the location

Return type:

str or None

Retrieves the city name for the given location.

For a GWEATHER_LOCATION_CITY or GWEATHER_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()
Returns:

the location’s METAR station code

Return type:

str or None

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:

(latitude: float, longitude: float)

Gets self's coordinates.

You must call [method`GWeather`.Location.has_coords] before calling this function.

get_country()
Returns:

the location’s country code

Return type:

str or None

Gets the ISO 3166 country code of the given location.

For GWEATHER_LOCATION_WORLD and GWEATHER_LOCATION_REGION, this function returns NULL.

get_country_name()
Returns:

the location’s country name

Return type:

str or None

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 and GWEATHER_LOCATION_WORLD location, this method will return NULL.

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 second GWeather.Location

Returns:

the distance between self and loc2.

Return type:

float

Determines the distance in kilometers between self and loc2.

get_english_name()
Returns:

the location’s name

Return type:

str or None

Gets the location’s name.

get_english_sort_name()
Returns:

the sort name of the location

Return type:

str or None

Gets the location’s name, in a representation useful for comparisons.

The “sort name” is the location’s name after having GLib.utf8_normalize() (with G_NORMALIZE_ALL) and GLib.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:

GWeather.LocationLevel

Gets self's level, from GWeather.LocationLevel.WORLD, to GWeather.LocationLevel.WEATHER_STATION.

get_name()
Returns:

the location’s name

Return type:

str or None

Gets the location’s name, localized into the current language.

get_parent()
Returns:

the location’s parent

Return type:

GWeather.Location or None

Gets the location’s parent.

get_sort_name()
Returns:

the sort name of the location

Return type:

str or None

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() (with G_NORMALIZE_ALL) and GLib.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:

GLib.TimeZone or None

Gets the timezone associated with self, if known.

get_timezone_str()
Returns:

the location’s timezone as a string

Return type:

str or None

Gets the timezone associated with self, if known, as a string.

get_timezones()
Returns:

the timezones associated with the location

Return type:

[GLib.TimeZone]

Gets an array of all timezones associated with any location under self.

Use GWeather.Location.free_timezones() to free this array.

has_coords()
Returns:

True if self has valid latitude and longitude.

Return type:

bool

Checks if self has valid latitude and longitude.

has_timezone()
Returns:

true if the location has a timezone; false otherwise

Return type:

bool

Checks whether the location has a timezone.

next_child(child)
Parameters:

child (GWeather.Location or None) – the next child

Returns:

The next child, if one exists

Return type:

GWeather.Location or None

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:

GLib.Variant

Transforms a GWeather.Location into a GLib.Variant, in a way that calling GWeather.Location.deserialize() will hold an equivalent GWeather.Location. The resulting variant can then be stored into Gio.Settings or on disk. This call is only valid for cities, weather stations and detached locations. The format of the resulting GLib.Variant is private to libgweather, and it is subject to change. You should use the “v” format in Gio.Settings, to ensure maximum compatibility with future versions of the library.