[R-sig-Geo] Calculate the area of pixel in square kilometers from a raster in lat/long projection
Isaque Daniel
isaquedanielre at hotmail.com
Wed Nov 23 00:57:55 CET 2016
Hi there,
I found a example in stackoverflow of distance calculation and convertion, so I modificate that to compute the area by pixel in hectares using the raster in degrees.
#####
# Function to compute the area in hectares
measureAreahec <- function(imageRaster) {
R <- 6378.137 # radius of earth in Km
areaImagetemp <- area(ceiImg)
xresVal <- xres(areaImagetemp)
yresVal <- yres(areaImagetemp)
coords <- data.frame(coordinates(areaImagetemp))
colnames(coords) <- c("lon","lat")
lon1 <- coords$lon - (xresVal/2)
lon2 <- coords$lon + (xresVal/2)
lat1 <- coords$lat - (yresVal/2)
lat2 <- coords$lat + (yresVal/2)
# width
dLat <- (lat1-lat1)*pi/180
dLon <- (lon2-lon1)*pi/180
a <- sin((dLat/2))^2 + cos(lat1*pi/180)*cos(lat1*pi/180)*(sin(dLon/2))^2
c <- 2 * atan2(sqrt(a), sqrt(1-a))
dlongitude <- R * c * 1000
# heigth
dLat <- (lat1-lat2)*pi/180
dLon <- (lon1-lon1)*pi/180
a <- sin((dLat/2))^2 + cos(lat1*pi/180)*cos(lat1*pi/180)*(sin(dLon/2))^2
c <- 2 * atan2(sqrt(a), sqrt(1-a))
dlatitude <- R * c * 1000
return (dlatitude * dlongitude / 10000) # distance in meters
}
##########################
It's a very simple one, but ,maybe can help somebody.
Best
Isaque
------------------------------------------------------------------------------------------------------------------
Agronomist engineer
Master in Remote Sensing - National Institute for Space Research (INPE) - Brazil
PHD Student in Transport - Brazlia University (UNB)
________________________________
De: R-sig-Geo <r-sig-geo-bounces at r-project.org> em nome de Isaque Daniel <isaquedanielre at hotmail.com>
Enviado: terça-feira, 22 de novembro de 2016 17:48
Para: r-sig-geo
Assunto: [R-sig-Geo] Calculate the area of pixel in square kilometers from a raster in lat/long projection
Hi,
I'm looking for some advice to convert the area calculated by raster::area() in a raster image as the projection in lat/long.
[[elided Hotmail spam]]
Best
Isaque
------------------------------------------------------------------------------------------------------------------
Agronomist engineer
Master in Remote Sensing - National Institute for Space Research (INPE) - Brazil
PHD Student in Transport - Brazilia University (UNB)
[[alternative HTML version deleted]]
_______________________________________________
R-sig-Geo mailing list
R-sig-Geo at r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
R-sig-Geo Info Page<https://stat.ethz.ch/mailman/listinfo/r-sig-geo>
stat.ethz.ch
R-sig-Geo -- R Special Interest Group on using Geographical data and Mapping About R-sig-Geo
[[alternative HTML version deleted]]
More information about the R-sig-Geo
mailing list