pave {pgirmess} | R Documentation |
Provide a user-defined cellgrid of polygon squares (or square node points) along a segment. This can be used to define a sampling grid for spatial analysis.
pave(cordseg, yc, xc, fix.edge=NULL, ydown = TRUE, output = "list")
cordseg |
the segment coordinates. This can be a vector c(x1,y1,x2,y2), a 2 x 2 matrix or a data.frame (each line a coordinate) |
yc |
the number of segment divisions (y cells) |
xc |
the number of columns (x cells) |
fix.edge |
the edge length of a cell (user specified, default to NULL) |
ydown |
if TRUE (default) squares are computed decreasing y |
output |
a character string indicating which output is required. One of "list", "points" or "spdf". Partial match allowed |
The segment must have x1 < x2. If not, it is automatically reordered. When "spdf" is selected the output is an object of class
SpatialPolygonsDataframe. It has a plot method and can straightfully be handled by writeShapePoly (see readShapePoly
) of the maptools library to write a shapefile.
The value of the edge length of a cell can passed with the argument fix.edge. In this case, the coordinates of the segment right top are re-computed to adjust the cell edge to an user defined fixed value.
According to the output selected, a list of polygon coordinates, a 2 column matrix with the nodes coordinates or a SpatialPolygonsDataframe.
Patrick Giraudoux <pgiraudo@univ-fcomte.fr>
SpatialPolygonsDataFrame-class
, readShapePoly
, overlay
, diag2edge
# segment sloping up coord<-matrix(c(20,20,90,90),nr=2,byrow=TRUE) plot(coord,type="n",xlim=c(0,100),ylim=c(0,110),asp=1) lines(coord) # point grids gr<-pave(coord,20,4,output="points") # y decreasing points(gr) gr<-pave(coord,20,4,output="points",ydown=FALSE) # y increasing points(gr,col="blue") # square polygon grids gr<-pave(coord,20,4) # y decreasing for (i in 1:length(gr)) polygon(gr[[i]]) gr<-pave(coord,20,4,ydown=FALSE) # y increasing for (i in 1:length(gr)) polygon(gr[[i]],border="blue") # segment sloping down coord<-matrix(c(20,90,90,20),nr=2,byrow=TRUE) plot(coord,type="n",xlim=c(0,100),ylim=c(0,110),asp=1) lines(coord) # point grids gr<-pave(coord,20,4,output="points") # y decreasing points(gr) gr<-pave(coord,20,4,output="points",ydown=FALSE) # y increasing points(gr,col="blue") # fixed edge plot(coord,type="n",xlim=c(0,100),ylim=c(0,110),asp=1) lines(coord) gr<-pave(coord,20,4,fix.edge=4,output="points") points(gr,col="blue") plot(coord,type="n",xlim=c(0,100),ylim=c(0,110),asp=1) lines(coord) gr<-pave(coord,20,4,fix.edge=5.5,output="points") points(gr,col="red") # square polygon grids coord<-matrix(c(20,90,90,20),nr=2,byrow=TRUE) plot(coord,type="n",xlim=c(0,100),ylim=c(0,110),asp=1) lines(coord,lwd=2) gr<-pave(coord,20,4)# y decreasing for (i in 1:length(gr)) polygon(gr[[i]]) gr<-pave(coord,20,4,ydown=FALSE) # y increasing for (i in 1:length(gr)) polygon(gr[[i]],border="blue") ## Not run: # Writing a polygon shapefile gr<-pave(coord,20,4,output="spdf") # y decreasing library(maptools) writePolyShape(gr, "myshapefilename") ## End(Not run)