8

I have to get an extent of a given raster so that I can save it and use the same to clip another raster with that extracted extent. As of now I am stuck in the extent part.

import arcpy
from arcpy import env


desc= arcpy.env.extent("D:\GIS @ UTD\Sem 1\GISC 6317\Lab\Lab 10\temp\Tahoe\Tahoe\Emer\erelev.grid")

print desc

The following gives an output 0 0 0 0 NaN NaN NaN NaN.

Any suggestions.

18

Dont use env.extent you need to get raster extent.

import arcpy

elevRaster = arcpy.sa.Raster('C:/data/elevation')
myExtent = elevRaster.extent

print myExtent

i hope it helps you...

1

Please use the following script, which should work... Please change the path as per the location (Either in Geodatabase or Folders). In this example 'congrd' is the raster dataset that I used.

import arcpy

from arcpy.sa import *

elevRaster = Raster('C:/arcgis/ArcTutor/3DAnalyst/Exercise2/workspace2/congrd')

myExtent = elevRaster.extent

print myExtent

I hope this helps.

  • 2
    -1 This is effectively the same answer as the one posted by @Aragon. – Fezter Nov 22 '12 at 3:26
  • 3
    I tried yours and it failed...That is why I had posted the tweaked one...I guess "import arcpy" alone cannot do the trick. Sometimes we need a little push. – Jegan Somu Nov 23 '12 at 9:04
  • @JeganSomu You can always edit existing answer instead of creating barely different one. If you don't have enough points, your edits will be reviewed first. – mlt Jan 16 '14 at 17:00

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.