Skip to content

Commit

Permalink
checklist package toegepast
Browse files Browse the repository at this point in the history
  • Loading branch information
stienheremans committed Dec 19, 2024
1 parent 9d67fd4 commit b924758
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
1 change: 1 addition & 0 deletions data/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dronebeelden
9 changes: 9 additions & 0 deletions source/Coregistration.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
title: "Coregistration drone and orthophoto images"
output: html_notebook
---
```{r coregister}

Check warning on line 6 in source/Coregistration.Rmd

View workflow job for this annotation

GitHub Actions / check project with checklist

file=source/Coregistration.Rmd,line=6,col=1,[trailing_blank_lines_linter] Trailing blank lines are superfluous.

Check warning on line 7 in source/Coregistration.Rmd

View workflow job for this annotation

GitHub Actions / check project with checklist

file=source/Coregistration.Rmd,line=7,col=1,[trailing_blank_lines_linter] Trailing blank lines are superfluous.
```

36 changes: 19 additions & 17 deletions source/Orthophoto_processing.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ print(drone_outlines)
tile_shapefile <- st_read("../data/KaartbladenNGI/Kbl.shp")
# Add the "VL_" prefix to the CODE column
tile_shapefile$TileName <- paste0("OMZCIR21VL_", sprintf("%02d", as.integer(tile_shapefile$CODE)))
tile_shapefile$TileName <- paste0("OMZCIR21VL_",
sprintf("%02d", as.integer(tile_shapefile$CODE)))
# Ensure both datasets have the same CRS
drone_outlines <- st_transform(drone_outlines, st_crs(tile_shapefile))
Expand All @@ -29,7 +30,7 @@ print(matched_tiles)
# General folder path for orthos (GIS schijf INBO)
ortho_folder <- "Z:/Vlaanderen/Referentie/Orthofoto/Orthofoto_zomer2021_CIR"

Check warning on line 32 in source/Orthophoto_processing.Rmd

View workflow job for this annotation

GitHub Actions / check project with checklist

file=source/Orthophoto_processing.Rmd,line=32,col=18,[absolute_path_linter] Do not use absolute paths.
## List ortho files (tiles)
# List ortho files (tiles)
ortho_files <- list.files(ortho_folder, pattern = "\\.jp2$", full.names = TRUE)
# Extract tile names from raster filenames
Expand All @@ -49,41 +50,41 @@ for (drone_id in unique(matched_tiles$naam)) {
# Subset the current drone polygon
drone_geom <- matched_tiles[matched_tiles$naam == drone_id, ]
print(drone_id)
# Add a 10-meter buffer around the polygon
# Add a 10-meter buffer around the polygon
drone_geom <- st_buffer(drone_geom, dist = 10)
# Find all raster tiles corresponding to this drone polygon
tile_files <- unique(drone_geom$RasterFile)
(print(tile_files))
# Initialize a list to store clipped rasters
clipped_parts <- list()
# Loop through the corresponding raster tiles
for (tile_file in tile_files) {
# Check if the raster file exists
if (!file.exists(tile_file)) {
cat("Raster file not found:", tile_file, "\n")
next
}
# Load the raster
raster <- rast(tile_file)
# Clip and mask the raster to the drone polygon
print('starting clip')
print("starting clip")
# Reproject the vector to match the raster
crs_raster <- crs(raster)
drone_geom <- st_transform(drone_geom, crs_raster)
clipped_raster <- crop(raster, vect(drone_geom))
masked_raster <- mask(clipped_raster, vect(drone_geom))
# Add to the list of clipped parts
clipped_parts <- append(clipped_parts, list(masked_raster))
}
print('clipping done')
print('starting merge')
print("clipping done")
print("starting merge")
# Merge all clipped parts if there are multiple tiles
if (length(clipped_parts) > 1) {
merged_raster <- do.call(merge, clipped_parts)
Expand All @@ -93,17 +94,18 @@ for (drone_id in unique(matched_tiles$naam)) {
cat("No valid raster data for Drone ID:", drone_id, "\n")
next
}
print('merge done')
print("merge done")
# Define the output file name
output_file <- paste0("../output/ortho_CIR/ortho_CIR_", drone_id, "_10mbuf.tif")
output_file <- paste0("../output/ortho_CIR/ortho_CIR_", drone_id,
"_10mbuf.tif")
# Ensure the output directory exists
if (!dir.exists("../output/ortho_CIR")) {
dir.create("../output/ortho_CIR", recursive = TRUE)
}
print('starting save raster')
print("starting save raster")
# Save the merged raster
writeRaster(merged_raster, output_file, overwrite = TRUE)
print('save raster done')
print("save raster done")
# Print status
cat("Saved merged raster for Drone ID:", drone_id, "to", output_file, "\n")
}
Expand Down

0 comments on commit b924758

Please sign in to comment.