[Tutor] Changing spatial reference of shapefiles in folder and exporting to new folder

Danny Yoo dyoo at hashcollision.org
Sun Apr 12 01:50:07 CEST 2015


Hi Michael,

Your question appears to be specifically about the ArcGIS library.
Unfortunately, I would assume very few of us have expertise on this
particular third-party mapping library; we're mostly a  forum for
teaching basic Python programming.  We can help on non-domain-specific
Python-learning issues, but for anything that's specific to ArcGIS,
you'll probably have more success talking to the ArcGIS folks.  I
believe you can find the ArcGIS folks at:
https://geonet.esri.com/community/developers/gis-developers/python


With that in mind: I will take a look at your program from a neutral
standpoint, assuming no domain-specific knowledge:

1.  Your program is malformed because it has a "try" block, but with
no "except" or "finally".  This is a syntax error.  The program is not
perfectly formed, so Python will not run your program until it has the
form of a correct program.  (Whether it does what you want is an
entirely different, "semantic" matter.)

When you're using 'try', your program is grammatically prompting the
setting up of an exception handler.

##################################
try:
    inFolder = arcpy.ListFeatureClasses()
    ...
##################################

... But your program has omitted what should happen if an exception
does occur!  What should happen if things go wrong?  Since that hasn't
been written in your program, it's ungrammatical.

See: https://docs.python.org/2/tutorial/errors.html for examples of
programs that have exception handlers to see how to correct this.
Alternatively: remove the exception handling altogether.  Often,
beginners put exception handling in because they don't realize that
error messages are awesome.  When there's an error, you usually *want*
to see the errors show up, at least while you are developing your
software.


2.  The line:

    template = arcpy.GetParameteAsText(1)

does not look correct because there's a inconsistently-spelled method
name "GetParameteAsText".

The line that follows immediately afterwards uses "GetParameterAsText":

    outFolder = arcpy.GetParameterAsText(2)

and so this inconsistency attracts my eye.  But because of the
domain-specificness, I can't say for certain that this is wrong, only
that it looks very not-quite-right.


More information about the Tutor mailing list