Inspects an sf object and reports geometry type, coordinate reference
system, feature count, candidate grouping columns (including empty-value
counts), detected parent-to-child column hierarchies (including cases where
child names repeat across parents), and invalid geometry counts. The output
guides column selection in drag_map_prototype() and helps diagnose
unexpected behaviour when uploading custom spatial files to Spatial Studio.
Value
An invisible named list with components:
geometry_typeCharacter vector of unique geometry type names.
crsCRS identifier string (e.g.
"EPSG:3857"or"Unknown CRS").is_longlatLogical —
TRUEwhen the CRS is geographic.n_featuresInteger row count.
candidate_colsCharacter vector of candidate grouping columns.
column_detailsNamed list with
n_uniqueandn_emptyper candidate column.n_invalid_geometriesNumber of features with invalid geometry.
hierarchy_pairsList of detected parent-to-child column pairs, each with
parent,child,n_parent,n_child, andchild_repeats_across_parents.recommended_pathSuggested grouping path string, or
NULL.
Examples
poly <- sf::st_sf(
county = c("Essex", "Essex", "Morris", "Morris"),
mun = c("Fairfield", "Caldwell", "Fairfield", "Roxbury"),
geometry = sf::st_sfc(
sf::st_polygon(list(rbind(c(0,1e5),c(1e5,1e5),c(1e5,2e5),c(0,2e5),c(0,1e5)))),
sf::st_polygon(list(rbind(c(0,0),c(1e5,0),c(1e5,1e5),c(0,1e5),c(0,0)))),
sf::st_polygon(list(rbind(c(1e5,1e5),c(2e5,1e5),c(2e5,2e5),c(1e5,2e5),c(1e5,1e5)))),
sf::st_polygon(list(rbind(c(1e5,0),c(2e5,0),c(2e5,1e5),c(1e5,1e5),c(1e5,0)))),
crs = 3857
)
)
diag <- dragmapr_diagnostics(poly)
#> dragmapr spatial diagnostics
#> ------------------------------------------
#> Geometry type : POLYGON
#> CRS : EPSG:3857 (projected)
#> Features : 4
#> Invalid geometries : 0
#>
#> Candidate grouping columns:
#> - county (2 unique)
#> - mun (3 unique)
#>
#> Detected column hierarchies:
#> - county -> mun (2 -> 3 groups) [child names repeat across parents - use make_hierarchy_key()]
#>
#> Recommended grouping : county -> mun
#> ------------------------------------------
