Deleting source `output/mitigation_points_shp/mitigation_points.shp' using driver `ESRI Shapefile'
Writing layer `mitigation_points' to data source
`output/mitigation_points_shp/mitigation_points.shp' using driver `ESRI Shapefile'
Writing 76 features with 21 fields and geometry type Point.
Deleting source `docs/mitigation_points_shp/mitigation_points.shp' failed
Writing layer `mitigation_points' to data source
`docs/mitigation_points_shp/mitigation_points.shp' using driver `ESRI Shapefile'
Writing 76 features with 21 fields and geometry type Point.
Deleting source `output/mitigation_sites_shp/mitigation_sites.shp' using driver `ESRI Shapefile'
Writing layer `mitigation_sites' to data source
`output/mitigation_sites_shp/mitigation_sites.shp' using driver `ESRI Shapefile'
Writing 90 features with 13 fields and geometry type Polygon.
Deleting source `docs/mitigation_sites_shp/mitigation_sites.shp' failed
Writing layer `mitigation_sites' to data source
`docs/mitigation_sites_shp/mitigation_sites.shp' using driver `ESRI Shapefile'
Writing 90 features with 13 fields and geometry type Polygon.
[1] TRUE
Code
# Load CSV datamitigation_data <-read_csv("data/gis/Mitigation_PointsAGOL.csv", show_col_types =FALSE)mitigation_data <- mitigation_data %>%filter(!is.na(Latitude) &!is.na(Longitude))# Normalize project names to match shapefile naming (remove extra spaces)popup_name_col <-if ("POPUP NAME"%in%names(mitigation_data)) "POPUP NAME"elseif ("POPUP_NAME"%in%names(mitigation_data)) "POPUP_NAME"elseNULLif (!is.null(popup_name_col)) { mitigation_data[[popup_name_col]] <-gsub("129/ 118", "129/118", mitigation_data[[popup_name_col]], fixed =TRUE)# Also normalize any other common spacing issues mitigation_data[[popup_name_col]] <-gsub(" ", " ", mitigation_data[[popup_name_col]]) # Remove double spaces mitigation_data[[popup_name_col]] <-trimws(mitigation_data[[popup_name_col]]) # Trim whitespace}# Convert CSV to spatial pointsmitigation_sf <-st_as_sf( mitigation_data,coords =c("Longitude", "Latitude"),crs =4326)# Create popup text for CSV pointspopup_name_col <-if ("POPUP NAME"%in%names(mitigation_sf)) "POPUP NAME"elseif ("POPUP_NAME"%in%names(mitigation_sf)) "POPUP_NAME"elseNULLif (!is.null(popup_name_col)) { project_names <-ifelse(is.na(mitigation_sf[[popup_name_col]]), "Project", mitigation_sf[[popup_name_col]])} else { project_names <-rep("Project", nrow(mitigation_sf))}mitigation_sf$popup_text <-paste0("<b>", project_names, "</b><br>",ifelse(!is.na(mitigation_sf$PROJECT_TYPE_2), paste0("Type: ", mitigation_sf$PROJECT_TYPE_2, "<br>"), ""),ifelse(!is.na(mitigation_sf$ACRES), paste0("Acres: ", mitigation_sf$ACRES, "<br>"), ""),ifelse(!is.na(mitigation_sf$Project_Status), paste0("Status: ", mitigation_sf$Project_Status, "<br>"), ""),ifelse(!is.na(mitigation_sf$DESCRIPTION), paste0("Description: ", substr(mitigation_sf$DESCRIPTION, 1, 200), "..."), ""))# Create color palette for CSV points (for ggplot)if ("PROJECT_TYPE_2"%in%names(mitigation_sf)) { project_types <-unique(mitigation_sf$PROJECT_TYPE_2) project_types <- project_types[!is.na(project_types)]# Create named vector of colors for ggplot n_types <-length(project_types) project_colors_vec <- RColorBrewer::brewer.pal(min(n_types, 9), "Set1")if (n_types >9) { project_colors_vec <-c(project_colors_vec, RColorBrewer::brewer.pal(min(n_types -9, 8), "Set2")) } project_colors <-setNames(project_colors_vec[1:n_types], project_types)} else { project_colors <-NULL}# Load shapefile datamitigation_sites_sf <-st_read("data/gis/mit_points/mitigation_sites.shp", quiet =TRUE) %>%st_transform(4326)# Create popup text for shapefile polygonsmitigation_sites_sf <- mitigation_sites_sf %>%mutate(popup_name =ifelse(is.na(Name) | Name =="", "Project", as.character(Name)),popup_type =ifelse(is.na(TYPE) | TYPE =="", "", paste0("Type: ", TYPE, "<br>")),popup_acres =ifelse(is.na(Acres), "", paste0("Acres: ", round(Acres, 1), "<br>")),popup_desc =ifelse(is.na(Sidebar_DE) | Sidebar_DE =="", "", paste0("Description: ", substr(Sidebar_DE, 1, 200), "...")),popup_text =paste0("<b>", popup_name, "</b><br>", popup_type, popup_acres, popup_desc) ) %>%select(-popup_name, -popup_type, -popup_acres, -popup_desc)# Create color palette for shapefile polygons (for ggplot)if ("TYPE"%in%names(mitigation_sites_sf)) { site_types <-unique(mitigation_sites_sf$TYPE) site_types <- site_types[!is.na(site_types)]# Create named vector of colors for ggplot n_types <-length(site_types) site_colors_vec <- RColorBrewer::brewer.pal(min(n_types, 8), "Set2")if (n_types >8) { site_colors_vec <-c(site_colors_vec, RColorBrewer::brewer.pal(min(n_types -8, 9), "Set1")) } site_colors <-setNames(site_colors_vec[1:n_types], site_types)} else { site_colors <-NULL}# Prepare CSV table data - simplified to just POPUP NAME for testingpopup_col <-if ("POPUP NAME"%in%names(mitigation_data)) "POPUP NAME"elseif ("POPUP_NAME"%in%names(mitigation_data)) "POPUP_NAME"elseNULLif (!is.null(popup_col) && popup_col %in%names(mitigation_data)) { mitigation_table_data <- mitigation_data %>%select(all_of(popup_col)) %>%rename(`POPUP NAME`=all_of(popup_col))} else { mitigation_table_data <-data.frame(`POPUP NAME`=character(0))}# Prepare shapefile table datashapefile_table_data <- mitigation_sites_sf %>%st_drop_geometry() %>%select(Name, TYPE, Acres, Sidebar_DE, UID) %>%mutate(Acres =round(Acres, 1))colnames(shapefile_table_data) <-gsub("_", " ", colnames(shapefile_table_data))# Create filtered versions for maps only (exclude Haiwee for better zoom)# Original data remains unfiltered for tables and downloadspopup_name_col <-if ("POPUP NAME"%in%names(mitigation_sf)) "POPUP NAME"elseif ("POPUP_NAME"%in%names(mitigation_sf)) "POPUP_NAME"elseNULLif (!is.null(popup_name_col)) { mitigation_sf_map <- mitigation_sf %>%filter(!grepl("Haiwee|haiwee", !!sym(popup_name_col), ignore.case =TRUE))} else { mitigation_sf_map <- mitigation_sf}# Create filtered version of shapefile for maps onlymitigation_sites_sf_map <- mitigation_sites_sf %>%filter(!grepl("Haiwee|haiwee", Name, ignore.case =TRUE))cat("Setup complete. Data loaded and prepared.\n")
Setup complete. Data loaded and prepared.
Data Descriptions
CSV Points Data Description
Code
cat("=== CSV Points Data Description ===\n")
=== CSV Points Data Description ===
Code
cat("Total rows:", nrow(mitigation_data), "\n")
Total rows: 76
Code
cat("Rows with valid coordinates:", nrow(mitigation_data), "\n")
spc_tbl_ [76 × 23] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
$ UID : num [1:76] 1 2 3 4 5 6 7 8 9 10 ...
$ NOTES : chr [1:76] NA NA NA NA ...
$ Latitude : num [1:76] 37.2 36.7 36.8 36.8 37.3 ...
$ Longitude : num [1:76] -118 -118 -118 -118 -118 ...
$ ACRES : num [1:76] 364 256 3 87 27 3 6 80 5 79 ...
$ PROJECT_TYPE_2 : chr [1:76] "Habitat" "Habitat" "Habitat" "Habitat" ...
$ POPUP NAME : chr [1:76] "Yellow Billed Cuckoo Habitat, Baker Creek" "Yellow Billed Cuckoo Habitat, Hogback Creek" "Well 368" "Homestead" ...
$ POLYGON_LAYER_ID: chr [1:76] "Yellow Billed Cuckoo Habitat Baker Creek" "Yellow Billed Cuckoo Habitat Hogback Creek" "Well 368 - 1600 AF" "Homestead - 1600 AF" ...
$ TYPE : chr [1:76] "MOU" "MOU" "MOU, 1600 AF" "MOU, 1600 AF" ...
$ ORIGIN : chr [1:76] "<a href=\"https://www.inyowater.org/documents/governing-documents/mou/\">MOU Section III.A.1</a>" "<a href=\"https://www.inyowater.org/documents/governing-documents/mou/\">MOU Section III.A.1</a>" "<a href=\"https://www.inyowater.org/documents/governing-documents/mou/\">MOU Section III.A.3</a>" "<a href=\"https://www.inyowater.org/documents/governing-documents/mou/\">MOU Section III.A.3</a>" ...
$ ORIGIN_2 : chr [1:76] "<a href=\"https://www.inyowater.org/wp-content/uploads/legacy/Mitigation/additional_mitigation_sites/AD%20HOC%2"| __truncated__ "<a href=\"https://www.inyowater.org/wp-content/uploads/legacy/Mitigation/additional_mitigation_sites/AD%20HOC%2"| __truncated__ "<a href=\"https://www.inyowater.org/wp-content/uploads/legacy/Mitigation/additional_mitigation_sites/AD%20HOC%2"| __truncated__ "<a href=\"https://www.inyowater.org/wp-content/uploads/legacy/Mitigation/additional_mitigation_sites/AD%20HOC%2"| __truncated__ ...
$ ORIGIN_3 : chr [1:76] "<a href=\"https://www.inyowater.org/wp-content/uploads/legacy/Mitigation/ybcu/YBC_MND_12Nov2009.pdf\">Mitigated"| __truncated__ "<a href=\"https://www.inyowater.org/wp-content/uploads/legacy/Mitigation/ybcu/YBC_MND_12Nov2009.pdf\">Mitigated"| __truncated__ NA NA ...
$ Project_Status : chr [1:76] "Implemented and ongoing" "Implemented and ongoing" "Implemented and ongoing" "Fully implemented, but not meeting goals" ...
$ STAT_NUM : num [1:76] 50 50 50 50 50 50 50 50 50 50 ...
$ STAT_DESCRP : chr [1:76] "The project area has burned multiple times, which had limited the effectiveness of habitat enhancement efforts." "The project area has maintained a good cover of mature tree canopy. Avian surveys have not been conducted. The "| __truncated__ "The aquatic habitat sustained by this flow has diminished in recent years, likely due to changes in the waterco"| __truncated__ "Beneficial riparian habitat has developed; however, a key component of the project is the establishment of a on"| __truncated__ ...
$ DESCRIPTION : chr [1:76] "This habitat project is designed to enhance vegetation, including tree planting, to enlarge and augment existing YBC habitat." "This habitat project, guided by a land management plan, includes tree planting to enlarge and enhance existing YBC habitat." "This Additional Mitigation habitat project will create and maintain riparian, aquatic and spring habitats. It a"| __truncated__ "This Additional Mitigation habitat project will create riparian, wetland, spring, and pond habitats and improve"| __truncated__ ...
$ IMPACT : chr [1:76] "Enlarges and enhances YBC habitat at Baker Creek." "Enlarges and enhances YBC habitat at Hogback Creek." "Provides riparian, aquatic, and spring habitat." "Provides riparian, wetland, and spring habitats." ...
$ DISCUSSION : logi [1:76] NA NA NA NA NA NA ...
$ WATER_DELIVERY : logi [1:76] NA NA NA NA NA NA ...
$ STUDIES_PROJECTS: logi [1:76] NA NA NA NA NA NA ...
$ ESTB_PTOTO : chr [1:76] "https://inyocounty.maps.arcgis.com/sharing/rest/content/items/43d57c17cbd34436a8a50b84b7adc54c/data" "https://inyocounty.maps.arcgis.com/sharing/rest/content/items/43d57c17cbd34436a8a50b84b7adc54c/data" "https://inyocounty.maps.arcgis.com/sharing/rest/content/items/7fe98a5b4bd04a818e3102de231a9f84/data" "https://inyocounty.maps.arcgis.com/sharing/rest/content/items/6ea6d36ef8e54a5bae0da58510e548a7/data" ...
$ ADDL_RESOURCES : chr [1:76] "<a href=\"https://www.dropbox.com/sh/n0s2svmu1zxkmch/AADwbyZkzNMF4dy6MpSKI-xQa?dl=0\">Additional Resources</a>" "<a href=\"https://www.dropbox.com/sh/n0s2svmu1zxkmch/AADwbyZkzNMF4dy6MpSKI-xQa?dl=0\">Additional Resources</a>" NA "<a href=\"https://www.dropbox.com/sh/r9tz240hizb0r7v/AADzeSzDKwZybyBIYllMEImVa?dl=0https://www.dropbox.com/sh/r"| __truncated__ ...
$ ADDL_PHOTOS : chr [1:76] NA NA NA NA ...
Latitude Longitude Acres UID ObjectID_1 UID_1
1 37.16063 -118.3196 363.509663 1 0 1
2 36.65578 -118.1474 256.336871 2 0 2
3 36.77049 -118.1240 2.965389 3 0 3
Name TYPE
1 Yellow Billed Cuckoo Habitat, Baker Creek Habitat MOU
2 Yellow Billed Cuckoo Habitat, Hogback Creek Habitat MOU
3 Well 368 Habitat MOU 1600 AF
Sidebar_DE
1 This project, west of Big Pine, utilizes tree planting and other means to enhance and enlarge habitat for endangered Yellow-Billed Cuckoo
2 This project, north of Lone Pine, supports suitable habitat for endangered Yellow-Billed Cuckoo
3 Artesian well water is provided to create riparian, aquatic and spring habitats in support of the Owens Valley Pupfish
Sidebar_Ph
1 https://inyocounty.maps.arcgis.com/sharing/rest/content/items/70dde4f3b80d4850a81d58d93d218f74/data
2 https://inyocounty.maps.arcgis.com/sharing/rest/content/items/5dc47b1f0e954a568ca2a036117eaa9c/data
3 https://inyocounty.maps.arcgis.com/sharing/rest/content/items/1fca5c488e9c49b1ac7d1c62529fcb6c/data
ObjectID_2 Shape__Are Shape__Len
1 1 1.492299e-04 0.074855450
2 2 1.045505e-04 0.135242732
3 3 1.211251e-06 0.009144914
popup_text
1 <b>Yellow Billed Cuckoo Habitat, Baker Creek</b><br>Type: Habitat MOU<br>Acres: 363.5<br>Description: This project, west of Big Pine, utilizes tree planting and other means to enhance and enlarge habitat for endangered Yellow-Billed Cuckoo...
2 <b>Yellow Billed Cuckoo Habitat, Hogback Creek</b><br>Type: Habitat MOU<br>Acres: 256.3<br>Description: This project, north of Lone Pine, supports suitable habitat for endangered Yellow-Billed Cuckoo...
3 <b>Well 368</b><br>Type: Habitat MOU 1600 AF<br>Acres: 3<br>Description: Artesian well water is provided to create riparian, aquatic and spring habitats in support of the Owens Valley Pupfish...
Interactive Data Tables
CSV Points Data
This table shows data from the CSV file, which includes real-time updates on project status.
Total rows: 76
# A tibble: 76 × 1
`POPUP NAME`
<chr>
1 Yellow Billed Cuckoo Habitat, Baker Creek
2 Yellow Billed Cuckoo Habitat, Hogback Creek
3 Well 368
4 Homestead
5 Freeman Creek
6 Hines Springs, Well 355
7 Hines Springs, Aberdeen Ditch
8 Warren Lake
9 North of Mazourka Canyon Rd
10 Diaz Lake
11 640 Acres Near Laws Revegetation
12 Lone Pine East Side Regreening
13 Lone Pine Woodlot
14 Lone Pine Sports Complex
15 Richards Field
16 Van Norman Field
17 Lone Pine West Side Regreening
18 Lone Pine Riparian Park
19 Eastern California Museum
20 Independence Roadside Rest Area
21 Independence Woodlot
22 Independence Eastside Regreening
23 Independence Springfield
24 Independence Pasturelands
25 Big Pine Northeast Regreening
26 McNally Ponds and Native Pasture
27 Bishop Area Revegetation
28 Shepherd Creek Alfalfa Field
29 Billy Lake
30 Twin Lakes
31 Goose Lake
32 Laws Historical Museum Irrigated Pastures
33 Laws/Poleta Native Pasture
34 Farmers Pond
35 Five Bridges Revegetation
36 Buckley Ponds
37 140 Acres Near Laws Revegetation
38 Klondike Lake
39 Independence Ditch
40 Big Pine Area Revegetation, 160 Acres
41 Steward Ranch
42 Fish Springs Hatchery
43 Blackrock 16E Revegetation
44 Hines Spring South Revegetation
45 Little Blackrock Springs
46 Blackrock Hatchery (Big Blackrock Springs)
47 Independence 105 Revegetation
48 Independence 131 South Revegetation
49 Independence 131 North Revegetation
50 Independence 123 Revegetation
51 Reinhackle Spring
52 Big and Little Seely Springs
53 Big Pine Area Revegetation, 20 Acres
54 Millpond
55 Klondike Lake South Shore Habitat Area
56 Tule Elk Field
57 Haiwee Reservoir
58 Calvert Slough
59 Saunders Pond
60 Delta Habitat Area
61 River Pumpback Facility
62 Islands Area
63 River Intake Structure
64 Drew Unit
65 Winterton Unit
66 Waggoner Unit
67 Thibaut Unit
68 Laws 27 Irrigated Revegetation
69 Laws 90 Irrigated Revegetation
70 Laws 95 Irrigated Revegetation
71 Laws 94 Irrigated Revegetation
72 Laws 129/118 Irrigated Revegetation
73 Lower Owens River
74 Tinemaha 54 Revegetation
75 Big Pine Ditch
76 Laws/Poleta Native Pasture
Mitigation Polygons Data
This table shows data from the mitigation polygons.
Project Name Comparison
This section compares project names between the CSV points and mitigation polygons to identify projects that appear in one dataset but not the other.
=== Project Comparison Summary ===
Total projects in CSV (after filtering): 75
Total projects in Shapefile (after filtering): 75
Projects in BOTH datasets: 75
Projects ONLY in CSV: 0
Projects ONLY in Shapefile: 0
=== Projects in BOTH Datasets ( 75 projects) ===
Project_Name In_CSV In_Shapefile
140 Acres Near Laws Revegetation Yes Yes
640 Acres Near Laws Revegetation Yes Yes
Big and Little Seely Springs Yes Yes
Big Pine Area Revegetation, 160 Acres Yes Yes
Big Pine Area Revegetation, 20 Acres Yes Yes
Big Pine Ditch Yes Yes
Big Pine Northeast Regreening Yes Yes
Billy Lake Yes Yes
Bishop Area Revegetation Yes Yes
Blackrock 16E Revegetation Yes Yes
Blackrock Hatchery (Big Blackrock Springs) Yes Yes
Buckley Ponds Yes Yes
Calvert Slough Yes Yes
Delta Habitat Area Yes Yes
Diaz Lake Yes Yes
Drew Unit Yes Yes
Eastern California Museum Yes Yes
Farmers Pond Yes Yes
Fish Springs Hatchery Yes Yes
Five Bridges Revegetation Yes Yes
Freeman Creek Yes Yes
Goose Lake Yes Yes
Haiwee Reservoir Yes Yes
Hines Spring South Revegetation Yes Yes
Hines Springs, Aberdeen Ditch Yes Yes
Hines Springs, Well 355 Yes Yes
Homestead Yes Yes
Independence 105 Revegetation Yes Yes
Independence 123 Revegetation Yes Yes
Independence 131 North Revegetation Yes Yes
Independence 131 South Revegetation Yes Yes
Independence Ditch Yes Yes
Independence Eastside Regreening Yes Yes
Independence Pasturelands Yes Yes
Independence Roadside Rest Area Yes Yes
Independence Springfield Yes Yes
Independence Woodlot Yes Yes
Islands Area Yes Yes
Klondike Lake Yes Yes
Klondike Lake South Shore Habitat Area Yes Yes
Laws 129/118 Irrigated Revegetation Yes Yes
Laws 27 Irrigated Revegetation Yes Yes
Laws 90 Irrigated Revegetation Yes Yes
Laws 94 Irrigated Revegetation Yes Yes
Laws 95 Irrigated Revegetation Yes Yes
Laws Historical Museum Irrigated Pastures Yes Yes
Laws/Poleta Native Pasture Yes Yes
Little Blackrock Springs Yes Yes
Lone Pine East Side Regreening Yes Yes
Lone Pine Riparian Park Yes Yes
Lone Pine Sports Complex Yes Yes
Lone Pine West Side Regreening Yes Yes
Lone Pine Woodlot Yes Yes
Lower Owens River Yes Yes
McNally Ponds and Native Pasture Yes Yes
Millpond Yes Yes
North of Mazourka Canyon Rd Yes Yes
Reinhackle Spring Yes Yes
Richards Field Yes Yes
River Intake Structure Yes Yes
River Pumpback Facility Yes Yes
Saunders Pond Yes Yes
Shepherd Creek Alfalfa Field Yes Yes
Steward Ranch Yes Yes
Thibaut Unit Yes Yes
Tinemaha 54 Revegetation Yes Yes
Tule Elk Field Yes Yes
Twin Lakes Yes Yes
Van Norman Field Yes Yes
Waggoner Unit Yes Yes
Warren Lake Yes Yes
Well 368 Yes Yes
Winterton Unit Yes Yes
Yellow Billed Cuckoo Habitat, Baker Creek Yes Yes
Yellow Billed Cuckoo Habitat, Hogback Creek Yes Yes
Maps
CSV Points - 2025 Status
Map showing mitigation project points from CSV data with project names labeled. Note: Haiwee site not shown.
Mitigation Polygons
Map showing mitigation polygons with project names labeled.
Source Code
---title: "Data Processing"format: html: theme: cosmo toc: true toc-depth: 2 code-fold: true code-tools: true embed-resources: true css: styles.cssexecute: echo: true warning: false message: false---## SetupThis section loads and processes the data for visualization and analysis. The setup code also generates the download files available on the main page.```{r setup}#| echo: true#| message: false#| warning: false# Load all required librarieslibrary(DT)library(ggplot2)library(ggrepel)library(sf)library(dplyr)library(readr)library(RColorBrewer)# Export data for downloads (same code as index.qmd setup)# Load CSV datamitigation_data_export <-read_csv("data/gis/Mitigation_PointsAGOL.csv", show_col_types =FALSE)mitigation_data_export <- mitigation_data_export %>%filter(!is.na(Latitude) &!is.na(Longitude))# Normalize project namespopup_name_col_export <-if ("POPUP NAME"%in%names(mitigation_data_export)) "POPUP NAME"elseif ("POPUP_NAME"%in%names(mitigation_data_export)) "POPUP_NAME"elseNULLif (!is.null(popup_name_col_export)) { mitigation_data_export[[popup_name_col_export]] <-gsub("129/ 118", "129/118", mitigation_data_export[[popup_name_col_export]], fixed =TRUE) mitigation_data_export[[popup_name_col_export]] <-gsub(" ", " ", mitigation_data_export[[popup_name_col_export]]) mitigation_data_export[[popup_name_col_export]] <-trimws(mitigation_data_export[[popup_name_col_export]])}# Convert CSV to spatial pointsmitigation_sf_export <-st_as_sf( mitigation_data_export,coords =c("Longitude", "Latitude"),crs =4326)# Load shapefile datamitigation_sites_sf_export <-st_read("data/gis/mit_points/mitigation_sites.shp", quiet =TRUE) %>%st_transform(4326)# Export dataif (!dir.exists("output")) dir.create("output", recursive =TRUE)if (!dir.exists("docs")) dir.create("docs", recursive =TRUE)tryCatch({write_sf(mitigation_sf_export, "output/mitigation_points.geojson", delete_dsn =TRUE)write_sf(mitigation_sf_export, "docs/mitigation_points.geojson", delete_dsn =TRUE)}, error =function(e) cat("Warning: Could not export CSV points to GeoJSON\n"))tryCatch({if (exists("mitigation_sites_sf_export") &&nrow(mitigation_sites_sf_export) >0) { mitigation_sites_sf_geojson <-st_cast(mitigation_sites_sf_export, "MULTIPOLYGON") %>%st_cast("POLYGON") %>%st_simplify(dTolerance =0.001)write_sf(mitigation_sites_sf_geojson, "output/mitigation_sites.geojson", delete_dsn =TRUE)write_sf(mitigation_sites_sf_geojson, "docs/mitigation_sites.geojson", delete_dsn =TRUE) }}, error =function(e) cat("Warning: Could not export shapefile polygons to GeoJSON:", conditionMessage(e), "\n"))if (!dir.exists("output/mitigation_points_shp")) dir.create("output/mitigation_points_shp", recursive =TRUE)if (!dir.exists("docs/mitigation_points_shp")) dir.create("docs/mitigation_points_shp", recursive =TRUE)tryCatch({st_write(mitigation_sf_export, "output/mitigation_points_shp/mitigation_points.shp", delete_dsn =TRUE)st_write(mitigation_sf_export, "docs/mitigation_points_shp/mitigation_points.shp", delete_dsn =TRUE)zip("output/mitigation_points_shp.zip", list.files("output/mitigation_points_shp", full.names =TRUE),flags ="-j")file.copy("output/mitigation_points_shp.zip", "docs/mitigation_points_shp.zip", overwrite =TRUE)}, error =function(e) cat("Warning: Could not export CSV points shapefile\n"))if (!dir.exists("output/mitigation_sites_shp")) dir.create("output/mitigation_sites_shp", recursive =TRUE)if (!dir.exists("docs/mitigation_sites_shp")) dir.create("docs/mitigation_sites_shp", recursive =TRUE)tryCatch({if (exists("mitigation_sites_sf_export") &&nrow(mitigation_sites_sf_export) >0) { mitigation_sites_sf_simple <-st_cast(mitigation_sites_sf_export, "MULTIPOLYGON") %>%st_cast("POLYGON") %>%st_simplify(dTolerance =0.001)st_write(mitigation_sites_sf_simple, "output/mitigation_sites_shp/mitigation_sites.shp", delete_dsn =TRUE)st_write(mitigation_sites_sf_simple, "docs/mitigation_sites_shp/mitigation_sites.shp", delete_dsn =TRUE) shp_files <-list.files("output/mitigation_sites_shp", full.names =TRUE, pattern ="\\.(shp|shx|dbf|prj)$")if (length(shp_files) >0) {zip("output/mitigation_sites_shp.zip", shp_files, flags ="-j")if (file.exists("output/mitigation_sites_shp.zip")) {file.copy("output/mitigation_sites_shp.zip", "docs/mitigation_sites_shp.zip", overwrite =TRUE) } } }}, error =function(e) cat("Warning: Could not export polygon shapefile:", conditionMessage(e), "\n"))# Load CSV datamitigation_data <-read_csv("data/gis/Mitigation_PointsAGOL.csv", show_col_types =FALSE)mitigation_data <- mitigation_data %>%filter(!is.na(Latitude) &!is.na(Longitude))# Normalize project names to match shapefile naming (remove extra spaces)popup_name_col <-if ("POPUP NAME"%in%names(mitigation_data)) "POPUP NAME"elseif ("POPUP_NAME"%in%names(mitigation_data)) "POPUP_NAME"elseNULLif (!is.null(popup_name_col)) { mitigation_data[[popup_name_col]] <-gsub("129/ 118", "129/118", mitigation_data[[popup_name_col]], fixed =TRUE)# Also normalize any other common spacing issues mitigation_data[[popup_name_col]] <-gsub(" ", " ", mitigation_data[[popup_name_col]]) # Remove double spaces mitigation_data[[popup_name_col]] <-trimws(mitigation_data[[popup_name_col]]) # Trim whitespace}# Convert CSV to spatial pointsmitigation_sf <-st_as_sf( mitigation_data,coords =c("Longitude", "Latitude"),crs =4326)# Create popup text for CSV pointspopup_name_col <-if ("POPUP NAME"%in%names(mitigation_sf)) "POPUP NAME"elseif ("POPUP_NAME"%in%names(mitigation_sf)) "POPUP_NAME"elseNULLif (!is.null(popup_name_col)) { project_names <-ifelse(is.na(mitigation_sf[[popup_name_col]]), "Project", mitigation_sf[[popup_name_col]])} else { project_names <-rep("Project", nrow(mitigation_sf))}mitigation_sf$popup_text <-paste0("<b>", project_names, "</b><br>",ifelse(!is.na(mitigation_sf$PROJECT_TYPE_2), paste0("Type: ", mitigation_sf$PROJECT_TYPE_2, "<br>"), ""),ifelse(!is.na(mitigation_sf$ACRES), paste0("Acres: ", mitigation_sf$ACRES, "<br>"), ""),ifelse(!is.na(mitigation_sf$Project_Status), paste0("Status: ", mitigation_sf$Project_Status, "<br>"), ""),ifelse(!is.na(mitigation_sf$DESCRIPTION), paste0("Description: ", substr(mitigation_sf$DESCRIPTION, 1, 200), "..."), ""))# Create color palette for CSV points (for ggplot)if ("PROJECT_TYPE_2"%in%names(mitigation_sf)) { project_types <-unique(mitigation_sf$PROJECT_TYPE_2) project_types <- project_types[!is.na(project_types)]# Create named vector of colors for ggplot n_types <-length(project_types) project_colors_vec <- RColorBrewer::brewer.pal(min(n_types, 9), "Set1")if (n_types >9) { project_colors_vec <-c(project_colors_vec, RColorBrewer::brewer.pal(min(n_types -9, 8), "Set2")) } project_colors <-setNames(project_colors_vec[1:n_types], project_types)} else { project_colors <-NULL}# Load shapefile datamitigation_sites_sf <-st_read("data/gis/mit_points/mitigation_sites.shp", quiet =TRUE) %>%st_transform(4326)# Create popup text for shapefile polygonsmitigation_sites_sf <- mitigation_sites_sf %>%mutate(popup_name =ifelse(is.na(Name) | Name =="", "Project", as.character(Name)),popup_type =ifelse(is.na(TYPE) | TYPE =="", "", paste0("Type: ", TYPE, "<br>")),popup_acres =ifelse(is.na(Acres), "", paste0("Acres: ", round(Acres, 1), "<br>")),popup_desc =ifelse(is.na(Sidebar_DE) | Sidebar_DE =="", "", paste0("Description: ", substr(Sidebar_DE, 1, 200), "...")),popup_text =paste0("<b>", popup_name, "</b><br>", popup_type, popup_acres, popup_desc) ) %>%select(-popup_name, -popup_type, -popup_acres, -popup_desc)# Create color palette for shapefile polygons (for ggplot)if ("TYPE"%in%names(mitigation_sites_sf)) { site_types <-unique(mitigation_sites_sf$TYPE) site_types <- site_types[!is.na(site_types)]# Create named vector of colors for ggplot n_types <-length(site_types) site_colors_vec <- RColorBrewer::brewer.pal(min(n_types, 8), "Set2")if (n_types >8) { site_colors_vec <-c(site_colors_vec, RColorBrewer::brewer.pal(min(n_types -8, 9), "Set1")) } site_colors <-setNames(site_colors_vec[1:n_types], site_types)} else { site_colors <-NULL}# Prepare CSV table data - simplified to just POPUP NAME for testingpopup_col <-if ("POPUP NAME"%in%names(mitigation_data)) "POPUP NAME"elseif ("POPUP_NAME"%in%names(mitigation_data)) "POPUP_NAME"elseNULLif (!is.null(popup_col) && popup_col %in%names(mitigation_data)) { mitigation_table_data <- mitigation_data %>%select(all_of(popup_col)) %>%rename(`POPUP NAME`=all_of(popup_col))} else { mitigation_table_data <-data.frame(`POPUP NAME`=character(0))}# Prepare shapefile table datashapefile_table_data <- mitigation_sites_sf %>%st_drop_geometry() %>%select(Name, TYPE, Acres, Sidebar_DE, UID) %>%mutate(Acres =round(Acres, 1))colnames(shapefile_table_data) <-gsub("_", " ", colnames(shapefile_table_data))# Create filtered versions for maps only (exclude Haiwee for better zoom)# Original data remains unfiltered for tables and downloadspopup_name_col <-if ("POPUP NAME"%in%names(mitigation_sf)) "POPUP NAME"elseif ("POPUP_NAME"%in%names(mitigation_sf)) "POPUP_NAME"elseNULLif (!is.null(popup_name_col)) { mitigation_sf_map <- mitigation_sf %>%filter(!grepl("Haiwee|haiwee", !!sym(popup_name_col), ignore.case =TRUE))} else { mitigation_sf_map <- mitigation_sf}# Create filtered version of shapefile for maps onlymitigation_sites_sf_map <- mitigation_sites_sf %>%filter(!grepl("Haiwee|haiwee", Name, ignore.case =TRUE))cat("Setup complete. Data loaded and prepared.\n")```## Data Descriptions### CSV Points Data Description```{r csv-data-description}#| echo: truecat("=== CSV Points Data Description ===\n")cat("Total rows:", nrow(mitigation_data), "\n")cat("Rows with valid coordinates:", nrow(mitigation_data), "\n")cat("Columns:", ncol(mitigation_data), "\n")cat("\nGeometry Information:\n")cat("Geometry type:", st_geometry_type(mitigation_sf, by_geometry =FALSE), "\n")cat("Unique geometry types:", paste(unique(st_geometry_type(mitigation_sf)), collapse =", "), "\n")cat("Has geometry column:", !is.null(st_geometry(mitigation_sf)), "\n")cat("\nColumn names:\n")print(names(mitigation_data))cat("\nData structure:\n")str(mitigation_data, give.attr =FALSE)cat("\nFirst few rows:\n")print(head(mitigation_data, 3))```### Mitigation Polygons Data Description```{r shapefile-data-description}#| echo: truecat("=== Mitigation Polygons Data Description ===\n")cat("Total rows:", nrow(mitigation_sites_sf), "\n")cat("Columns:", ncol(mitigation_sites_sf), "\n")cat("\nGeometry Information:\n")cat("Geometry type:", st_geometry_type(mitigation_sites_sf, by_geometry =FALSE), "\n")cat("Unique geometry types:", paste(unique(st_geometry_type(mitigation_sites_sf)), collapse =", "), "\n")cat("Has geometry column:", !is.null(st_geometry(mitigation_sites_sf)), "\n")cat("\nGeometry type breakdown:\n")geom_types <-st_geometry_type(mitigation_sites_sf)geom_type_table <-table(geom_types)print(geom_type_table)cat("\nColumn names:\n")print(names(mitigation_sites_sf %>%st_drop_geometry()))cat("\nData structure:\n")str(mitigation_sites_sf %>%st_drop_geometry(), give.attr =FALSE)cat("\nFirst few rows:\n")print(head(mitigation_sites_sf %>%st_drop_geometry(), 3))```## Interactive Data Tables### CSV Points DataThis table shows data from the CSV file, which includes real-time updates on project status.```{r csv-points-table}#| echo: false# Test with simple print table first - show all rowscat("Total rows:", nrow(mitigation_table_data), "\n")print(mitigation_table_data, n =Inf)# Also try DT tableDT::datatable( mitigation_table_data,caption ='Mitigation Points from CSV - Includes Real-Time Project Status Updates',filter ='top',elementId ='csv-points-table',options =list(pageLength =-1,scrollX =TRUE,dom ='Blfrtip',buttons =c('copy', 'csv', 'excel', 'pdf', 'print'),columnDefs =list(list(targets ='_all', className ='dt-wrap') ),autoWidth =TRUE,lengthMenu =list(c(10, 25, 50, 100, -1), c('10', '25', '50', '100', 'All')) ),rownames =FALSE,extensions =c('Buttons', 'Scroller'),escape =FALSE,style ='bootstrap',callback = htmlwidgets::JS(" function(settings) { var api = new $.fn.dataTable.Api(settings); api.on('draw', function() { $(api.table().container()).find('td, th').css({ 'white-space': 'normal', 'word-wrap': 'break-word', 'word-break': 'break-word', 'overflow-wrap': 'break-word' }); }); $(api.table().container()).find('td, th').css({ 'white-space': 'normal', 'word-wrap': 'break-word', 'word-break': 'break-word', 'overflow-wrap': 'break-word' }); } "))```### Mitigation Polygons DataThis table shows data from the mitigation polygons.```{r shapefile-polygons-table}#| echo: falseDT::datatable( shapefile_table_data,caption ='Mitigation Polygons Data',filter ='top',elementId ='shapefile-polygons-table',options =list(pageLength =-1,scrollX =TRUE,scrollY ='600px',dom ='Blfrtip',buttons =c('copy', 'csv', 'excel', 'pdf', 'print'),columnDefs =list(list(className ='dt-center', targets =which(colnames(shapefile_table_data) %in%c('Acres', 'UID'))),list(targets ='_all', className ='dt-wrap') ),autoWidth =TRUE,lengthMenu =list(c(10, 25, 50, 100, -1), c('10', '25', '50', '100', 'All')) ),rownames =FALSE,extensions =c('Buttons', 'Scroller'),escape =FALSE,style ='bootstrap',callback = htmlwidgets::JS(" function(settings) { var api = new $.fn.dataTable.Api(settings); api.on('draw', function() { $(api.table().container()).find('td, th').css({ 'white-space': 'normal', 'word-wrap': 'break-word', 'word-break': 'break-word', 'overflow-wrap': 'break-word' }); }); $(api.table().container()).find('td, th').css({ 'white-space': 'normal', 'word-wrap': 'break-word', 'word-break': 'break-word', 'overflow-wrap': 'break-word' }); } "))```### Project Name ComparisonThis section compares project names between the CSV points and mitigation polygons to identify projects that appear in one dataset but not the other.```{r project-comparison}#| echo: false# Get project names from CSV (unfiltered for comparison)popup_name_col <-if ("POPUP NAME"%in%names(mitigation_data)) "POPUP NAME"elseif ("POPUP_NAME"%in%names(mitigation_data)) "POPUP_NAME"elseNULLif (!is.null(popup_name_col)) { csv_projects <- mitigation_data %>%pull(!!sym(popup_name_col)) %>%unique() %>%sort()} else { csv_projects <-character(0)}# Get project names from shapefile (unfiltered for comparison)shapefile_projects <- mitigation_sites_sf %>%st_drop_geometry() %>%pull(Name) %>%unique() %>%sort()# Find differencescsv_only <-setdiff(csv_projects, shapefile_projects)shapefile_only <-setdiff(shapefile_projects, csv_projects)in_both <-intersect(csv_projects, shapefile_projects)# Print summary statisticscat("=== Project Comparison Summary ===\n\n")cat("Total projects in CSV (after filtering):", length(csv_projects), "\n")cat("Total projects in Shapefile (after filtering):", length(shapefile_projects), "\n")cat("Projects in BOTH datasets:", length(in_both), "\n")cat("Projects ONLY in CSV:", length(csv_only), "\n")cat("Projects ONLY in Shapefile:", length(shapefile_only), "\n\n")# Create detailed comparison tablesif (length(in_both) >0) {cat("=== Projects in BOTH Datasets (", length(in_both), " projects) ===\n") in_both_df <-data.frame(Project_Name = in_both,In_CSV ="Yes",In_Shapefile ="Yes" )print(in_both_df, row.names =FALSE)cat("\n")}if (length(csv_only) >0) {cat("=== Projects ONLY in CSV Dataset (", length(csv_only), " projects) ===\n") csv_only_df <-data.frame(Project_Name = csv_only,In_CSV ="Yes",In_Shapefile ="No" )print(csv_only_df, row.names =FALSE)cat("\n")}if (length(shapefile_only) >0) {cat("=== Projects ONLY in Shapefile Dataset (", length(shapefile_only), " projects) ===\n") shapefile_only_df <-data.frame(Project_Name = shapefile_only,In_CSV ="No",In_Shapefile ="Yes" )print(shapefile_only_df, row.names =FALSE)cat("\n")}# Create interactive comparison tablecomparison_detailed <-data.frame(Project_Name =c(if (length(in_both) >0) in_both elsecharacter(0),if (length(csv_only) >0) csv_only elsecharacter(0),if (length(shapefile_only) >0) shapefile_only elsecharacter(0) ),In_CSV =c(if (length(in_both) >0) rep("Yes", length(in_both)) elsecharacter(0),if (length(csv_only) >0) rep("Yes", length(csv_only)) elsecharacter(0),if (length(shapefile_only) >0) rep("No", length(shapefile_only)) elsecharacter(0) ),In_Shapefile =c(if (length(in_both) >0) rep("Yes", length(in_both)) elsecharacter(0),if (length(csv_only) >0) rep("No", length(csv_only)) elsecharacter(0),if (length(shapefile_only) >0) rep("Yes", length(shapefile_only)) elsecharacter(0) ),Status =c(if (length(in_both) >0) rep("In Both", length(in_both)) elsecharacter(0),if (length(csv_only) >0) rep("CSV Only", length(csv_only)) elsecharacter(0),if (length(shapefile_only) >0) rep("Shapefile Only", length(shapefile_only)) elsecharacter(0) ))if (nrow(comparison_detailed) >0) { DT::datatable( comparison_detailed,caption ='Detailed Project Comparison: CSV Points vs Mitigation Polygons',filter ='top',elementId ='project-comparison-table',options =list(pageLength =-1,scrollX =TRUE,scrollY ='600px',dom ='Blfrtip',buttons =c('copy', 'csv', 'excel', 'pdf', 'print'),columnDefs =list(list(className ='dt-center', targets =c(1, 2, 3)),list(targets ='_all', className ='dt-wrap') ),autoWidth =TRUE,lengthMenu =list(c(10, 25, 50, 100, -1), c('10', '25', '50', '100', 'All')),order =list(list(3, 'asc'), list(0, 'asc')) # Sort by Status, then Project Name ),rownames =FALSE,extensions =c('Buttons', 'Scroller'),escape =FALSE,style ='bootstrap',callback = htmlwidgets::JS(" function(settings) { var api = new $.fn.dataTable.Api(settings); api.on('draw', function() { $(api.table().container()).find('td, th').css({ 'white-space': 'normal', 'word-wrap': 'break-word', 'word-break': 'break-word', 'overflow-wrap': 'break-word' }); }); $(api.table().container()).find('td, th').css({ 'white-space': 'normal', 'word-wrap': 'break-word', 'word-break': 'break-word', 'overflow-wrap': 'break-word' }); } ") )} else {cat("No projects found for comparison.\n")}```## Maps### CSV Points - 2025 Status```{r csv-points-map}#| echo: false#| fig-cap: "Map showing mitigation project points from CSV data with project names labeled. Note: Haiwee site not shown."#| fig-width: 24#| fig-height: 16if (exists("mitigation_sf_map") &&nrow(mitigation_sf_map) >0) {# Get bounding box for map extent bbox <-st_bbox(mitigation_sf_map)# Create ggplot map p <-ggplot() +geom_sf(data = mitigation_sf_map,aes(color =if(!is.null(project_colors) &&"PROJECT_TYPE_2"%in%names(mitigation_sf_map)) PROJECT_TYPE_2 elseNULL),size =2,alpha =0.7 ) +geom_text_repel(data = mitigation_sf_map,aes(label =`POPUP NAME`, geometry = geometry),stat ="sf_coordinates",size =2.5,min.segment.length =0,max.overlaps =Inf,box.padding =0.5,point.padding =0.3 ) +coord_sf(xlim =c(bbox["xmin"], bbox["xmax"]),ylim =c(bbox["ymin"], bbox["ymax"]),expand =TRUE ) +theme_minimal() +theme(axis.text =element_text(size =8),axis.title =element_blank(),panel.grid =element_line(color ="gray90", linewidth =0.5),panel.background =element_rect(fill ="white", color =NA),legend.position ="right" )# Add color scale if project types existif (!is.null(project_colors) &&"PROJECT_TYPE_2"%in%names(mitigation_sf_map)) { p <- p +scale_color_manual(values = project_colors,name ="Project Type" ) +guides(color =guide_legend(override.aes =list(size =3))) } else { p <- p +scale_color_manual(values ="#FF0000", guide ="none") }print(p)} else {cat("No data available for map\n")}```### Mitigation Polygons```{r shapefile-polygons-map}#| echo: false#| fig-cap: "Map showing mitigation polygons with project names labeled."#| fig-width: 24#| fig-height: 16if (exists("mitigation_sites_sf_map") &&nrow(mitigation_sites_sf_map) >0) {# Simplify geometry for faster rendering mitigation_sites_sf_simple <-st_simplify(mitigation_sites_sf_map, dTolerance =0.001)# Get centroids for labels centroids <-st_centroid(mitigation_sites_sf_simple) centroids$Name <- mitigation_sites_sf_map$Name# Get bounding box for map extent bbox <-st_bbox(mitigation_sites_sf_simple)# Create ggplot map p <-ggplot() +geom_sf(data = mitigation_sites_sf_simple,aes(fill =if(!is.null(site_colors) &&"TYPE"%in%names(mitigation_sites_sf_simple)) TYPE elseNULL),color =if(!is.null(site_colors) &&"TYPE"%in%names(mitigation_sites_sf_simple)) "white"else"#0066FF",alpha =0.4,linewidth =0.5 ) +geom_sf(data = centroids,size =1,color ="black",alpha =0.6 ) +geom_text_repel(data = centroids,aes(label = Name, geometry = geometry),stat ="sf_coordinates",size =2.5,min.segment.length =0,max.overlaps =Inf,box.padding =0.5,point.padding =0.3 ) +coord_sf(xlim =c(bbox["xmin"], bbox["xmax"]),ylim =c(bbox["ymin"], bbox["ymax"]),expand =TRUE ) +theme_minimal() +theme(axis.text =element_text(size =8),axis.title =element_blank(),panel.grid =element_line(color ="gray90", linewidth =0.5),panel.background =element_rect(fill ="white", color =NA),legend.position ="right" )# Add color scale if types existif (!is.null(site_colors) &&"TYPE"%in%names(mitigation_sites_sf_map)) { p <- p +scale_fill_manual(values = site_colors,name ="Project Type" ) +guides(fill =guide_legend(override.aes =list(alpha =0.7))) } else { p <- p +scale_fill_manual(values ="#0066FF", guide ="none") }print(p)} else {cat("No data available for map\n")}```