varunayan.util.geojson_utils module#

varunayan.util.geojson_utils.convert_to_geojson(json_data: Dict[str, Any]) Dict[str, Any][source]#

Convert various JSON formats to valid GeoJSON.

This function tries to intelligently convert different JSON structures to proper GeoJSON format based on the content.

Parameters:

json_data – The parsed JSON data

Returns:

A valid GeoJSON dictionary

Raises:

ValueError – If the JSON cannot be converted to GeoJSON

varunayan.util.geojson_utils.create_geojson_from_bbox(west: float, south: float, east: float, north: float) Dict[str, Any][source]#

Create a GeoJSON polygon from bounding box coordinates.

Parameters:
  • west – Western longitude

  • south – Southern latitude

  • east – Eastern longitude

  • north – Northern latitude

Returns:

A GeoJSON Feature with a Polygon geometry

varunayan.util.geojson_utils.create_temp_geojson(geojson_data: Dict[str, Any], request_id: str) str[source]#

Create a temporary GeoJSON file with the provided data.

Parameters:
  • geojson_data – Valid GeoJSON data

  • request_id – Unique identifier for the request (used in filename)

Returns:

Path to the created temporary file

varunayan.util.geojson_utils.extract_coords_from_geometry(geometry: Dict[str, Any]) List[List[float]][source]#

Extract all coordinates from a GeoJSON geometry object.

varunayan.util.geojson_utils.get_bounding_box(geojson_data: Dict[str, Any]) Tuple[float, float, float, float][source]#

Extract the bounding box (west, south, east, north) from a GeoJSON object.

Parameters:

geojson_data – A GeoJSON object (loaded as a Python dictionary)

Returns:

Tuple of (west, south, east, north) coordinates

varunayan.util.geojson_utils.is_valid_geojson(json_data: Dict[str, Any]) bool[source]#

Check if the provided JSON data is valid GeoJSON.

Parameters:

json_data – Parsed JSON data

Returns:

True if it’s valid GeoJSON, False otherwise

varunayan.util.geojson_utils.load_json_with_encoding(file_path: str) Dict[str, Any][source]#

Load a JSON file from local path or URL with appropriate encoding detection.

Parameters:

file_path – Path or URL to the JSON file

Returns:

Parsed JSON data as a dictionary

Raises:

ValueError – If the file cannot be parsed as JSON

varunayan.util.geojson_utils.set_v_geoj_utl(verbosity: int)[source]#