简体   繁体   中英

R - How to retrieve xy-coordinates at max(z)?

Given are XYZ coordinates of LiDAR points (taken from itcSegment documentation):

data(lasData)

Retrieving the highest point can be done by:

max(lasData$Z)

Now, I´m searching for a way to get the xy-coordinates of this highest points.

It´s probably not a big deal, however I was trying for quite some time...

Here is an example using matrices:

> m <- matrix(c(1:9),3,3)
> colnames(m) <- c('X','Y','Z')
> m
     X Y Z
[1,] 1 4 7
[2,] 2 5 8
[3,] 3 6 9
> max(m[,'Z'])
[1] 9
> which(m[,'Z']==max(m[,'Z']))
[1] 3
> m[which(m[,'Z']==max(m[,'Z'])),]
X Y Z 
3 6 9 
> data<-data.frame(x=c(2,5,4,6,2),y=c(34,55,23,3,6),z=c(54,23,6,11,93))
> data
  x  y  z
1 2 34 54
2 5 55 23
3 4 23  6
4 6  3 11
5 2  6 93

> max(data$z)
[1] 93

> which(data$z == max(data$z))
[1] 5

This might be helpful

# data.frame
data(meuse.grid)
coordinates(meuse.grid) <- ~x+y
gridded(meuse.grid) <- TRUE
class(meuse.grid)
bbox(meuse.grid)

data(meuse)
meuse.xy = meuse[c("x", "y")]
coordinates(meuse.xy) <- ~x+y
class(meuse.xy)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM