J'ai un raster correspondant à une parcelle d'expérimentation, ainsi que les coordonnées géographiques d'un point de mesure terrain. J'aimerais extraire la valeur du pixel correspondant à la mesure terrain pour pouvoir faire mon analyse.
Voici mon code :
Code : Tout sélectionner
library(sp)
library(rgdal)
library(rgeos)
library(mapproj)
library(maptools)
library(raster)
# Chargement d'un raster
rast_LAI <- readGDAL("raster_LAI_20190321.ima")
# Mon point de mesure terrain
mes_995326<-data.frame(parcelle="M-995326-8",long=2.386662031,lat=48.31697945)
#interprete la localisation de la mesure comme un point geolocalisé
mes_995326_wgs84<-SpatialPoints(coords=mes_995326[,c('long','lat')],
proj4string=CRS ("+init=epsg:4326"))
#Pour être sur que je sois dans le même système de projection (raster et point)
crs_carte<-proj4string(rast_LAI)
acq_1px<- spTransform(les_995326_wgs84[1,],CRS(crs_carte))
# affichage
plot(rast_LAI,col=rev(terrain.colors(length(unique(rast_LAI@data$band2)))))
points(acq_1px, col="red")
#extraction d'un pixel
acq_1px<-extract(x=rast_LAI,y=acq_1px,
layer=2,
method='simple')
Le script marche jusqu'à l'affichage, où j'ai bien mon point qui se supperpose au raster.
Par contre la fonction extract ne fonctionne pas.
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘extract’ for signature ‘"SpatialGridDataFrame", "SpatialPoints"’
Avez-vous des pistes?
Merci beaucoup de votre aide,
Anaïs Bonnard