On Sat, 17 Mar 2007, Milton Cezar Ribeiro wrote:

> Dear helpers
> 
> I need convert a shape file to AscGrid format. How can I select a field,
> convert to AscGrid and save as ascii file?

This should work:

library(maptools)
xx <- readShapePoly(system.file("shapes/sids.shp", package="maptools")[1], 
  IDvar="FIPSNO", proj4string=CRS("+proj=longlat +ellps=clrk66"))
grd <- GE_SpatialGrid(xx, asp=1, maxPixels=100)$SG
# to make a SpatialGrid object, could use GridTopology() directly, here 
# asp=1 to be sure that cells are square
summary(grd)
poly_which <- overlay(xx, grd)
# copies out the polygon field values to the appropriate grid cells
summary(poly_which)
SGDF <- SpatialGridDataFrame(slot(grd, "grid"), data=poly_which, 
  proj4string=CRS(proj4string(grd))
image(SGDF, "BIR74")
plot(xx, add=TRUE)
writeAsciiGrid(SGDF, "BIR74.aai", "BIR74")

Of course, you could compute rates, etc, on the SpatialPolygonDataFrame 
before copying the values out to the grid cells, and you could drop data 
columns in the SpatialPolygonDataFrame first to avoid unecessary copying. 
But this runs pretty quickly anyway.

Hope this helps,

Roger


> 
> Kind regards,
> 
> miltinho
> 
> __________________________________________________
> 
> 
>       [[alternative HTML version deleted]]
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo@stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> 

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: [EMAIL PROTECTED]

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Reply via email to