Phyton script from Modelbuilder (9.3.1 SP2). Command error

811
3
05-22-2013 04:22 AM
CarlosVillalba_Alonso
New Contributor
Dear colleagues,
I'm having a problem with a py script generated from a Model (export to py). The model works fine, and input and output projection data is included, but the script gives an error while projecting data, and it looks like is not taking the input data projection info when exporting to py.

I can not see where the problem lies, especially because the model works fine, but I need script to create a daily execution task.

Below is the history record of the operation, highlighted in bold the command and the error message.

Any help is appreciated.

<CommandLine>Project_management E:\A.gdb\SDE_GIS_APROV_HIDRO_CopyFeatures E:\FileGeodatabase\A.gdb\SDE_GIS_APROV_HIDRO_CopyFeatures_pr PROJCS['ETRS_1989_UTM_Zone_29N',GEOGCS['GCS_ETRS_1989',DATUM['D_ETRS_1989',SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Transverse_Mercator'],PARAMETER['False_Easting',500000.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',-9.0],PARAMETER['Scale_Factor',0.9996],PARAMETER['Latitude_Of_Origin',0.0],UNIT['Meter',1.0]] ED_1950_To_ETRS_1989_12_NTv2_Spain_v2 Unknown</CommandLine>
<ToolSource>C:\Program Files (x86)\ArcGIS\ArcToolbox\Toolboxes\Data Management Tools.tbx\Projections and Transformations\Feature\Project</ToolSource>
<StartTime>Wed May 22 13:52:19 2013</StartTime>
<Parameters>
<Inputs>
<Parameter Label="Input Dataset or Feature Class" Type="Dataset">E:\FileGeodatabase\CHMS_pub.gdb\SDE_GIS_APROV_HIDRO_CopyFeatures</Parameter>
<Parameter Label="Output Coordinate System" Type="Scalar">PROJCS['ETRS_1989_UTM_Zone_29N',GEOGCS['GCS_ETRS_1989',DATUM['D_ETRS_1989',SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Transverse_Mercator'],PARAMETER['False_Easting',500000.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',-9.0],PARAMETER['Scale_Factor',0.9996],PARAMETER['Latitude_Of_Origin',0.0],UNIT['Meter',1.0]]</Parameter>
<Parameter Label="Geographic Transformation" Type="Scalar">ED_1950_To_ETRS_1989_12_NTv2_Spain_v2</Parameter>
<Parameter Label="Input Coordinate System" Type="Scalar">Unknown</Parameter>
</Inputs>
<Outputs>
<Parameter Label="Output Dataset or Feature Class" Type="Dataset">E:\FileGeodatabase\CHMS_pub.gdb\SDE_GIS_APROV_HIDRO_CopyFeatures_pr</Parameter>
</Outputs>
</Parameters>
<Environments>
<Environment Label="Precision For New Coverages">SINGLE</Environment>
<Environment Label="Auto Commit">1000</Environment>
<Environment Label="Minimize memory use during analysis on terrains">false</Environment>
<Environment Label="Compression">LZ77</Environment>
<Environment Label="Coincident Points">MEAN</Environment>
<Environment Label="Random number generator">0 ACM599</Environment>
<Environment Label="Raster Statistics">STATISTICS 1 1</Environment>
<Environment Label="Level Of Comparison Between Projection Files">NONE</Environment>
<Environment Label="Output has Z Values">Same As Input</Environment>
<Environment Label="Maintain fully qualified field names">true</Environment>
<Environment Label="Tile Size">128 128</Environment>
<Environment Label="Pyramid">PYRAMIDS -1 NEAREST</Environment>
<Environment Label="Output Spatial Grid 1">0</Environment>
<Environment Label="Cell Size">MAXOF</Environment>
<Environment Label="Output has M Values">Same As Input</Environment>
<Environment Label="Output Spatial Grid 2">0</Environment>
<Environment Label="Output Spatial Grid 3">0</Environment>
<Environment Label="Precision For Derived Coverages">HIGHEST</Environment>
</Environments>
<Errors>
<Error>Failed to execute. Parameters are not valid.</Error>
<Error>ERROR 000517: The coordinate system is not defined for the input dataset.
Tags (2)
0 Kudos
3 Replies
MathewCoyle
Frequent Contributor
The model builder export to python is just a tool to help convert a model to a script, it is not a perfect conversion and requires modifications to work after the conversion. Also if you want help with your script you should post your script not just the error you receive.
0 Kudos
T__WayneWhitley
Frequent Contributor
Just to give you a little more info on what to look for, the input coord system is not defined as you stated - the evidence is with your provided statement here:

<Parameter Label="Input Coordinate System" Type="Scalar">Unknown</Parameter>

If for some reason it isn't being read properly, then you need to fix that -- your output coordinate system appears to have been set okay, but I assure you no 'project' will work without info on both 'from' and 'to' coordinate systems.  You may have to properly Define Projection on the input dataset before attempting to Project it.

-Wayne
0 Kudos
CarlosVillalba_Alonso
New Contributor
The problem is solved. Apparently, the key was that in the feature class created from event layer the projection has to be defined before executing the command gp.Project_management.

As a sum up of the thread, I would stress that exporting models to py does need editing and revision after the automatic code generation. For instance, you have to specify to overwrite in the gp object, and so on.
So the 'export to script' action in model builder it is a good tool, but it does not guarantee that if the model works the generated script will work straightforward.

Thanks to those who responded.

See below the right code:

# G_A_H2.py
# Created on: jue may 23 2013 09:30:15
#   (generated by ArcGIS/ModelBuilder)
# ---------------------------------------------------------------------------

# Import system modules
import sys, string, os, arcgisscripting

# Create the Geoprocessor object
gp = arcgisscripting.create()
gp.OverwriteOutput = 1

# Load required toolboxes...
gp.AddToolbox("C:/Program Files (x86)/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx")


# Local variables...
G_A_H_event = "HERE GOES THE EVENT TABLE"
sde_sde_GIS_AH = "ORIGINAL TABLE WITH XY DATA"
G_A_H_Prjdefine = "FEAT CLASS GENERATED FROM EVENT TABLE"
G_A_H_Project = "FEAT CLASS PROJECTED"
Aprovechamientos_Hidroelectricos = "FINAL RESULT"
G_A_H_Prjdefine2 = "INTERMEDIATE STEP, FOR PROJECT DEFINITION"

# Process: Make XY Event Layer...
gp.MakeXYEventLayer_management(sde_sde_GIS_AH, "CE_UTM_X", "CE_UTM_Y", G_A_H_event, "")

# Process: Copy Features...
gp.CopyFeatures_management(G_A_H_event, G_A_H_Prjdefine, "", "0", "0", "0")

# Process: Define Projection...
gp.DefineProjection_management(G_A_H_Prjdefine, "PROJCS['ED_1950_UTM_Zone_29N',GEOGCS['GCS_European_1950',DATUM['D_European_1950',SPHEROID['International_1924',6378388.0,297.0]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Transverse_Mercator'],PARAMETER['False_Easting',500000.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',-9.0],PARAMETER['Scale_Factor',0.9996],PARAMETER['Latitude_Of_Origin',0.0],UNIT['Meter',1.0]]")

# Process: Project...
gp.Project_management(G_A_H_Prjdefine2, G_A_H_Project, "PROJCS['ETRS_1989_UTM_Zone_29N',GEOGCS['GCS_ETRS_1989',DATUM['D_ETRS_1989',SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Transverse_Mercator'],PARAMETER['False_Easting',500000.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',-9.0],PARAMETER['Scale_Factor',0.9996],PARAMETER['Latitude_Of_Origin',0.0],UNIT['Meter',1.0]]", "ED_1950_To_ETRS_1989_12_NTv2_Spain_v2", "PROJCS['ED_1950_UTM_Zone_29N',GEOGCS['GCS_European_1950',DATUM['D_European_1950',SPHEROID['International_1924',6378388.0,297.0]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Transverse_Mercator'],PARAMETER['False_Easting',500000.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',-9.0],PARAMETER['Scale_Factor',0.9996],PARAMETER['Latitude_Of_Origin',0.0],UNIT['Meter',1.0]]")

# Process: Copy Features (2)...
gp.CopyFeatures_management(G_A_H_Project, Aprovechamientos_Hidroelectricos, "DEFAULTS", "0", "0", "0")
0 Kudos