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

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Isaque Eberhardt
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
Reply | Threaded
Open this post in threaded view
|

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

Isaque Eberhardt
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-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]]


_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

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

R-sig-geo mailing list
raster::area would calculate the area in square kilometers, and from there one can convert to hectare or square meters.

I was wondering: how do those calculations differ from raster::area's?
Greetings,
 -- Thiago V. dos Santos

PhD student
Land and Atmospheric Science
University of Minnesota


On Tuesday, November 22, 2016 8:15 PM, Isaque Daniel <[hidden email]> wrote:



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�-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-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]]


_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

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

Isaque Eberhardt
Hi Thiago,


The function calculate the area by pixel "like raster::area", but, considering the distortions of projection and transforming from degree to hectares (or square kilometers, if someone need).

The problem is: how to compute the area for raster maps during the interactive process and compare as the values used to define the classification (chosing the thresholds), because the raster::area return the area in the projection of raster, and for huge datasets or multiple aplications in sequence (or both togheter, as in my case), is computational hard to reproject raster ou poor to work with "mean value of pixel" in large rasters......

So, I develop this simple function.
Best
Isaque


------------------------------------------------------------------------------------------------------------------
Eng. Agr. Isaque Daniel Rocha Eberhardt
Mestre em Sensoriamento Remoto - Instituto Nacional de Pesquisas Espaciais (INPE)
Doutorando em Transportes - Universidade de Bras??lia (UNB)
Mobile: +55 (061) 99015658
------------------------------------------------------------------------------------------------------------------
Agronomist engineer
Master in Remote Sensing - National  Institute for Space Research (INPE) - Brazil
PHD Student in Transport - Bras??lia University (UNB)


________________________________
De: Thiago V. dos Santos <[hidden email]>
Enviado: quarta-feira, 23 de novembro de 2016 15:56
Para: Isaque Daniel; r-sig-geo
Assunto: Re: [R-sig-Geo] Calculate the area of pixel in square kilometers from a raster in lat/long projection

raster::area would calculate the area in square kilometers, and from there one can convert to hectare or square meters.

I was wondering: how do those calculations differ from raster::area's?
Greetings,
 -- Thiago V. dos Santos

PhD student
Land and Atmospheric Science
University of Minnesota


On Tuesday, November 22, 2016 8:15 PM, Isaque Daniel <[hidden email]> wrote:



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�-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-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


R-sig-Geo Info Page<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


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
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]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo