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:
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?
Solved! Go to Solution.
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.
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.
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!