# Calculate the area of pixel in square kilometers from a raster in lat/long projection

4 messages
Open this post in threaded view
|

## 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. If anyone has some suggestion, please!! 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 [hidden email] https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Open this post in threaded view
|

## Re: Calculate the area of pixel in square kilometers from a raster in lat/long projection

 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 <[hidden email]> em nome de Isaque Daniel <[hidden email]> 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 [hidden email] https://stat.ethz.ch/mailman/listinfo/r-sig-geoR-sig-Geo Info Page stat.ethz.ch R-sig-Geo -- R Special Interest Group on using Geographical data and Mapping About R-sig-Geo         [[alternative HTML version deleted]] _______________________________________________ R-sig-Geo mailing list [hidden email] https://stat.ethz.ch/mailman/listinfo/r-sig-geo