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?

Robert Hijmans
  • 10,683
  • 25
  • 35
Leprechault
  • 175
  • 10
  • 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: https://gis.stackexchange.com/questions/384756/georeference-single-drone-image-from-exif-data - have you checked to see if anyone has already done this in R? – Spacedman Feb 02 '23 at 14:40
  • Thanks @Spacedman, but its not for R yet! – Leprechault Feb 02 '23 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 Feb 02 '23 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 Feb 02 '23 at 17:44

1 Answers1

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")

Robert Hijmans
  • 10,683
  • 25
  • 35
  • 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 Feb 03 '23 at 12:18