Welcome to Cecil's Area of Interest (AOI) resources. These resources are designed to help you prepare and validate your AOI data.

  1. Prepare Your Dataset: A guide to ensure your AOI is in a compatible format
  2. AOI Validation: Tools to verify your AOI data before implementation

Prepare Your Dataset

prepare_your_dataset.ipynb

The purpose of this resource is to ensure that your AOI is in a format that we can ingest at Cecil.

Cecil's platform accepts AOIs in GeoJSON format. Follow the directions below to convert your dataset into GeoJSON format based on the current file type.

Notebook Setup

Ensure you have created and activated your virtual environment to run the following code. Also ensure that you have installed GDAL prior to running the following imports.

*# Import Packages*
**import** json
**import** geopandas **as** gpd
**from** shapely.geometry **import** mapping, shape, Polygon
**import** fiona

Converting Your AOI to GeoJSON

If you would like to do your own conversions instead of using the code below, your AOIs must be:

KML to GeoJSON

*# Set filepaths*
kml_path **=** "PATH_TO_YOUR_KML"
geojson_path **=** "PATH_TO_OUTPUT_FILE"

*# Note: you may need to enable KML support:*
fiona**.**drvsupport**.**supported_drivers['KML'] **=** 'rw'
**def** remove_z_coord(geometry):
    """Remove the Z (altitude) coordinate from a geometry object, making it 2D."""
    
    **if** geometry **is** **None**:
        **return** **None**
    
    *# Convert geometry to GeoJSON format*
    geom_mapping **=** mapping(geometry)

    *# Process coordinates to remove altitude (Z)*
    **def** strip_z(coords):
        **if** isinstance(coords[0], (float, int)):
            **if** len(coords) **==** 3 **and** coords[2] **==** 0:
                print("Stripping 0 z-coordinate.")
                **return** coords[:2]
            **elif** len(coords) **==** 3 **and** coords[2] **!=** 0:
                print("Stripping non-0 z-coordinate.")
        **else**:
            **return** [strip_z(coord) **for** coord **in** coords]
                
    geom_mapping["coordinates"] **=** strip_z(geom_mapping["coordinates"])
    **return** shape(geom_mapping)  
    
  ****def** kml_to_geojson(input_kml, output_geojson):
	  """
	  Convert a KML file to GeoJSON, removing altitude (Z) coordinates to create 2D geometries.
	
	  Args:
	      input_kml (str): Path to the input KML file.
	      output_geojson (str): Path to the output GeoJSON file.
	  """
	  *# Read the KML file into a GeoDataFrame*
	  gdf **=** gpd**.**read_file(input_kml, driver**=**"KML")
	
	  *# Remove altitude from all geometries*
	  gdf["geometry"] **=** gdf["geometry"]**.**apply(remove_z_coord)
	
	  *# Convert to GeoJSON-like dictionary*
	  geojson_dict **=** json**.**loads(gdf**.**to_json())
	
	  *# Write to GeoJSON file*
	  **with** open(output_geojson, "w") **as** f:
	      json**.**dump(geojson_dict, f, indent**=**4)
	      print(f"Wrote output geojson to {output_geojson}")
	  **return**
*# Convert your data*
kml_to_geojson(kml_path, geojson_path)

Shapefile to GeoJSON

*# Set filepaths*
shp_path **=** "PATH_TO_YOUR_SHP"
geojson_path **=** "PATH_TO_OUTPUT_FILE"