[R-sig-Geo] Geolocating and writing many tiffs at the same time

Rodofili, Esteban Nicolas erodo|||| @end|ng |rom u||@edu
Fri May 21 04:31:32 CEST 2021


Solved!

library(raster)
library(rgdal)
library(ggplot2)
library(dplyr)
library(OpenImageR)


geolocate <- function(input) {
## Loading image of interest as raster
R_test <-
  stack(input)
R_test ## It does not have any CRS
plot(R_test)

# Give image of interest the lat/lon coords of the geolocated image as appear in its metadata in the console
extent(R_test) <- c(-9073461, -9073269, 2974255, 2974366)
# Copy the projection data of the geolocated image as appears in the console to the image of interest
projection(R_test) <- CRS("+proj=merc +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs")

## Write new geolocated image into a file

writeRaster(R_test,
            filename=sub(".png", "_geolocated.tif", input),
            format="GTiff",
            overwrite=TRUE,
            NAflag=-9999)
}


filenames <- list.files(path = ".",  #The point means the working directory
                        # Now follows a regular expression that matches:
                        pattern = ".png",
                        full.names = TRUE)
for (f in filenames) {
  geolocate(f)
}

Esteban N. Rodofili
Ph.D. Student - Interdisciplinary Ecology Program, SNRE
Lic. in Biology - Mgtr. in Public Policy
Marine Geomatics Lab
University of Florida
UF Climate Action Plan - Transportation Working Group
352-284-6828
erodofili using ufl.edu
https://www.thelecourslab.org/

I stand in solidarity with Graduate Assistants United and demand the University of Florida:
1.      Follow through with its agreement to pay certain fees on behalf of GAs as outlined in Article 10.6 of our Collective Bargaining Agreement.
2.      Discontinue all business relationships with Aramark due to their use of prison labor, and directly consult with the Food Justice League, Gator NAACP, Dream Defenders, and allied groups on the upcoming food service vendor contract to ensure racial equity.
3.      Immediately reverse its plan to demolish the Maguire and UVS Graduate Family Housing complexes.
4.      Immediately revoke its new furlough policy.


________________________________
From: R-sig-Geo <r-sig-geo-bounces using r-project.org> on behalf of Rodofili, Esteban Nicolas <erodofili using ufl.edu>
Sent: Thursday, May 20, 2021 8:21 PM
To: r-sig-geo using r-project.org <r-sig-geo using r-project.org>
Subject: [R-sig-Geo] Geolocating and writing many tiffs at the same time

Hi! I have found a way to give a png the CRS and location of a geolocated tiff, and to convert the png to tiff. Now I have to apply it to different pngs in the same folder (all named Pt6_frame1, Pt6_frame2, etc) and write the individual new tiff files as Pt6_frame1_geolocated, Pt6_frame2_geolocated, etc. Does anyone have an idea of how to do so? I have tried the code in various posts, using for loops and functions, but I get various errors. Thanks.

**## Loading image of interest as stack**

R_test <-
  stack("Pt6_clear.png")

**# Give image of interest the lat/lon coords of the geolocated image as appear in its metadata in the console**

extent(R_test) <- c(-9073461, -9073269, 2974255, 2974366)

**# Copy the projection data of the geolocated image as appears in the console to the image of interest**

projection(R_test) <- CRS("+proj=merc +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs")

**## Write new geolocated image into a file**

writeRaster(R_test, "R_test_geolocated.tif",
            format="GTiff",
            overwrite=TRUE,
            NAflag=-9999)

Esteban N. Rodofili
Ph.D. Student - Interdisciplinary Ecology Program, SNRE
Lic. in Biology - Mgtr. in Public Policy
Marine Geomatics Lab
University of Florida
UF Climate Action Plan - Transportation Working Group
352-284-6828
erodofili using ufl.edu
https://urldefense.proofpoint.com/v2/url?u=https-3A__www.thelecourslab.org_&d=DwICAg&c=sJ6xIWYx-zLMB3EPkvcnVg&r=JPNgOv5us8uAguSZncngjd5s5z0ipng9nnp7uq0axoI&m=1pC7ri4XHqeWYavskPdPUhTZ5aSx6YKOUXDpG4uGVpY&s=3ObX7Vn7iq8WknN9RhbTrlz4ESoiqbdgcGZtaaSDC3M&e=

I stand in solidarity with Graduate Assistants United and demand the University of Florida:
1.      Follow through with its agreement to pay certain fees on behalf of GAs as outlined in Article 10.6 of our Collective Bargaining Agreement.
2.      Discontinue all business relationships with Aramark due to their use of prison labor, and directly consult with the Food Justice League, Gator NAACP, Dream Defenders, and allied groups on the upcoming food service vendor contract to ensure racial equity.
3.      Immediately reverse its plan to demolish the Maguire and UVS Graduate Family Housing complexes.
4.      Immediately revoke its new furlough policy.



        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo using r-project.org
https://urldefense.proofpoint.com/v2/url?u=https-3A__stat.ethz.ch_mailman_listinfo_r-2Dsig-2Dgeo&d=DwICAg&c=sJ6xIWYx-zLMB3EPkvcnVg&r=JPNgOv5us8uAguSZncngjd5s5z0ipng9nnp7uq0axoI&m=1pC7ri4XHqeWYavskPdPUhTZ5aSx6YKOUXDpG4uGVpY&s=gCIeuZ55ZMWoqghaNxDNY_kBMOi_d1_IHxGxPBplOgg&e=

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list