Clip data and add layer to second dataframe using python Add-In

234
0
02-14-2013 05:15 AM
IbraheemKhan1
New Contributor III
I want to clip a layer from data frame 1 and add it to the data frame 2 using the following script. But instead it just add all grids to current data frame 1 and don't update data frame 2. Please suggest how to stop it from updating data frame 1 TOC and add new layer to data frame 2.

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):
        mxd = arcpy.mapping.MapDocument(r'C:/test.mxd')
        df1 = arcpy.mapping.ListDataFrames(mxd, "View1")[0]
        df2 = arcpy.mapping.ListDataFrames(mxd, "View2")[0]
        extent = rectangle_geometry
        arcpy.Clip_management(r"data/iras",
                              "%f %f %f %f" % (extent.XMin, extent.YMin, extent.XMax, extent.YMax), "oras", "#", "#", "NONE")
        grid1 = arcpy.MakeRasterLayer_management("oras", "grid2", "#", "", "")
        arcpy.SaveToLayerFile_management(grid1, 'grid2.lyr')
        grid3 = arcpy.mapping.Layer('grid2.lyr')
        arcpy.mapping.AddLayer(df2,grid3,"TOP")
Tags (2)
0 Kudos
0 Replies