Skip to content

Commit aa523ec

Browse files
committed
update OSCAR coordinates
1 parent d8bbc03 commit aa523ec

7 files changed

Lines changed: 311 additions & 440 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,5 @@ analysis/dev-*
5050

5151
# data
5252
data/17parcelles*
53-
data/XYpoint1*
53+
data/XYpoint1*
54+
data/OSCAR_gps*

analysis/03_update_data.R

Lines changed: 32 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
# Read and pre-process the metadata
22
# The input file was sent by Axelle on 27/01/2026
3+
# with update from Sylvie Ladet (Sebiopag_VcG) on 17/12/2026
4+
# with update from Frederic Fabre (OSCAR) on 03/04/2026
35

4-
# Creates one files for the shiny app
6+
# Creates one files for the shiny app
57

68
# load the needed package and functions
79
devtools::load_all()
810
library(sf) |> suppressWarnings()
911

12+
# 1. Load data from Axelle
1013
meta <- read.csv2("data/dataset_coordinates_wCropSpecies.csv")
1114

12-
1315
# guess the coordinate system
1416
proj <- ifelse(meta$Long > 180, "LAMB93", "WGS84")
1517
# transform LAMB93 to WGS84
@@ -20,6 +22,8 @@ coo_4326 <- st_coordinates(shp_4326)
2022
meta[proj %in% "LAMB93", c("Long", "Lat")] <- coo_4326
2123

2224
# plot(meta$Long, meta$Lat)
25+
26+
# 2. update from Sylvie Ladet (Sebiopag_VcG) on 17/12/2026
2327
sebiopagF <- st_read(
2428
"data/XYpoint1_transect1_17parcelles_Sebiopag_Toulouse_L93.shp"
2529
)
@@ -30,15 +34,33 @@ coo_vcg <- data.frame(
3034
)
3135

3236
# Replace SEBIOPAG_VcG coordinates
33-
m0 <- match(meta$Plot_ID[meta$Study_ID == "SEBIOPAG_VcG"], coo_vcg$Site)
34-
meta$Lat[meta$Study_ID == "SEBIOPAG_VcG"] <- coo_vcg$Y[m0]
35-
meta$Long[meta$Study_ID == "SEBIOPAG_VcG"] <- coo_vcg$X[m0]
36-
37-
write.csv(meta, "coordinates_year_crop.csv", row.names = FALSE)
37+
# but not for T08, T18 and T19 which doesn't have coordinates in Sylvie's dataset
38+
sel <- meta$Study_ID == "SEBIOPAG_VcG" & meta$Plot_ID %in% coo_vcg$Site
39+
m0 <- match(meta$Plot_ID[sel], coo_vcg$Site)
40+
meta$Lat[sel] <- coo_vcg$Y[m0]
41+
meta$Long[sel] <- coo_vcg$X[m0]
42+
43+
44+
# 3. update from Frederic Fabre (OSCAR) on 03/04/2026
45+
oscar <- readxl::read_xlsx("data/OSCAR_gps_manquant_VF.xlsx")
46+
rm <- oscar$plot[oscar$latitude %in% c("à supprimer", "Plot arraché")]
47+
oscar <- oscar[!oscar$plot %in% rm, ]
48+
sel <- meta$Study_ID == "OSCAR" & meta$Plot_ID %in% oscar$plot
49+
m1 <- match(meta$Plot_ID[sel], oscar$plot)
50+
meta$Lat[sel] <- as.numeric(oscar$latitude[m1])
51+
meta$Long[sel] <- as.numeric(oscar$longitude[m1])
52+
meta <- meta[!(meta$Study_ID == "OSCAR" & meta$Plot_ID %in% rm), ]
53+
54+
# table(is.na(meta$Lat), meta$Study_ID, useNA = "ifany")
55+
write.csv(
56+
meta,
57+
here::here("data", "coordinates_year_crop.csv"),
58+
row.names = FALSE
59+
)
3860

39-
meta <- read.csv("coordinates_year_crop.csv")
40-
dim(meta) # 2068
41-
length(unique(paste0(meta$Long, meta$Lat, sep = "_")))
61+
meta <- read.csv(here::here("data", "coordinates_year_crop.csv"))
62+
dim(meta) # 2059
63+
length(unique(paste0(meta$Long, meta$Lat, sep = "_"))) # 592
4264

4365
meta$ID <- paste(meta$Study_ID, meta$Plot_ID, sep = "@")
4466
uID <- sort(unique(meta$ID))
@@ -67,79 +89,3 @@ umeta[!is.na(umeta$Lat), -1] |>
6789
here::here("data", "Fields_Unique.gpkg"),
6890
overwrite = TRUE
6991
)
70-
71-
range(umeta$Long, na.rm = TRUE)
72-
73-
meta$ID2 <- paste(meta$Study_ID, meta$Plot_ID, meta$Lat, sep = "@")
74-
meta$ID2[!duplicated(meta$ID2)]
75-
table(tapply(meta$Long, meta$ID, sd) > 0)
76-
length(unique(paste0(
77-
meta$Study_ID,
78-
meta$Plot_ID,
79-
meta$Long,
80-
meta$Lat,
81-
sep = "_"
82-
)))
83-
84-
# check previous coordinates
85-
# meta0 <- read.csv2("data/dataset_coordinates.csv")
86-
# meta0$Study_ID <- gsub("SEBIOPAG _BVD", "SEBIOPAG_BVD", meta0$Study_ID)
87-
# meta0$Study_ID[!meta0$Study_ID %in% meta$Study_ID]
88-
# meta$Study_ID[!meta$Study_ID %in% meta0$Study_ID]
89-
90-
meta$ID <- paste(meta$Study_ID, meta$Plot_ID, meta$Year, sep = "@")
91-
meta0$ID <- paste(meta0$Study_ID, meta0$Plot_ID, meta0$Year, sep = "@")
92-
# plot(meta$Lat, meta0$Lat[match(meta$ID, meta0$ID)])
93-
boxplot(meta$Lat - meta0$Lat[match(meta$ID, meta0$ID)])
94-
# plot(meta$Long, meta0$Long[match(meta$ID, meta0$ID)])
95-
boxplot(meta$Long - meta0$Long[match(meta$ID, meta0$ID)])
96-
97-
pts <- terra::vect("data/fields_FR.gpkg")
98-
table(pts$Study_ID)
99-
table(meta$Study_ID)
100-
# pts$ID <- paste(pts$Study_ID, pts$Site, pts$Year, sep = "@")
101-
# pts$ID[!pts$ID %in% meta$ID]
102-
# match(meta$ID, pts$ID)
103-
104-
# check Lepibats coordinates
105-
106-
pts_SEB <- meta[meta$Study_ID == "SEBIOPAG_VcG" & meta$Year == "2023", ]
107-
plot(coo_vcg$X - pts_SEB$Long[match(coo_vcg$Site, pts_SEB$Plot_ID)])
108-
boxplot(coo_vcg$X - pts_SEB$Long[match(coo_vcg$Site, pts_SEB$Plot_ID)])
109-
110-
out <- data.frame(
111-
"Site" = coo_vcg$Site,
112-
"Long_Sylvie" = coo_vcg$X,
113-
"Lat_Sylvie" = coo_vcg$Y,
114-
"Long_Axelle" = pts_SEB$Long[match(coo_vcg$Site, pts_SEB$Plot_ID)],
115-
"Lat_Axelle" = pts_SEB$Lat[match(coo_vcg$Site, pts_SEB$Plot_ID)]
116-
)
117-
write.csv(out, "coordinates_SEBIOPAG_VcG.csv", row.names = FALSE)
118-
119-
# pts_m <- pts_SEB[match(coo_vcg$Site, pts_SEB$Plot_ID), ]
120-
plot(
121-
out$Long_Sylvie,
122-
out$Lat_Sylvie,
123-
col = "black",
124-
pch = 16,
125-
xlab = "Longitude",
126-
ylab = "Latitude"
127-
)
128-
points(out$Long_Axelle, out$Lat_Axelle, col = "red", pch = 16)
129-
legend("topleft", c("Sylvie", "Axelle"), pch = 16, col = c("black", "red"))
130-
131-
132-
pts_TLS <- st_read(
133-
"data/XYpoint1_transect1_17parcelles_Sebiopag_Toulouse_L93.shp"
134-
) |>
135-
st_transform(crs = 4326)
136-
pol_TLS <- st_read(
137-
"data/17parcelles_Sebiopag_Toulouse_L93_Dynafor.shp"
138-
) |>
139-
st_transform(crs = 4326)
140-
pol_cts_TLS <- st_centroid(pol_TLS)
141-
142-
library(mapview)
143-
mapview(terra::vect(pol_TLS)) +
144-
mapview(pts_TLS) +
145-
mapview(pol_cts_TLS)

data/Fields_Unique.gpkg

8 KB
Binary file not shown.

0 commit comments

Comments
 (0)