I come up with a provisional way to coregister our data given the following remarks during my data check:
mangatu_eros_feat
folderMangatu_feature_extraction
folder + aerial photoslibrary(here)
library(sf)
library(stars)
library(tidyverse, quietly = T, warn.conflicts = F)
library(mapview)
stec_dir = "R:/RESEARCH/02_PROJECTS/01_P_330001/119_STEC/04_Data/Gullies-Mangatu"
g88_wrongproj = st_read(here(stec_dir, 'mangatu_eros_feat', 'mangatu_1988_ero_feat.shp'))
## Reading layer `mangatu_1988_ero_feat' from data source `R:\RESEARCH\02_PROJECTS\01_P_330001\119_STEC\04_Data\Gullies-Mangatu\mangatu_eros_feat\mangatu_1988_ero_feat.shp' using driver `ESRI Shapefile'
## Simple feature collection with 1390 features and 4 fields
## geometry type: POLYGON
## dimension: XY
## bbox: xmin: 2019163 ymin: 5751020 xmax: 2033407 ymax: 5765684
## projected CRS: NZGD2000 / New Zealand Transverse Mercator 2000
g88_goodproj = st_read(here(stec_dir, 'Mangatu_feature_extraction', 'mangatu_1988_ero_feat_nztm.shp'))
## Reading layer `mangatu_1988_ero_feat_nztm' from data source `R:\RESEARCH\02_PROJECTS\01_P_330001\119_STEC\04_Data\Gullies-Mangatu\Mangatu_feature_extraction\mangatu_1988_ero_feat_nztm.shp' using driver `ESRI Shapefile'
## Simple feature collection with 1390 features and 4 fields
## geometry type: POLYGON
## dimension: XY
## bbox: xmin: 2019192 ymin: 5751216 xmax: 2033436 ymax: 5765880
## projected CRS: NZGD2000_New_Zealand_Transverse_Mercator_2000
# Extract geometries from good and wrong registration
t1 = g88_goodproj %>%
st_geometry()
t2 = g88_wrongproj %>%
st_geometry()
# Transform wrong registration to same CRS as good coregistration
t2t = t2 %>%
st_transform(crs = st_crs(g88_goodproj))
# Calculate differences between polygons centroids
diff = (st_centroid(t1) - st_centroid(t2t))
# Density
par(mfrow = c(2,2))
diff %>%
st_coordinates() %>%
apply(2, function (x) plot(density(x))) %>%
invisible()
# Histogram
diff %>%
st_coordinates() %>%
apply(2, hist) %>%
invisible()
# Median
median = diff %>% st_coordinates() %>% apply(2, median)
# Mean
mean = diff %>% st_coordinates() %>% apply(2, mean)
# Min
min = diff %>% st_coordinates() %>% apply(2, min)
# Max
max = diff %>% st_coordinates() %>% apply(2, max)
# Standard deviation
sd = diff %>% st_coordinates() %>% apply(2, sd)
knitr::kable(rbind(min, mean, median, max, sd))
X | Y | |
---|---|---|
min | 28.7316462 | 195.4090545 |
mean | 28.8827100 | 195.4544335 |
median | 28.8797528 | 195.4506451 |
max | 29.0418722 | 195.5233130 |
sd | 0.0748139 | 0.0281182 |
# Sum the mean difference to X and Y
t3t = st_sfc(t2t + mean) %>%
# Reproject to "good" registration file
st_set_crs(st_crs(t1))
t1 %>%
plot(border = 'darkgreen', col = NA)
t2t %>%
plot(border = 'red', col = NA, add = T)
t3t %>%
plot(border = 'blue', col = NA, add = T)
mapview(t1, layer.name = "Correct proj", col.regions = 'darkgreen') +
mapview(t2t, layer.name = "Wrong proj", col.regions = 'red') +
mapview(t3t, layer.name = "Affine proj", col.regions = 'blue')