0

I have several shapefiels that i have to turn into raster. Here's the coastline

coastline<-readShapeSpatial("shp")
r <- raster(ncols=90, nrows=45)
jd<-rasterize(coastline,r)
plot(jd)

it gives an empty thing with no map, a blank thing.

0

1 Answer 1

3

You may want to consider to tell us why the above code didn't work, i.e. include the referring error message. I just tried to reproduce your issue using the German border from the countriesCoarse dataset included in the rworldmap package and everything worked out fine. Remember to set the projection and the desired extent of your raster template properly, otherwise it will range from -180, 180, -90, 90 (xmin, xmax, ymin, ymax), which would be way too much for our purposes.

## german borders
library(rgdal)
library(rworldmap)
library(raster)

data(countriesCoarse)
spy_germany <- subset(countriesCoarse, GEOUNIT == "Germany")
sln_germany <- as(spy_germany, "SpatialLinesDataFrame")

## raster template
rst_template <- raster(ncols = 30, nrows = 60, 
                       crs = projection(sln_germany), 
                       ext = extent(sln_germany))

## rasterize
rst_germany <- rasterize(sln_germany, rst_template)
plot(rst_germany, col = "grey75", legend = FALSE, xlab = "lon", ylab = "lat")
plot(rasterToPolygons(rst_germany), add = TRUE)

enter image description here

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.