Gracias por su respuesta. No sé cómo suministrar mis datos, no veo ningún lugar para adjuntarlos, pero también soy nuevo en publicar aquí, pero voy a tratar de darle la impresión de los datos.
##point files
trainData_crs<- read.csv(file.csv) > class(trainData_crs)
[1] "data.frame"
> summary(trainData_crs)
PlotType Class Latitude Longitude
closedforest:22 Min. :1.000 Min. :17.81 Min. :24.72
grass :34 1st Qu.:2.000 1st Qu.:17.86 1st Qu.:24.98
lowforest :24 Median :3.000 Median :17.92 Median :25.02
mediumforest:26 Mean :2.904 Mean :17.95 Mean :25.02
shrubs : 4 3rd Qu.:4.000 3rd Qu.:18.01 3rd Qu.:25.10
unknown : 3 Max. :7.000 Max. :18.46 Max. :25.16
water : 1
##images load and convert it to bricks
all_landsat_bands<-list.files ("file.tif")
img <- brick(all_landsat_bands)
> img <- brick(LandsatAprJune_2019_st)
> class(img)
[1] "RasterBrick"
attr(,"package")
[1] "raster"
> names(img)
[1] "B1" "B2" "B3" "B4" "B5" "B6" "B7" "B10" "B11"
>
##convert to same projection
coordinates(trainData_crs)<-~Latitude +Longitude
trainData_crs <- SpatialPoints(cbind(trainData_crs$Latitude, trainData_crs$Longitude),
proj4string=CRS("+proj=utm +zone=34 +south +a=6378249.145 +b=6356514.966398753 +towgs84=-138,-105,-289,0,0,0,0 +units=m
+no_defs "))
trainData_crs_sp <- spTransform(trainData_crs, crs(img))
##confirm if points and image are in same coordinates
> crs(trainData_crs_sp)
CRS arguments:
+proj=utm +zone=34 +south +a=6378249.145 +b=6356514.966398753 +towgs84=-138,-105,-289,0,0,0,0 +units=m
+no_defs
> crs(img)
CRS arguments:
+proj=utm +zone=34 +south +a=6378249.145 +b=6356514.966398753 +towgs84=-138,-105,-289,0,0,0,0 +units=m
+no_defs
##summary on transformed points
> summary(trainData_crs_sp)
Object of class SpatialPoints
Coordinates:
min max
coords.x1 177676.9 244145.4
coords.x2 12738109.3 12786443.7
Is projected: TRUE
proj4string :
[+proj=utm +zone=34 +south +a=6378249.145 +b=6356514.966398753 +towgs84=-138,-105,-289,0,0,0,0 +units=m
+no_defs]
Number of points: 114
##extract pixel values
trainData_bands<-raster::extract(img, trainData_crs_sp)
He editado el código anterior para intentar usar spTransform en los puntos pero sigo obteniendo NAs
Gracias