Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I want to clip rasters in data view using interactive rectangle (to define Area of Interest) and add them to current dataframe. Following is a piece of code which is not returning anything. Any suggestions to correct it would be appreciative:

import arcpy
import pythonaddins

def __init__(self):
    self.enabled = True
    self.cursor = 1
    self.shape = 'Rectangle'

def onRectangle(self, rectangle_geometry):
    """Occurs when the rectangle is drawn and the mouse button is released.
    The rectangle is a extent object."""

    extent = rectangle_geometry

    ras1 = arcpy.Clip_management(r"C:/temp/ras",
                                extent.XMin extent.YMin extent.XMax extent.YMax,
                                ras1, "#", "#", "NONE")
    arcpy.RefreshActiveView()
    return ras1
share|improve this question
1  
I'm confused - your question is tagged arcgis-10.0 but you mention pythonaddins and python27 which are both 10.1. Also, even assuming you are using 10.1, "The pythonaddins module can only be used within a Python add-in. It cannot be used in stand-alone scripts or geoprocessing script tools.", so can you confirm that you are NOT trying to do the latter? –  PolyGeo Dec 17 '12 at 5:04
    
You are right, it should be 10.1. I am using it within Python add-in, not as stand-alone script. –  Ibe Dec 18 '12 at 7:02
    
I am not sure about it. Isn't Extent already an Envelop? Maybe you need to pass the extent only. –  Emi Jan 14 '13 at 9:42

2 Answers 2

up vote 2 down vote accepted

Here is code snippet for people who would like to use it:

import arcpy 
import pythonaddins

class DrawRectangle(object):
    """Implementation for rectangle_addin.tool (Tool)"""
    def __init__(self):
        self.enabled = True
        self.cursor = 1
        self.shape = 'Rectangle'

    def onRectangle(self, rectangle_geometry):
        extent = rectangle_geometry
        arcpy.Clip_management(r"data/iras",
                              "%f %f %f %f" % (extent.XMin, extent.YMin, extent.XMax, extent.YMax),
                              "oras", "#", "#", "NONE")
        arcpy.RefreshActiveView()
share|improve this answer
    
Please mark your answer as accepted so others can find it. –  Jason Scheirer Jan 24 '13 at 20:14
    
Thanks for pointing that out. –  Ibe Jan 25 '13 at 0:23

try to put your rectangle dimensions in strings as:

ras1 = arcpy.Clip_management(r"C:/temp/ras",
                                str(extent.XMin extent.YMin extent.XMax extent.YMax),
                                ras1, "#", "#", "NONE")

i hope it helps you..

share|improve this answer
    
Thanks for suggestion but tool is unresponsive and nothing happens upon clicking it. –  Ibe Nov 30 '12 at 0:11
    
I got it working myself. –  Ibe Jan 24 '13 at 8:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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