Learn R Programming

mapplots (version 1.5.3)

write.grid: Export a grd object as csv or shapefile

Description

Export a grd object (created by make.grid) as csv or shapefile.

Usage

write.grid(grd, file, type="csv")

Value

A csv file with three columns corresponding to x, y and z (lon, lat, value), or a shapefile with a polygon for each cell in the grd object. The assumed projection is EPSG:4326

Arguments

grd

a grid object created by the function make.grid.

file

character string naming the output filename. For csv files do include the extension (e.g. "my_file.csv"); for shapefiles omit the extension (e.g. "my_file").

type

character string specifying the output file type. Must be one of "csv" (default) or "shape"

Author

Hans Gerritsen

See Also

make.grid, write.shapefile .

Examples

Run this code
library(shapefiles)
data(landings)
data(coast)
byx = 1
byy = 0.5
xlim <- c(-15.5,0)
ylim <- c(50.25,56)
grd <- make.grid(landings$Lon, landings$Lat, landings$LiveWeight, byx, byy, xlim, ylim)
breaks <- breaks.grid(grd,zero=FALSE)
basemap(xlim, ylim, main = "Gadoid landings")
draw.grid(grd,breaks)
draw.shape(coast, col="darkgreen")
legend.grid("topright", breaks=breaks/1000, type=2)
if (FALSE) {
write.grid(grd,"c:/test1.csv")
write.grid(grd,"c:/test1","shape")
}

Run the code above in your browser using DataLab