Quantcast
Channel: Question and Answer » arcpy
Viewing all articles
Browse latest Browse all 767

ArcPy combination of different featurelayers in Combox

$
0
0

I developed a Combox which:

  1. combines values from different featurelayers
  2. the User can select an ID or activitycode (acode)
  3. the active view zooms to the object (biotop or Protected Area)

The Combobox works, but it is very slow, because it looks up in every layer 2 times – one time for putting the values in the combobox and second time for finding the selected feature and zoom to it. My question is, how can I make the search faster.

Here is my code:

class SiteComboBoxClass4(object):
"""Implementation for Site_Python_Addins_addin.combobox (ComboBox)"""
def __init__(self):
self.items = []
self.editable = True
self.enabled = True
self.dropdownWidth = 'WWWWWWWWW'
self.width = 'WWWWWWWWW'
def onFocus(self, focused):
if focused:
    self.mxd = arcpy.mapping.MapDocument('current')
    global items, site, akode, fc_biotop_pol, fc_biotop_poi, fc_biotop_li, fc_pro1_pol, fc_pro1_poi, fc_pro1_li  
    items = []
    site = "SITE_ID" #Attribute fields of the features
    acode = "ACODE" #Attribute fields of the features
    fc_biotop_pol = "Biotop (Polygon)"
    fc_biotop_poi = "Biotop (Point)"
    fc_biotop_li = "Biotop (Line)"
    fc_pro1_pol = "Protection Area 1 (Polygon)"
    fc_pro1_poi = "Protection Area 1 (Point)"
    fc_pro1_li = "Protection Area 1 (Line)"
    Cursor_1 = arcpy.da.SearchCursor(fc_biotop_pol,site)
    Cursor_2 = arcpy.da.SearchCursor(fc_biotop_poi,site)
    Cursor_3 = arcpy.da.SearchCursor(fc_biotop_li,site)
    Cursor_4 = arcpy.da.SearchCursor(fc_pro1_pol,site)
    Cursor_5 = arcpy.da.SearchCursor(fc_pro1_poi,site)
    Cursor_6 = arcpy.da.SearchCursor(fc_pro1_li,site)
    Cursor_7 = arcpy.da.SearchCursor(fc_pro1_pol,acode)
    Cursor_8 = arcpy.da.SearchCursor(fc_pro1_poi,acode)
    Cursor_9 = arcpy.da.SearchCursor(fc_pro1_li,acode)
    for row in Cursor_1: items.append(row[0])
    for row in Cursor_2: items.append(row[0])
    for row in Cursor_3: items.append(row[0])
    for row in Cursor_4: items.append(row[0])
    for row in Cursor_5: items.append(row[0])
    for row in Cursor_6: items.append(row[0])
    for row in Cursor_7: items.append(row[0])
    for row in Cursor_8: items.append(row[0])
    for row in Cursor_9: items.append(row[0])
    self.items = sorted(items)                            
pass

def onSelChange(self, selection):
combobox.enabled = True
self.value = selection
self.mxd = arcpy.mapping.MapDocument('current')
self.df = arcpy.mapping.ListDataFrames(self.mxd)[0]  

arcpy.SelectLayerByAttribute_management(fc_biotop_poi, "NEW_SELECTION", site + "='" + selection + "'")
self.df.zoomToSelectedFeatures()
arcpy.SelectLayerByAttribute_management(fc_biotop_li, "NEW_SELECTION", site + "='" + selection + "'")
self.df.zoomToSelectedFeatures()
#arcpy.RefreshActiveView()
arcpy.SelectLayerByAttribute_management(fc_biotop_pol, "NEW_SELECTION", site + "='" + selection + "'")
self.df.zoomToSelectedFeatures()
arcpy.SelectLayerByAttribute_management(fc_pro1_poi, "NEW_SELECTION", site + "='" + selection + "'")
self.df.zoomToSelectedFeatures()
arcpy.SelectLayerByAttribute_management(fc_pro1_li, "NEW_SELECTION", site + "='" + selection + "'")
self.df.zoomToSelectedFeatures()
arcpy.SelectLayerByAttribute_management(fc_pro1_pol, "NEW_SELECTION", site + "='" + selection + "'")
self.df.zoomToSelectedFeatures()
arcpy.SelectLayerByAttribute_management(fc_pro1_poi, "NEW_SELECTION", acode + "='" + selection + "'")
self.df.zoomToSelectedFeatures()
arcpy.SelectLayerByAttribute_management(fc_pro1_li, "NEW_SELECTION", acode + "='" + selection + "'")
self.df.zoomToSelectedFeatures()
arcpy.SelectLayerByAttribute_management(fc_pro1_pol, "NEW_SELECTION", acode + "='" + selection + "'")
self.df.zoomToSelectedFeatures()
pass

Viewing all articles
Browse latest Browse all 767

Trending Articles