0

This question already has an answer here:

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.

marked as duplicate by Simbamangu, underdark Jul 13 '15 at 12:22

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • that question is not answered apparently and also downvoted.This is another effort more precise.Hope finds thorough answer this time – gsa Jul 13 '15 at 11:43
  • 1
    It's answered now ... if you're not getting a response, the practice on this site is to edit your question, sharing more about aims and where you're getting stuck, to make sure you're going to get a good response. – Simbamangu Jul 13 '15 at 12:05
  • Sorry @Simbamangu, noticed too late you already answered the related question. – fdetsch Jul 13 '15 at 13:00
1

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

  • Can you tell me how extent works and what refers to? – gsa Jul 13 '15 at 19:34
  • extent extracts the northern, eastern, southern and western bounding coordinate from 'sln_germany' and assigns those geographic limits to the raster template via the 'ext' parameter. Have a look at ?raster::extent for further information. – fdetsch Jul 14 '15 at 5:32

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