TransWikia.com

How to access a "geoprocessing value object" when a row in ValueTable is empty (Python Toolbox)

Geographic Information Systems Asked by jonlew on June 12, 2021

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?

One Answer

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)

Correct answer by jonlew on June 12, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP