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?

3
  • 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
    Commented Mar 10, 2017 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. Commented Mar 10, 2017 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
    Commented Mar 10, 2017 at 20:47

1 Answer 1

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 and acknowledge you have read our privacy policy.

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