Hi

I have a shape file (initially produced by intersecting two other shapefiles using the PBSmapping functions) and I would like to turn it into a raster based on a raster layer.

This has worked for me previously:

r<-rasterize(myShape, myRaster, mask=TRUE)

However, my end result is a "blank" raster. That is when I check values I get:

values      : NA, -Inf  (min, max)


Can anyone suggest issues that might cause the result to be a blank raster? I'm totally stumped given that I was able to run this code for a different shapefile (also the intersection of two other shapefiles, one of which is in common with those used to produce "myShape" above). I am also able to successful rasterize both of the shapfiles used to produce "myShape" (myStates and myRange below) which makes me think it's a problem with the intersection. To do the intersection, I used the following script:

library(PBSmapping)

#read in shapefiles
myStates<-reaShapeSpatial(file.choose())
myRange<-readShapeSpatial(file.choose())
p<- CRS("+proj=longlat +datum=WGS84")
proj4string(myStates)<-p
proj4string(myRange)<-p

#convert to PBS format
myStates.pbs<-combinePolys(SpatialPolygons2PolySet(myStates))
myRange.pbs<-combinePolys(SpatialPolygons2PolySet(myRange))


#intersection
myShape<-combinePolys(joinPolys(myRange.pbs,myStates.pbs,"INT"))

#convert to sp format for writing
myShape.sp<-PolySet2SpatialPolygons(myShape)

# and to spatial dataframe
IDs<-sapply(slot(myShape.sp,"polygons"),function(x) slot(s,"ID"))
df<-data.frame(rep(0,length(IDs)),row.names=IDs)
myShape.sp2<-SpatialPolygonsDataFrame(myShape.sp,df)

# write and then read back in before trying to rasterize
writeSpatialShape(myShape.sp2, "myShape")

myShape<-readShapePoly("myShape")

The intersection appears to work (e.g. plot properly) but one thing that I've noticed is that the joinPolys command in PBS mapping no longer allows me to set maxVert...which may be more important for this particular intersection...this is the only difference I can find and I'm not sure why it would matter.


Any help would be much much appreciated.

Thanks!

Julie

	[[alternative HTML version deleted]]

