Skip to content

Selecting contiguous, irregularly-shaped sets of values from arrays

2 messages · Chris Campbell, Bryan McCloskey

5 days later
#
Chris,

That worked exceptionally well. Here's the pseudo-code for what I ended up using:

library(spatstat)
depth_bin<-depth<-stage-elevation #depth at grid cells = stage matrix - elevation matrix; initialize binary matrix
depth_bin[,]<-depth>5 #binary matrix of cells >5cm deep
depth_con_im<-connected(as.im(depth_bin),background=0) #8-connected regions of pixel image
depth_con<-depth_con_im$v #v element is data matrix
class(depth_con)<-"matrix"
for (i in 1:length(coords$points)) { #points of interest
	x_co<-which.min(abs(x-coords$EASTING[i]))
	y_co<-which.min(abs(y-coords$NORTHING[i]))
	pond[i]<-depth_con[x_co,y_co] #pond of cell of interest
	area[i]<-length(which(depth_con==pond[i]))*400*400 #area of the pond (400m grid)
	depth[i]<-depth[x_co,y_co] #depth at cell of interest
}

Thanks for the tip!
-bryan

------
Bryan McCloskey, Ph.D.
IT Specialist (Data Management/Internet)
U.S. Geological Survey
St. Petersburg Coastal & Marine Science Center
600 Fourth St. South
St. Petersburg, FL 33701

South Florida Information Access: http://sofia.usgs.gov
Everglades Depth Estimation Network: http://sofia.usgs.gov/eden
Phone: 727.803.8747x3017 * Fax: 727.803.2032
------
On Feb 1, 2012, at 9:34 AM, Chris Campbell wrote: