Raster Plantability To Geometries¶
get_administrative_attachment(polygon, previous, model)
¶
Determine the administrative attachment (e.g., city or IRIS) for a given polygon.
Parameters:¶
polygon : shapely.geometry.base.BaseGeometry The polygon for which to determine the administrative attachment. previous : Optional[Model] The previous administrative unit (e.g., city or IRIS). If provided, the function first checks if the polygon intersects with this unit. model : Type[Model] The Django model to query for administrative units (e.g., City or Iris).
Returns:¶
Tuple[Optional[int], Optional[Model]] A tuple containing: - The ID of the administrative unit that intersects with the polygon, or None if no match is found. - The administrative unit (e.g., city or IRIS) that intersects with the polygon, or None if no match is found.
Source code in back/plantability/management/commands/raster_plantability_to_geom.py
raster_to_db_tiles(raster_path, batch_size=BATCH_SIZE)
¶
Convert a raster file to Tile objects in the database. Each pixel becomes a square polygon with plantability indices based on the pixel value.
Parameters:¶
raster_path : str Path to the input raster file. batch_size : int, optional Number of tiles to create before committing to the database. Default is BATCH_SIZE.