Specify Geographic Transformation as user input in python script

2027
6
04-27-2011 02:55 PM
KarenMiller
New Contributor II
I have a script that includes the Project Raster process. The standard ArcToolbox tool dialog has an optional input to specify the Geographic Transformation. If it detects a datum transformation is needed between your input and output coordinate systems, it will automatically populate the drop-down list with relevant datum transformation options.

I would like to implement this type of parameter in my python script, but haven't been able to figure out how to go about it. The data type for this parameter is listed as "String" so I presume you could enter in the name for a transformation manually (i.e. "NAD_1927_To_NAD_1983_NADCON"), but it'd sure save a lot of trouble (who's going to remember the exact name?) if I could get the list to populate like on the standard tool.

Anyone ever do this successfully?

Many thanks!
Tags (2)
0 Kudos
6 Replies
DarrenWiens2
MVP Honored Contributor
I believe you'd have to use ArcObjects to respond to such an event (choosing input/output datasets).

Edit: I think you can use a Tool Validator.
0 Kudos
RDHarles
Occasional Contributor
I figured out the ones I use most often and set them as a system argument (variable) like this:

# Code 1515, United States 
if sys.argv[2] == "8483":
    print "Setting transformation method to: NAD_1983_To_WGS_1984_5"
    log.write("Setting transformation method to: NAD_1983_To_WGS_1984_5")
    transformation = "NAD_1983_To_WGS_1984_5"

# Code 1241, United States (contiguous 48 states)
if sys.argv[2] == "8327":
    print "Setting transformation method to: NAD_1927_To_NAD_1983_NADCON"
    log.write("Setting transformation method to: NAD_1927_To_NAD_1983_NADCON")
    transformation = "NAD_1927_To_NAD_1983_NADCON"
 
# Code 1901
if sys.argv[2] == "8483harn":
    print "Setting transformation method to: NAD_1983_HARN_To_WGS_1984_3"
    log.write("Setting transformation method to: NAD_1983_HARN_To_WGS_1984_3")
    transformation = "NAD_1983_HARN_To_WGS_1984_3"

# If you're not changing the datum...
if sys.argv[2] == "none":
    print "Setting transformation method to: none"
    log.write("Setting transformation method to: none")                 
    transformation = ""

0 Kudos
GhislainPrince
Esri Contributor
Hi guys,
what you're trying to do here is non easy at 10.0.  We're working on some nice functions for the 10.1 release to do exactly what you're asking for.

This is still under development and subject to change... but here's what it should look like at 10.1.  Then you could put the tlist (below) into your script tool's params.filter.list = tlist



>>> from_sr = arcpy.SpatialReference('NAD 1983 HARN UTM Zone 11N')
>>> to_sr = arcpy.SpatialReference('NAD 1927 StatePlane California VI FIPS 0406')
>>> 
>>> # extent of San Diego county in from_sr coords
>>> ex = arcpy.Extent(444450.2212, 3599832.1877, 585727.9387, 3707930.3429)
>>> 
>>> tlist = arcpy.ListTransformations(from_sr, to_sr,ex)
>>> pprint.pprint(sorted(outlist))
[u'NAD_1983_HARN_PACP00_MARP00_To_WGS_1984 + NAD_1927_To_WGS_1984_18',
 u'NAD_1983_HARN_PACP00_MARP00_To_WGS_1984 + NAD_1927_To_WGS_1984_4',
 u'NAD_1983_HARN_PACP00_MARP00_To_WGS_1984 + NAD_1927_To_WGS_1984_6',
 u'NAD_1983_HARN_PACP00_MARP00_To_WGS_1984 + NAD_1927_To_WGS_1984_79_CONUS',
 u'NAD_1983_HARN_To_WGS_1984 + NAD_1927_To_WGS_1984_18',
 u'NAD_1983_HARN_To_WGS_1984 + NAD_1927_To_WGS_1984_4',
 u'NAD_1983_HARN_To_WGS_1984 + NAD_1927_To_WGS_1984_6',
 u'NAD_1983_HARN_To_WGS_1984 + NAD_1927_To_WGS_1984_79_CONUS',
 u'NAD_1983_HARN_To_WGS_1984_2 + NAD_1927_To_WGS_1984_18',
 u'NAD_1983_HARN_To_WGS_1984_2 + NAD_1927_To_WGS_1984_4',
 u'NAD_1983_HARN_To_WGS_1984_2 + NAD_1927_To_WGS_1984_6',
 u'NAD_1983_HARN_To_WGS_1984_2 + NAD_1927_To_WGS_1984_79_CONUS',
 u'NAD_1983_HARN_To_WGS_1984_3 + NAD_1927_To_WGS_1984_18',
 u'NAD_1983_HARN_To_WGS_1984_3 + NAD_1927_To_WGS_1984_4',
 u'NAD_1983_HARN_To_WGS_1984_3 + NAD_1927_To_WGS_1984_6',
 u'NAD_1983_HARN_To_WGS_1984_3 + NAD_1927_To_WGS_1984_79_CONUS',
 u'NAD_1983_To_HARN_CA_S + NAD_1927_To_NAD_1983_NADCON',
 u'WGS_1984_(ITRF00)_To_NAD_1983_HARN + NAD_1927_To_WGS_1984_18',
 u'WGS_1984_(ITRF00)_To_NAD_1983_HARN + NAD_1927_To_WGS_1984_4',
 u'WGS_1984_(ITRF00)_To_NAD_1983_HARN + NAD_1927_To_WGS_1984_6',
 u'WGS_1984_(ITRF00)_To_NAD_1983_HARN + NAD_1927_To_WGS_1984_79_CONUS']
>>> 
0 Kudos
DarrenWiens2
MVP Honored Contributor
Would using a Tool Validator work? I've never used one, but it seems like you could use it to populate your combobox.
0 Kudos
LoganPugh
Occasional Contributor III
The easiest way to do it would be to define a parameter (in your script tool parameters tab) that is of type String and has a Value Filter consisting of the names of the common transformations you listed. That way they appear as a dropdown that the user can pick from and the value chosen will be used as the input to your script.

See Setting script tool parameters in the help.

Otherwise I believe you would need to use ArcObjects to do something more intelligent such as listing only those transformations that apply between the two coordinate systems. The method Mr. Prince listed above would certainly make that easily doable within Python at 10.1.

Also, there is a link to a list of all the transformations on this page: http://resources.arcgis.com/content/kbase?fa=articleShow&d=21327
0 Kudos
KarenMiller
New Contributor II
Thanks everyone for your responses! I had thought about using the tool validator, but it looks like you'd still have the problem intelligently populating the list. I agree, the easiest way would be to populate a value list filter with the most commonly used transformations - I simply was hoping I wouldn't have to guess what those will be in the future, in case something unusual comes up. And it looks like the improvements in 10.1 will do exactly what I want to do here. I suppose if one needs to use a transformation that isn't in my predefined list, they could just set it in the environment settings so it will run properly without crashing - that might be an acceptable work-around until 10.1 - whenever that is...

Thanks again- I'll give this a try and see how it goes!
0 Kudos