1

I am relatively new to python and I am trying to build a tool within python toolbox with GPSQLExpression as parameter.

I am having trouble with populating its field and value list. Below is part of my code, I put it in updateParameters.

Feature classes in geodatabase were made from OSM data.

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

    p1 = arcpy.Parameter(
        displayName = "In gdb",
        name = "in_gdb",
        datatype = "DEWorkspace",
        parameterType = "Required",
        direction = "Input")

    p2 = arcpy.Parameter(
        displayName = "Geometry type",
        name = "userinput",
        datatype = "GPString",
        parameterType = "Required",
        direction = "Input",
        multiValue = False)

    p2.filter.type = "ValueList"    
    p2.filter.list = ['pt','ln','ply']


    p3 = arcpy.Parameter(
        displayName ="Selected fc",
        name = "fcs_of_gdb",
        datatype = "GPFeatureLayer",
        parameterType = "Required",
        direction = "Input",
        multiValue = True)

    p4 = arcpy.Parameter(
        displayName = "Pick counties",
        name = "colli",
        datatype = "GPString",
        parameterType = "Required",
        direction = "Input",
        multiValue = True)

    p4.filter.type = "ValueList"


    p5 = arcpy.Parameter(
        displayName = "Select Feature Layer",
        name = "fl_gdb",
        datatype = "GPFeatureLayer",
        parameterType = "Required",
        direction = "Input")


    p6 = arcpy.Parameter(
        displayName = "SQL Expresssion",
        name = "expres",
        datatype = "GPSQLExpression",
        parameterType = "Required",
        direction = "Input",
        multiValue = False)

    p6.parameterDependencies = [p5.name]

    p = [
        p1, p2, p3,
        p4, p5, p6
    ]
    return p

Below I attached 2 screenshots from ArcGIS Pro. When I type for ex. highway or any other field name from OSM data scheme - it is fine, no errors, but when I try to write whole SQL expression, error shown below appears and also I cannot compose SQL expression using drop down list, because it is empty.

Any ideas how to write whole SQL expression?

Below error message:

ERROR 000800 The value is not a member of OBJECTID | Shape | highway | building | natural | waterway | amenity | landuse | place | railway | boundary | power | leisure | man_made | shop | tourism | route | historic | aeroway | aerialway | barrier | military | geological | OSMID | osmuser | osmuid | osmvisible | osmversion | osmchangeset | osmtimestamp | osmMemberOf | osmTags | osmSupportingElement | osmMembers | Shape_Length.

enter image description here

enter image description here

EDIT:

Removed meaningless code, fixed bugs. Now code is working properly.

  • Welcome to GIS SE! As a new user be sure to take the Tour. For questions that involve error messages we ask that you show us them in full using text rather than a picture so that they can be searched and also read easily on all devices. There is an edit button beneath your question which will enable you to do that and {} and " " buttons that enables you to format any highlighted text nicely. – PolyGeo Oct 8 '18 at 7:35
0

OK so you are new to python. You have made a fundamental mistake when asking help with code. You have not provided all the code so none of us really know whats the problem...

You have provided images (that's good) but not given us the full story (not good)...

Soo...that said I think you are barking up the wrong tree. Populating a filter makes no sense when an SQL expression is more than just a field name. It's a field-operator-value construct.

I believe the issue is to do with how you define your parameters (but as you have not shown us any of that code I can only assume this is the case...)

When I set the dependency property to the layer then the SQL parameter behaves as expected. No need to pointlessly add fields to a list. See the example below.

def getParameterInfo(self):
    """Define parameter definitions"""
    p0 = arcpy.Parameter("p0","Layer","Input","GPFeatureLayer","Required",True)
    p1 = arcpy.Parameter("p1","SQl Parameter","Input","GPSQLExpression","Required",True)
    p1.parameterDependencies = [p0.name]
    params = [p0,p1]
    return params

Other parameters that make use of the dependency property are discussed in this section of the help file.

UPDATE

Full toolbox code:

import arcpy

class Toolbox(object):
    def __init__(self):
        """Define the toolbox (the name of the toolbox is the name of the
        .pyt file)."""
        self.label = "Toolbox"
        self.alias = ""

        # List of tool classes associated with this toolbox
        self.tools = [Tool]

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"""
        """Define parameter definitions"""
        p0 = arcpy.Parameter("p0","Layer","Input","GPFeatureLayer","Required",True)
        p1 = arcpy.Parameter("p1","SQl Parameter","Input","GPSQLExpression","Required",True)
        p1.parameterDependencies = [p0.name]
        params = [p0,p1]
        return params

    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."""

    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."""
        return

Here is the tool running as expected:

Screen shot

  • So I edited my post, added bunch code. Also, I tried witth some tables - still not working. – JuniorPythonNewbie Oct 11 '18 at 11:54
  • Your code has several basic syntax errors which is stopping the tool interface appear. Are you writing this in an IDE or notepad? ANY IDE would pick up these syntax errors. I still think your use of filters is incorrect. Your p1 displayName has no closing quotes. p5 has some random kolumny2 line which is breaking syntax. How can you miss that? You've set your p6 dependency to a string parameter not a featurelayer (I assume you want to be using p3) – Hornbydd Oct 11 '18 at 14:02
  • Syntax mistakes came along, because I had variables names etc. written in other language than english and I tried to make it more clear to read for english user. I tried with featurelayer and still my SQLExpression is empty, not populated ( I am aware that I set dependency with string). According to the HELP you linked me to - I am supposed to use tables. I tried and still not working. Filters - I need to have populated multiValue String fields to allow user to pick certain feature classes - that was the only soultion which I came up with. Do you have maybe better idea for strings? – JuniorPythonNewbie Oct 12 '18 at 7:49
  • I think you are "over thinking" the problem and placing filters when none are needed, I have updated my answer with a full toolbox code. No need to specify workspace, geometry type, you simply need to create two parameters as I had shown in the original code. – Hornbydd Oct 12 '18 at 11:29
  • Thank you very much for your patience. All your tips were very useful. – JuniorPythonNewbie Oct 12 '18 at 12:44

Your Answer

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

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