run_spatial_analysis
Run the complete spatial analysis pipeline on a clustered CSV file. This is the primary entry point for the analysis stage.
- Loads the clustered CSV and validates required columns (
area,perimeter,cluster,centroid_x,centroid_y). - Computes descriptive statistics and saves
descriptive_stats.csv. - Generates boxplots for morphological features and a spatial distribution map.
- Computes the ANN index per cluster and saves
ann_results.csvandann_results.png.
Path to the clustered CSV file produced by
KMeansAnalyzer.process_features_csv. Must contain area, perimeter, cluster, centroid_x, and centroid_y columns.Directory for output files. Created automatically if it does not exist.
tuple[list[DescriptiveStats], list[ANNResult]]
compute_ann_index
Compute the Average Nearest Neighbor R-index for each cluster in a DataFrame.
DataFrame containing
centroid_x, centroid_y, and a cluster column.Name of the column holding cluster labels.
list[ANNResult]
ANN R-index interpretation
The R-index is the ratio of the observed mean nearest-neighbor distance to the expected mean distance for a random Poisson process at the same density:| R value | Interpretation |
|---|---|
| R < 0.9 | Clustered — objects are closer together than expected by chance |
| 0.9 ≤ R ≤ 1.1 | Random — distribution consistent with a random process |
| R > 1.1 | Dispersed — objects are spread further apart than expected |
r_index is None and interpretation is "Insufficient points".
generate_descriptive_stats
Generate descriptive statistics for each cluster in a DataFrame.
DataFrame containing
area, perimeter, and a cluster column.Name of the column holding cluster labels.
list[DescriptiveStats]
export_clusters_to_geojson
Convenience function that reads a clustered CSV and exports it directly to a GeoJSON file.
Path to the input clustered CSV file.
Destination path for the GeoJSON file.
Optional georeferencing data. When
None, pixel coordinates are written directly to the GeoJSON and a warning is logged.None
export_to_geojson
Export an in-memory DataFrame to a GeoJSON file.
DataFrame with
centroid_x, centroid_y, and other properties to include as GeoJSON feature attributes.Destination path for the GeoJSON file.
Optional georeferencing data.
None
Data classes
ANNResult
Result of Average Nearest Neighbor analysis for a single cluster.
Zero-based cluster identifier.
The computed R-index value, rounded to 3 decimal places.
None when the cluster has fewer than 2 points or the study area has zero extent.Human-readable label:
"Clustered", "Random", "Dispersed", or "Insufficient points".DescriptiveStats
Descriptive statistics for objects belonging to a single cluster.
Zero-based cluster identifier.
Number of objects in the cluster.
Mean object area in pixels.
Standard deviation of object area.
0.0 when the cluster has only one object.Minimum object area in pixels.
Maximum object area in pixels.
Mean object perimeter in pixels.
Standard deviation of object perimeter.
0.0 when the cluster has only one object.ImageReference
Georeferencing metadata for converting pixel coordinates to a real-world coordinate system.
X coordinate of the image origin in real-world units.
Y coordinate of the image origin in real-world units.
Size of one pixel in the X direction (real-world units per pixel).
Size of one pixel in the Y direction (real-world units per pixel). The Y axis is inverted during conversion to match the typical image coordinate system.
Coordinate reference system identifier (e.g.
"EPSG:4326"). None indicates pixel / local coordinates.pixel_to_geo
Convert a pixel coordinate pair to geographic (or projected) coordinates.
X coordinate in pixels.
Y coordinate in pixels.
tuple[float, float] — (geo_x, geo_y) in the target CRS, or (x, y) in local units when crs is None.