[GIS] Crop Landsat image using Extent in R

extentsrraster

I'm following a tutorial on Remote Sensing within R and I'm attempting to crop a Landsat image, however I'm getting the error:
Error in validityMethod(object) : invalid extent: ymin >= ymax

My code is:

# Find the current extent
extent(landsat)
class       : Extent 
xmin        : 269625 
xmax        : 337155 
ymin        : 3221685 
ymax        : 3289215 

# Create new extent object
e <- extent(250000, 325000, -3150000,-3250000)

# Crop Landsat
l_crop <- crop(landsat, extent(e))

Is there an error in the syntax or have I missed something?

Best Answer

I'm not all that familiar with R but it looks like you've just mixed up your ymin and ymax values when you create your extent object:

# Arguments are xmin,xmax,ymin,ymax
# Note: ymin > ymax which is invalid.
e <- extent(250000, 325000, -3150000, -3250000) 

If you change it to:

e <- extent(250000, 325000, -3250000, -3150000)

That should create a valid extent object.

Related Question