1

In modelbuilder I am trying to create a tool which will check the coordinate system of the input shapefile. If it is GCS_WGS_1984, then nothing happens. If it is not, then it will reproject it to GCS_WGS_1984.

I know I have to create a script and import the tool to modelbuilder, which I have done. Below is the script I used:

import arcpy, os
from arcpy import env
env.overwriteOutput = True
arcpy.CheckOutExtension("Spatial")

Footprints = arcpy.GetParameterAsText(0)

desc = arcpy.Describe(Footprints)
type = desc.spatialReference

try:
    if type.name == "GCS_WGS_1984":
        arcpy.SetParameterAsText(1, "True")
        arcpy.SetParameterAsText(2, "False")
    else:
        arcpy.SetParameterAsText(1, "False")
        arcpy.SetParameterAsText(2, "True")

except Exception as e:
AddPrintMessage(e[0], 2)

And my model: enter image description here

I connected the "NOT" to the "PROJECT" and set it as a precondition, but when I try to run it, I get an error telling me that no input is set for the Project Function. I know that the Footprints are not GCS_WGS_1984. So how do I get the model to run properly?

Is there a problem with the model, script, or both? Thanks!


Ok, so I added in the project tool as suggested, but then I get the following error:

ExecuteError: ERROR 000622: Failed to execute (Project). Parameters are not valid. ERROR 000628: Cannot set input into parameter out_coor_system.

My script now looks like

import arcpy, os
from arcpy import env
env.overwriteOutput = True
arcpy.CheckOutExtension("Spatial")

Footprints = arcpy.GetParameterAsText(0)
NewProject = arcpy.GetParameterAsText(2)
OutCoorSys = "GCS_WGS_1984"

desc = arcpy.Describe(Footprints)
type = desc.spatialReference

if type.name == "GCS_WGS_1984":
    arcpy.SetParameterAsText(1, "True")
else:
    arcpy.Project_management(Footprints, NewProject, OutCoorSys) 
  • 1
    Although I like PolyGeo's answer as an alternative, to answer your question why you're receiving the error, it is because you have not set the input for the project tool. You have only checked for a coordinate system. A precondition in Model Builder is only helpful when you need to specify the order in which processes run. Like I said in the beginning, PolyGeo suggests adding the project line into your conditional Check script. -> arcpy.Project_management(input_features, output_features_class, out_coordinate_system) (Replace variables accordingly. – evv_gis Feb 25 '14 at 21:38
1

I think you will find this easier to do if you enhance your Check script to be a "CheckAndProject" script.

In other words bring the Project tool into your script.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.