Lookup Table in Model Builder

3628
2
Jump to solution
07-31-2014 01:04 PM
DanielHorn
New Contributor II

I'm trying to build a process in Model Builder that takes several SDE Feature Classes (all named M_X_*) and exports them to shape files in a given directory. This seems easy enough, but there are two issues that I'm not sure how to address:

 

  1. Each shape file that gets exported needs to be renamed to something different, with no logic behind the naming convention (M_X_CASING becomes xCasing, M_X_AERIAL_MARKER becomes xAirMrkr, etc.)
  2. One of the feature classes is too large and needs to be split into two shape files. Essentially, we use a where clause and just export it twice.

 

In the past, this entire process was done using a command line script and the sde2shp.exe ArcSDE Utility, but we'd like to get away from that. I was thinking we could wrap all of this into a geoprocessing service that could be executed on demand through ArcMap.

 

Is there a way to do this using the model builder? Maybe a way we could build a lookup table with the feature class name, the name of the exported file, and the where clause, and then iterate through it? Or would I be better off writing a custom python script to do this?

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
FilipKrál
Occasional Contributor III

Hi Daniel,

The limited (if any) options to manipulate strings like file paths in model builder quickly turned me to Python, where things like that area easy to do. Here is how to core of the script you described might look like. I would have to try that and tweak it to be able to publish that as a service, but hopefully it is clear enough to get you started.

import arcpy

import os

osj = os.path.join # define shortcut for a function

# if you need inputs, get them like so:

#some_input = arcpy.GetParameterAsText(0)

#some_other_input = arcpy.GetParameter(1)

sde = 'Database Connections\database_connection.sde'

ows = r'c:\output\workspace'

# lookup of feature class - exported file name - where clause

lookup = [

    (osj(sde, 'M_X_CASING'), osj(ows, 'xCasing'), ''),

    (osj(sde, 'M_X_AERIAL_MARKER'), osj(ows, 'xAirMrkr'), ''),

    (osj(sde, 'M_X_WITHWHERE'), osj(ows, 'xWhere1'), '"COLUMN"=\'high\''),

    (osj(sde, 'M_X_WITHWHERE'), osj(ows, 'xWhere1'), '"COLUMN"=\'low\'')

    #, ...

]

exported = []

for item in lookup:

    fc = item[0]

    out = item[1]

    wc = item[2]

    result_i = arcpy.analysis.Select(fc, out, wc).getOutput(0)

    exported.append(result_i)

# exported is now a list of results but you may not need that

# you will definitely need to set some output, like so:

arcpy.SetParameter(1, exported[0])

# you may want to zip the whole output directory and

# set the zip file as output

# http://resources.arcgis.com/en/help/main/10.1/index.html#//005700000078000000

Filip.

View solution in original post

0 Kudos
2 Replies
FilipKrál
Occasional Contributor III

Hi Daniel,

The limited (if any) options to manipulate strings like file paths in model builder quickly turned me to Python, where things like that area easy to do. Here is how to core of the script you described might look like. I would have to try that and tweak it to be able to publish that as a service, but hopefully it is clear enough to get you started.

import arcpy

import os

osj = os.path.join # define shortcut for a function

# if you need inputs, get them like so:

#some_input = arcpy.GetParameterAsText(0)

#some_other_input = arcpy.GetParameter(1)

sde = 'Database Connections\database_connection.sde'

ows = r'c:\output\workspace'

# lookup of feature class - exported file name - where clause

lookup = [

    (osj(sde, 'M_X_CASING'), osj(ows, 'xCasing'), ''),

    (osj(sde, 'M_X_AERIAL_MARKER'), osj(ows, 'xAirMrkr'), ''),

    (osj(sde, 'M_X_WITHWHERE'), osj(ows, 'xWhere1'), '"COLUMN"=\'high\''),

    (osj(sde, 'M_X_WITHWHERE'), osj(ows, 'xWhere1'), '"COLUMN"=\'low\'')

    #, ...

]

exported = []

for item in lookup:

    fc = item[0]

    out = item[1]

    wc = item[2]

    result_i = arcpy.analysis.Select(fc, out, wc).getOutput(0)

    exported.append(result_i)

# exported is now a list of results but you may not need that

# you will definitely need to set some output, like so:

arcpy.SetParameter(1, exported[0])

# you may want to zip the whole output directory and

# set the zip file as output

# http://resources.arcgis.com/en/help/main/10.1/index.html#//005700000078000000

Filip.

0 Kudos
DanielHorn
New Contributor II

Thanks, I was able to take your script and with some slight modifications, I think it's going to work for what I need!

Really appreciate the help!

0 Kudos