0

I have this code where te input parameters are a shapefile [param0] and a string list [param1]. The second parameter is a list because I want that user select it.

class Tool(object):
def __init__(self):
    """Define the tool (tool name is the name of the class)."""
    self.label = "Tool"
    self.description = ""
    self.canRunInBackground = False

def getParameterInfo(self):
    """Define parameter definitions"""

param0 = arcpy.Parameter(
        displayName="Capa de Municipios",
        name="in_features",
        datatype="DEShapefile",
            parameterType="Required",
        direction="Input")

param1 = arcpy.Parameter(
        displayName="Municipio",
        name="texto",
        datatype="GPString",
            parameterType="Required",
        direction="Input")

param1.filter.type="ValueList"
param1.filter.list= [u'Guendul\xe1in', u'Muru-Astr\xe1in', u'Zolina', u'Tajonar <> Taxoare', u'Barbat\xe1in', u'Esqu\xedroz', u'Patern\xe1in', u'Sag\xfc\xe9s', u'Zizur Mayor <> Zizur Nagusia', u'Cizur Menor', u'Cordovilla', u'Gaz\xf3laz', u'Mutilva <> Mutiloa', u'Badost\xe1in', u'Bara\xf1\xe1in <> Bara\xf1ain', u'Ardanaz de Eg\xfc\xe9s', u'Sarriguren', u'Pamplona <> Iru\xf1a', u'Arazuri', u'Ororbia', u'Gorraiz', u'Olaz', u'Orkoien', u'Eg\xfc\xe9s', u'Huarte <> Uharte', u'Burlada <> Burlata', u'Ibiricu', u'Elcano', u'Villava <> Atarrabia', u'Anso\xe1in <> Antsoain', u'Iza', u'Berriozar', u'Trinidad de Arre', u'Artica <> Artika', u'Olloki', u'Loza <> Lotza', u'Alzuza', u'Arre', u'Sagaseta', u'Azoz <> Azotz', u'Arleta', u'Ezcaba', u'Aizo\xe1in <> Aitzoain', u'Zuasti', u'Oric\xe1in', u'Berrioplano <> Berriobeiti', u'Aldaba', u'Larragueta', u'Zabaldika', u'Berriosuso <> Berriogoiti', u'Garru\xe9s', u'Egulbati', u'Irotz', u'A\xf1\xe9zcar', u'Eusa', u'Sorauren', u'Ballariain', u'Ad\xe9riz', u'Elcarte', u'Oteiza', u'Makirriain', u'Antxoritz', u'Orrio', u'Ilurdotz', u'Sarasa', u'Unzu', u'Cildoz', u'Zuriain', u'Ollacarizqueta', u'Olave <> Olabe']

    parameters = [param0, param1]
    return parameters

def isLicensed(self):
    """Set whether tool is licensed to execute."""
    return True

def updateParameters(self, parameters):
    """Modify the values and properties of parameters before internal
    validation is performed.  This method is called whenever a parameter
    has been changed."""
    return

def updateMessages(self, parameters):
    """Modify the messages created by internal validation for each tool
    parameter.  This method is called after internal validation."""
    return

def execute(self, parameters, messages):
    """The source code of the tool."""

#--Define the parameters
a=parameters[0].valueAsText
b=parameters[1].valueAsText

des=arcpy.Describe(a)

#--Select by attribute

query =query = """ "ENTIDAD_1" = '%s'"""%b
sel=arcpy.SelectLayerByAttribute_management(a, "NEW_SELECTION", query)

#--Buffer
buffer_a=arcpy.Buffer_analysis(a, sel, "4000 Meters", "FULL", "ROUND", "NONE", "", "PLANAR")

#--Intersect
inters_4=arcpy.Intersect_analysis([a,buffer_a], inters_4, "ALL", "", "INPUT")

    return

Basically I am trying to select [select by attribute] one feature from the shapefile, after that I apply a [buffer] from this feature and finally I do the [intersect] with this buffer and the input shapefile.

When i run the script I get a error in SelectLayerByAttribute

enter image description here

  • 3
    You cant select by attributes on feature classes. You need to create a layer using MakeFeatureLayer with the fc as input then select on this. And remove one Query= in query =query = """ "ENTIDAD_1" = '%s'"""%b – BERA Feb 18 at 11:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.