1

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?

  • You've got negative Y coordinates (with minus signs) in your extent, but positive coordinates in your landsat data. Is this simply a typo? Did you really mean e <- extent(250000, 325000, 3150000, 3250000) – Spacedman Mar 10 '17 at 12:27
  • The e object is already an extent class object and calling the extent function will cause issues. You do not need to creat the object, just fixe the negative values issue and call extent, with the desired coordinates, in the crop function. – Jeffrey Evans Mar 10 '17 at 15:50
  • Thanks, although I get this: Error in .local(x, y, ...) : extents do not overlap when I try l_crop <- crop(landsat, extent(250000, 325000, -3250000, -3150000)), I have removed the e object. – Steven Mar 10 '17 at 20:47
1

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.

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.