I need to import a shapefile into R and turn it into a Raster object. I am using the following code:
map <- readOGR("path and file name")
r <- raster(ncol=4001, nrow=4001)
r <- rasterize(map, r)
When I import the shapefile, the resulting SpatialPolygonsDataFrame has the correct coordinates and extent:
map class : SpatialPolygonsDataFrame features : 1 extent : 22.97518, 23.09783, -34.09091, -34.0243 (xmin, xmax, ymin, ymax) crs : +proj=longlat +datum=WGS84 +no_defs variables : 11 names : Name, descriptio, timestamp, begin, end, altitudeMo, tessellate, extrude, visibility, drawOrder, icon value : Knysna box, NA, NA, NA, NA, NA, -1, 0, -1, NA, NA
However, as soon as I try to rasterize the object, it completely changes the coordinates and extent:
r class : RasterLayer dimensions : 4001, 4001, 16008001 (nrow, ncol, ncell) resolution : 0.08997751, 0.04498875 (x, y) extent : -180, 180, -90, 90 (xmin, xmax, ymin, ymax) crs : +proj=longlat +datum=WGS84 +no_defs source : memory names : layer values : 1, 1 (min, max) attributes : ID Name descriptio timestamp begin end altitudeMo tessellate extrude visibility drawOrder 1 Knysna box -1 0 -1 icon
Why is it doing this and how can I fix it? Any help would be greatly appreciated!