Skip to content

converting shapes to raster

2 messages · Antonio Silva, Michael Sumner

#
Dear list members



In order to run a niche overlap analysis with nicheOverlap (dismo package)
I need to convert some shapefiles to raster. I dropped a shapefile as
example at https://www.dropbox.com/s/g6o0vfdx7lr34ma/Species1Shape.rar?dl=0

Marine fish abundance data is aggregated in quadrants of 10 x 10 nautical
miles. As I have a coast line some quadrants are cut and also I have a
blank area (land area).

I tried many things like:

shp.frtcost <- readShapePoly("BL10_FRT_COSTEIRA.shp")

plot(shp.frtcost,axes=TRUE,xlim=c(-48,-45),border="grey")

text(coordinates(shp.frtcost),labels=as.character(shp.frtcost at data
$DENS),cex=0.7)

r <- raster(extent(shp.frtcost),nrows=10,ncols=15)

# or raster(extent(shp.frtcost),nrows=10,ncols=15,vals=shp.frtcost at data
$DENS)

r <- rasterize(shp.frtcost,r,fun="first")

plot(shp.frtcost,axes=TRUE,xlim=c(-48,-45),border="grey")

plot(r,add=TRUE)



Shape and raster don't overlay correctly and also I could not pass
densities values to raster.


Limits indicated at extent function do not indicate the limits of my grid.



Thanks for any help.



Best regards


Ant?nio Olinto ?vila da Silva
Instituto de Pesca (Fisheries Institute)
S?o Paulo, Brasil
#
On Fri, 5 Feb 2016 at 03:50 Antonio Silva <aolinto.lst at gmail.com> wrote:

            
I can' reproduce the problem? I did this, slightly simpler:

library(raster)

## if you have rgdal available
shp.frtcost <- shapefile("BL10_FRT_COSTEIRA.shp")

## no dropping of projection metadata
r <- raster(shp.frtcost,nrows=10,ncols=15)

r <- rasterize(shp.frtcost,r,fun="first")
plot(shp.frtcost,axes=TRUE,xlim=c(-48,-45),border="grey")
plot(r,add=TRUE)



HTH