I want to convert R 'library:raster' 'extent' object to a shapefile. I have the CRS available too.

  e=  c(4304916, 4305325, 365216, 365439)#xmin, xmax, ymin, ymax
  proj4string(e) = CRS("+proj=utm +zone=18 +ellps=GRS80 +datum=NAD83 +units=m +no_defs")

In older version of raster data there was a specific function "" 'extentTopolygon' which is depreciated now. My current approach is to create a raster object change its projection and assign the current extent and convert it to shapefile, which is not very efficient.


You can do the following:

e <- extent( c(4304916, 4305325, 365216, 365439) )
p <- as(e, 'SpatialPolygons')
crs(p) <- "+proj=utm +zone=18 +ellps=GRS80 +datum=NAD83 +units=m +no_defs"
shapefile(p, 'file.shp')
  • 1
    Just a comment--the coordinates are given are swapped. The four million values are the 'y' or northing values while the three hundred thousand values are the 'x' or easting values. – mkennedy Sep 27 '15 at 14:15
  • @mkennedy. How so? I do not think so. See plot(p, axes=TRUE) – Robert Hijmans Sep 27 '15 at 15:52
  • Okay, I don't see that in the question or answer (in the current versions), but UTM is always easting,northing so...? You know the software, not me. – mkennedy Sep 27 '15 at 16:42
  • right, and easting is x, and northing is y, hence the order – Robert Hijmans Sep 27 '15 at 20:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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