[R-sig-Geo] shapefile errors and kriging limits

Roger Bivand Roger.Bivand at nhh.no
Fri Aug 31 00:16:42 CEST 2007


On Thu, 30 Aug 2007, Carlos Guerra wrote:

> Dear useRs,
>
> I am trying to convert the predictions of a kriging model into a
> shapefile but I am getting some errors and I am getting nowere with
> my solutions...

Without the error messages and the output of sessionInfo(), it isn't easy 
to say.

>
> This is the code I am running:
>
> a <- data.frame(Id=seq(1,length(pred.grid[,1]),1),X=pred.grid[,
> 1],Y=pred.grid[,2])
> a_dbf <- data.frame(Id=seq(1,length(pred.grid[,1]),1), data=kc2$predict)
> shp_1 <- convert.to.shapefile(a, a_dbf, field="Id", type=1)
>
> were pre.grid is determined by this code:
>
> min_x <- 142794
> max_x <- 152121
> min_y <- 485080
> max_y <- 508887
> pred.grid <- expand.grid(seq(min_x, max_x, 50), seq(min_y, max_y, 50))
>
> and kc2 is an object returned by the aplication of the function
> krige.conv:
>
> kc2 <- krige.conv(dados_g, loc=pred.grid, krige=krige.control
> (obj.m=vario_fit2))
>

Although you are free to use the shapefiles package, your questions 
suggest that you might be better served by using sp classes and either 
maptools or rgdal to read and write your files. If you read the points 
data with readOGR() or readShapePoints(), created a GridTopology for your 
grid, and used the overlay() method from sp to cookie-cut the grid with a 
SpatialPolygonsDataFrame object read by readShapePoly() or readOGR(), and 
then simply passed coordinates() of the SpatialPixelsDataFrame object 
created after the overlaying to the loc= argument, you would be very 
close. Use bbox() of the imported SpatialPointsDataFrame object to find 
out what the grid should be. Consider reading the vignette of the sp 
package - and finally just output the SpatialPixelsDataFrame augmented 
with the prediction as a new column as a GeoTiff file using writeGDAL() in 
rgdal, choosing only the predictions.

There are a number of steps to take, but it does work.

Hope this helps,

Roger

>
>
>
> Another question:
>
> as you can see I am predicting my values to a square set of points...
> my question is how can I can I generate a set of point that match a
> specific area (because I have a specific limite(area) in an esri's
> shapefile).
>
>
>
> Thanks in advance.
> Carlos
>
>
>
> Carlos GUERRA
>
> Gabinete de Sistemas de Informacao Geografica
> Escola Superior Agraria de Ponte de Lima
> Mosteiro de Refoios do Lima
> 4990-706 Ponte de Lima
>
> Tlm: +351 91 2407109
> Tlf: +351 258 909779
>
> Be a Mac user... update your self!
>
>
> 	[[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at 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: Roger.Bivand at nhh.no




More information about the R-sig-Geo mailing list