3 votos

Python Addin Wizard Combobox scripting ayuda con el zoom a la selección

Estoy codificando un addin que me permita utilizar 3 comboboxes para seleccionar regiones específicas dentro de un estado. Una vez seleccionadas todas en los comboboxes necesito un botón final para hacer zoom a la zona seleccionada, indicada por los comboboxes. No estoy seguro de cómo conseguir que las selecciones de los tres comboboxes se pasen al botón de zoom para que haga zoom a la región seleccionada correcta.

A continuación se muestra mi código:

import arcpy
import pythonaddins

class SectionComboBoxClass35(object):
    """Implementation for SEC_TWN_RNG_2_addin.combobox (ComboBox)"""
    def __init__(self):
        self.items = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10" ,"11", "12", "13", "14",
        "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31",
        "32", "33", "34", "35", "36"]
        self.editable = True
        self.enabled = True
        self.dropdownWidth = 'WWWWWW'
        self.width = 'WWWWWW'
    def onSelChange(self, selection):
        pass
    def onEditChange(self, text):
        pass
    def onFocus(self, focused):
        pass
    def onEnter(self):
        pass
    def refresh(self):
        pass

class TownshipComboBoxClass36(object):
    """Implementation for SEC_TWN_RNG_2_addin.combobox_1 (ComboBox)"""
    def __init__(self):
        self.items = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14",
        "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30",
        "31","32", "32", "33", "34", "35"]
        self.editable = True
        self.enabled = True
        self.dropdownWidth = 'WWWWWW'
        self.width = 'WWWWWW'
    def onSelChange(self, selection):
        pass
    def onEditChange(self, text):
        pass
    def onFocus(self, focused):
        pass
    def onEnter(self):
        pass
    def refresh(self):
        pass

class TownshipDirectionComboBoxClass37(object):
    """Implementation for SEC_TWN_RNG_2_addin.combobox_2 (ComboBox)"""
    def __init__(self):
        self.items = ["N", "S", "E", "W"]
        self.editable = True
        self.enabled = True
        self.dropdownWidth = 'WWWWWW'
        self.width = 'WWWWWW'
    def onSelChange(self, selection):
        pass
    def onEditChange(self, text):
        pass
    def onFocus(self, focused):
        pass
    def onEnter(self):
        pass
    def refresh(self):
        pass

class RangeComboBoxClass38(object):
    """Implementation for SEC_TWN_RNG_2_addin.combobox_3 (ComboBox)"""
    def __init__(self):
        self.items = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14",
        "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30",
        "31","32", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45"]
        self.editable = True
        self.enabled = True
        self.dropdownWidth = 'WWWWWW'
        self.width = 'WWWWWW'
    def onSelChange(self, selection):
        pass
    def onEditChange(self, text):
        pass
    def onFocus(self, focused):
        pass
    def onEnter(self):
        pass
    def refresh(self):
        pass

class RangeDirectionComboBoxClass39(object):
    """Implementation for SEC_TWN_RNG_2_addin.combobox_4 (ComboBox)"""
    def __init__(self):
        self.items = ["N", "S", "E", "W"]
        self.editable = True
        self.enabled = True
        self.dropdownWidth = 'WWWWWW'
        self.width = 'WWWWWW'
    def onSelChange(self, selection):
        pass
    def onEditChange(self, text):
        pass
    def onFocus(self, focused):
        pass
    def onEnter(self):
        pass
    def refresh(self):
        pass

class ZoomButtonClass40(object):

    def onClick(self):
        mxd = arcpy.mapping.MapDocument("CURRENT")
        df = arcpy.mapping.ListDataFrames(mxd)[0]
        addLayer = arcpy.mapping.Layer(r'T:\Software\ESRI-GIS\toolbars\sec-twn-rng\KDAGISEDITOR.plss.lyr')
        arcpy.mapping.AddLayer(df, addLayer, "AUTO_ARRANGE")
    """Implementation for Zoom.button (Button)"""
    def __init__(self):
        self.enabled = True
        self.checked = False
    def onClick(self):
        pass
        # Implementation of OnClick method of Button's class
    def onClick(self):
        # Get the current map document and the first data frame.
        mxd = arcpy.mapping.MapDocument('current')
        df = arcpy.mapping.ListDataFrames(mxd)[0]
        # Call the zoomToSelectedFeatures() method of the data frame class
        df.zoomToSelectedFeatures()

2voto

steveax Puntos 316

Probablemente vas a querer formar una cláusula where a partir de los comboboxes. Puede obtener la cláusula valor del combobox mirando el docstring de su clase para obtener el valor real del objeto combobox por el nombre que ve allí. Así que en este ejemplo:

class RangeComboBoxClass38(object):
    """Implementation for SEC_TWN_RNG_2_addin.combobox_3 (ComboBox)"""
    def __init__(self):
        # stuff

El nombre del objeto combobox es combobox_3 por lo que para obtener el valor basta con utilizar combobox_3.value .

Así que utilizando este conocimiento, puede formar una cláusula where con su addLayer variable. Me lo estoy inventando pero podrías hacer algo así en tu ZoomButtonClass40.onClick() método:

field_name = 'SEC' # name of field to search 
delimited = arcpy.AddFieldDelimiters(addLayer, field_name)
where = '{} = {}{}'.format(delimited, combox_2.value, combobox_3.value) #concatenate the values of combobox_2 and combobox_3
arcpy.management.SelectLayerByLocation(addLayer, 'NEW_SELECTION', where)
df.zoomToSelectedFeatures()

i-Ciencias.com

I-Ciencias es una comunidad de estudiantes y amantes de la ciencia en la que puedes resolver tus problemas y dudas.
Puedes consultar las preguntas de otros usuarios, hacer tus propias preguntas o resolver las de los demás.

Powered by:

X