2

I have a tool with a ValueTable consisting of two columns - text (GPString) and layer (GPFeatureLayer). When I fill the parameter with desired values (field names in the first column, some feature layers in the second column, I can run the tool.

Problem is that not every row is filled with a layer, so some rows have the field names only. The second row of the value table then returns:

  1. a geoprocessing Layer object if it has been filled with a feature layer or
  2. a geoprocessing value object if it has not been filled with a feature layer.

It looks like this:

tool

I have a problem accessing the values row by row - I want to process all the rows with filled feature layer:

...
def getParameterInfo(self):
    """Define parameter definitions"""
    param0 = parameter("lokality", "Lokality", "GPFeatureLayer")
    param1 = parameter("value_table", "Atributy a FeatureLayery", "GPValueTable", "Optional")

    param1.columns = [["String", "Atribut"], ["GPFeatureLayer", "Limity"]]

 def execute(self, parameters, messages):
    """The source code of the tool."""
    lokality = parameters[0].valueAsText
    valuetable = parameters[1].value

    for v in valuetable:
       # if v[1] has been filled, it is a geoprocessing layer object. I can check e.g. its name and continue
       if v[1].name:   
          do something

       # if v[1] has not been filled, it is an empty(?) geoprocessing value object, I don´t know how to handle this empty row

How can I check if a layer has been filled and process rows with filled layers only?

4
  • Try something like if v[1] is None: or if v[1] == None: Does that work?
    – Hornbydd
    Commented Dec 3, 2020 at 13:26
  • Edit: not a LayerObject and ValueObject but "geoprocessing Layer object" and "geoprocessing value object". Interesting that Layer object is with a capital L and value object is not. Question updated.
    – jonlew
    Commented Dec 3, 2020 at 13:32
  • if not v[1]:, if v[1] is None: nor if v[1] == None not working... the empty GPFeatureLayer returns "something" even if it hasn´t been filled with a feature layer... that´s the problem
    – jonlew
    Commented Dec 3, 2020 at 13:39
  • I could possibly put the if v[1].name: to try-except block, so if v[1] was a layer object, it should go on, otherwise it would cast an exception. But I wouldn´t be much happy with this.
    – jonlew
    Commented Dec 3, 2020 at 13:45

1 Answer 1

2

I was not able to test if the returned object was a geoprocessing Layer object or a geoprocessing value object so I put if v[1].name into try-except block and it works.

for v in valuetable:
   try:
      if v[1].name:             
         ...do something with the layer

   except:
      ...do something else or don´t do anything (pass)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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