Utility functions

night_light.utils.mapping.create_folium_map(layers: list[Layer], center: list, zoom_start: int, map_filename: str)

Create a Folium map from a GeoDataFrame and save it to an HTML file.

This function generates a Folium map centered at a specified location and zoom level, overlays the geometries from the provided GeoDataFrame, and saves the map as an HTML file.

Parameters:
  • layers (list[folium.map.Layer]) – Layers containing geometries to be added to the map.

  • center (list) – A list containing the latitude and longitude for the map center [latitude, longitude].

  • zoom_start (int) – The initial zoom level for the map.

  • map_filename (str) – The file path where the HTML map will be saved.

Returns:

None

night_light.utils.mapping.open_html_file(file_path: str | PathLike[str])
Parameters:

file_path (str | PathLike[str])

night_light.utils.query_geojson.fetch_geojson_data(url: str, params: dict) GeoDataFrame

Fetch GeoJSON data from a specified URL with given parameters.

This function sends a GET request to the provided URL with the specified query parameters, retrieves the GeoJSON data, and converts it into a GeoDataFrame with an EPSG:4326 CRS.

Parameters:
  • url (str) – The URL to request the GeoJSON data from.

  • params (dict) – A dictionary of query parameters to include in the request.

Returns:

A GeoDataFrame containing the geometries and properties from the fetched GeoJSON data.

Return type:

gpd.GeoDataFrame

Raises:
  • requests.HTTPError – If the HTTP request fails.

  • ValueError – If the retrieved data does not contain valid GeoJSON features.

night_light.utils.query_geojson.save_geojson(gdf: GeoDataFrame, filename: str)

Save a GeoDataFrame to a GeoJSON file.

Parameters:
  • gdf (gpd.GeoDataFrame) – The GeoDataFrame to be saved as GeoJSON.

  • filename (str) – The file path where the GeoJSON will be saved.

Returns:

None