1

In my example, I have a single dji image in *JPG:

library(terra)
single.image <-rast("https://github.com/Leprechault/trash/raw/main/DJI_0274.JPG")
plotRGB(single.image,  r = 3, g = 2, b = 1, stretch = "lin")
# class      : RasterStack 
# dimensions : 3648, 4864, 17743872, 3  (nrow, ncol, ncell, nlayers)
# resolution : 1, 1  (x, y)
# extent     : 0, 4864, 0, 3648  (xmin, xmax, ymin, ymax)
# crs        : NA 
# names      : DJI_0274_1, DJI_0274_2, DJI_0274_3 

How can I use this single.image to * .jgw file creation using R?

4
  • 1
    The image has a bunch of DJI EXIF data for pitch and FOV etc, and the GPS metadata, so it might be a case of implementing these formulae: gis.stackexchange.com/questions/384756/… - have you checked to see if anyone has already done this in R?
    – Spacedman
    Commented Feb 2, 2023 at 14:40
  • Thanks @Spacedman, but its not for R yet! Commented Feb 2, 2023 at 14:49
  • 1
    Just to be clear, because I see there already is a JGW in that repo (and a Q from you on SO), you are trying to workout how to create such a JGW given just the image and its embedded metadata?
    – Spacedman
    Commented Feb 2, 2023 at 15:43
  • 1
    I've converted that code to R - its not overly complex - but am missing some parameters from the metadata - sensor width and aspect for starters.
    – Spacedman
    Commented Feb 2, 2023 at 17:44

1 Answer 1

2

Here is how you could do that if the image does not have a rotation.

Set the extent

ext(single.image) <- c(-10, 10, -20, 0)

Write the world file

wfile <- function (x, filename) {
    thefile <- file(filename, "w")
    cat(as.character(xres(x)), "\n", file = thefile)
    cat("0\n0\n", file = thefile)
    cat(-1 * yres(x), "\n", file = thefile)
    cat(xmin(x) + 0.5 * xres(x), "\n", file = thefile)
    cat(ymax(x) - 0.5 * yres(x), "\n", file = thefile)
    close(thefile)
}

wfile(single.image, "single.image.jpw")
1
  • 1
    I'm not sure that helps - the Q seems to be about how to find the ground extent given the metadata parameters of the drone - like the camera direction, field-of-view, and distance to ground.
    – Spacedman
    Commented Feb 3, 2023 at 12:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.