getGridData: Compute Data for a Grid Layer

Description Usage Arguments Value See Also Examples

Description

This function computes data to match a grid layer (as outputed by getGridLayer ) according to the surface intersections.

Usage

1
getGridData(x, df, dfid = NULL, var)

Arguments

x

a list generated by the getGridLayer function.

df

a data frame that contains the values to adapt to the grid. It must correspond to the spdf argument in getGridLayer.

dfid

identifier field in df, default to the first column of df. (optional)

var

name of the numeric field in df to adapt to the grid.

Value

A data frame is returned. id_cell are ids of the grid, the two other variable are the share of the variable in each cell and the share of the variable in each cell divided by its area (in map units).

See Also

getGridLayer

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
## Not run: 
data(nuts2006)
# Create a grid layer
mygrid <- getGridLayer(spdf=nuts2.spdf,cellsize = 200000)
# Compute data for the grid layer
datagrid.df <- getGridData(mygrid, nuts2.df, "pop2008",dfid=NULL)

# Plot total population
plot(mygrid$spdf, col="#CCCCCC",border="white")
propSymbolsLayer(spdf = mygrid$spdf, df = datagrid.df, legend.style = "e",
                 legend.pos = "right", border = "white",legend.title.txt = "Total population",
                 var = "pop2008", inches=0.01, col="black", add=TRUE)

# Plot dentsity of population 
## conversion from square meter to square kilometers
datagrid.df$densitykm <- datagrid.df$pop2008_density*1000*1000 
cols <- carto.pal(pal1 = "taupe.pal", n1 = 6)
choroLayer(spdf = mygrid$spdf,df = datagrid.df,var = "densitykm", add=FALSE,
           border = "grey80",col=cols,
           legend.pos = "right", method = "q6",
           legend.title.txt = "Population density")
           
## End(Not run)


Search within the cartography package
Search all R packages, documentation and source code

Questions? Problems? Suggestions? or email at ian@mutexlabs.com.

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.