Select to view content in your preferred language

Modelbuilder: Select value from .dbf and use this value to calculate further

3278
8
11-08-2010 10:40 PM
MarkVerlaat
Emerging Contributor
Good day all,

pretty new to modelbuilding and geoprocessing, I'm stuck at one place in my modelbuilder. I would like to do the following thing:

I have a .dbf file, which has a list of vehicles and a couple of vehicle characteristics (for example the width). If the user selects the vehicle of his desire, the model needs to grab this value and use it to calculate if this vehicle can drive upon a road. I have a shapefile with roads and how wide they are.

To select the vehicle and to manually select a width is not a problem. The problem is the connection between those two.

Is this a geoprocessing tool or do I have to write a Python script?

Many thanks in advance,

Mark Verlaat
The Netherlands
0 Kudos
8 Replies
DaleHoneycutt
Deactivated User
If you're using 10.0, there is a Model-Only tool you can use called Get Field Value.  http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Get_Field_Value/004000000006000000/

You can only use Get Field Value in ModelBuilder.  It is accessed from the ModeBuilder menu (Insert > Model Only Tools).  See http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Accessing_Model_Only_tools/002w0000006...

Get Field Value was introduced at 10.0.  If you don't have 10.0, you'll have to write a script tool.  I thought I had this implemented and could attach the script, but unfortunately I can't find it.  The logic is fairly simple... The script takes two arguments, a table and a field.  A cursor is opened on the input table and the value of the field is retrieved from the first record of the input table.  The value is output as the third parameter (i.e., SetParameterAsText(2) ).  Here's the basic (untested) code:

import arcgisscripting
gp = arcgisscripting.create(9.3)
intable = gp.GetParameterAsText(0)
infield = gp.GetParametersAsText(1)

# open cursor
rows = gp.searchcursor(intable)
row = rows.next()
fval = row.GetValue(infield)
gp.SetParameterAsText(2, str(fval))


For more help on creating script tools, start here: http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=An_overview_of_creating_script_tools
0 Kudos
MarkVerlaat
Emerging Contributor
Unfortunately we have 9.3, so I have to write a script. I will test this tomorrow (GMT +1).

So, let me get this clear. The user has to select the vehicle. With the vehicle selected, this script will execute my next tools in the modelbuilder.

Thanks! 🙂
I keep you posted!
0 Kudos
DaleHoneycutt
Deactivated User
What this tool does is output the value of a specific field in the first row of a table (or feature class).  The workflow is that the user selects a single row in a table (the row with your vehicle characteristics, I guess).  The script reads this row and outputs a value (an oval in ModelBuilder).  You then use this value in downstream processes.  So the script doesn't execute anything -- it just outputs a value that you use in ModelBuilder.

Take a look at the discussion in this topic:
http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00400000001m000000.htm

Scroll down until you find the discussion of Get Field Value.  It shows an example model using Get Field Value and in-line variable substitution.  (The script tool I suggested does the same thing as Get Field Value).  This is 10.0 documentation, but it would work exactly the same way in 9.3
0 Kudos
MarkVerlaat
Emerging Contributor
Hey there,

I wrote the script in Python. In ArcGIS I added the script via right mouse click, add script. I wrote down the name of the script, the alias and a brief description. In the next view I searched for the script and I imported the script. So far so good I thought. Then the next screen came;

With a little logic I filled in this:

@ - Input - Table (Required)
@ - Output - Table View (Derived, obtained from input).

Fingers crossed and let it do a test run. So I my model looks like this (see attachment; yeah I know it looks crappy :-), it was made with good old MS Paint; my current workstation has no internet).

With the information above, i try to connect my output with the script. It gives an error:
ERROR 000840: The Value is not a table.

I think my script tool has wrong parameters. unfortunately i cannot think of an other data type to select at the 'add script menu'. Because my main datafile is an .xls or .dbf file (and therefor a table) (I figured out that it doesn't matter which one I selected).

Hopefully you could help me. Thanks in advance though!

Yours,

Mark
0 Kudos
DaleHoneycutt
Deactivated User
Your 1st parameter is a Table View
Your 2nd parameter is a Field, Obtained From is set to the first parameter
These first two parameters are required inputs

Your 3rd parameter is a String and is a derived output.  Obtained From is blank
0 Kudos
MarkVerlaat
Emerging Contributor
Good afternoon dmhoneycutt and others,

thank you for your help. It works great. However, i think I need your expertise one more time.

I wrote a script, which applies the symbology. I wrote it, so the only thing I need is the output from the GetValue script. And that is just the thing I can't write... When I manually enter the value I got from the GetValue script, the model runs perfectly.

The script looks something like this: (do not mind the Dutch words; those are file names)

import sys, string, os, arcgisscripting

gp = arcgisscripting.create()
gp.AddToolbox("filepath/Data Management Tools.tbx")
gp.AddToolbox("filepath/Mark Toolbox.tbx")

String = ? #This has to be the value from the GetValue script
VCI_Laag = "filepath\\Symbology_Files\\"+String +".lyr"
Grondsoorten_Verzadigd = "Grondsoorten_Verzadigd"

gp.ApplySymbologyFromLayer_management(Grondsoorten_Verzadigd, VCI_Laag)
The parameters I used are:
1st: Input = String (From the GetValue script) Required
2nd: Input = Layer (Grondsoorten_Verzadigd, is a shapefile) Required
3rd: Output = Layer (Which combines the shapefile and symbology) Derived; obtained from Layer

Maybe you could help me with the sentence I need to fill at the 'String'.

Thanks in advance;

If you need more info, please ask me.

Mark
0 Kudos
MarkVerlaat
Emerging Contributor
I thought a from ... import code will work. But unfortunately it doesn't.
import sys, string, os, arcgisscripting  
gp = arcgisscripting.create() 
gp.AddToolbox("filepath/Data Management Tools.tbx") 
gp.AddToolbox("filepath/Mark Toolbox.tbx") 

from getValue import *

String = fval #This has to be the value from the GetValue script 
VCI_Laag = "filepath\\Symbology_Files\\"+String +".lyr" 
Grondsoorten_Verzadigd = "Grondsoorten_Verzadigd"
gp.ApplySymbologyFromLayer_management(Grondsoorten_Verzadigd, VCI_Laag)
In bold are the changes I tried to make.

The Error it gives in ArcGIS is a ERROR 999999: Error executing function. A locator with this name does not exist.

If import the getValue.py script in Python it gives an error. (The same as in ArcGIS).

I can't stand it, because I know it's something small (I think it is :)).

Could someone help me? Thanks
0 Kudos
MarkVerlaat
Emerging Contributor
I finally figured it out! I thought, let's combine those two scripts in one. And a miracle happend. It works!

It leaves me with a question though. Why didn't the from getValue import * code work? I had both files in the same folder, but it didn't work. Anyone knows why?

I entered an extra parameter for the script. The first 3 dmhoneycutt gave me; the fourth was Layer which is an required input.

I would like to thank dmhoneycutt for his help
0 Kudos