Project Trasformation for a list of shp don't work

698
1
01-09-2014 01:40 AM
francescodi_vito
New Contributor
hello guys.
I wrote this script that should read a list of shp file from a folder and then define the spatial and then the project.
How do I create db before, and in one of these I'm going to put the result.
The model works but does not run the project.
Can you help? I do not understand why is not working
This is my script
import arcpy, os
from arcpy import env

# Envirement Settings
arcpy.env.workspace = arcpy.GetParameterAsText(0)

# Variabili per la funzione di CreateFileGDB
out_folder_gdb = arcpy.GetParameterAsText(1)
name_gdb = arcpy.GetParameterAsText(2)
out_folder_gdb_utm = arcpy.GetParameterAsText(3)
name_gdb_utm = arcpy.GetParameterAsText(4)

# Creazione dei DB
arcpy.CreateFileGDB_management(out_folder_gdb, name_gdb)
arcpy.CreateFileGDB_management(out_folder_gdb_utm, name_gdb_utm)


# Imposto lista elementi
fcs = arcpy.ListFeatureClasses('*')


imposto variabile locale
try:
    for f in fcs:
        inData = f
        coordinateSystems = "PROJCS['Monte_Mario_Rome_Italy_1',GEOGCS['GCS_Monte_Mario_Rome',DATUM['D_Monte_Mario',SPHEROID['International_1924',6378388.0,297.0]],PRIMEM['Rome',12.45233333333333],UNIT['Degree',0.0174532925199433]],PROJECTION['Transverse_Mercator'],PARAMETER['False_Easting',1500000.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',-3.45233333],PARAMETER['Scale_Factor',0.9996],PARAMETER['Latitude_Of_Origin',0.0],UNIT['Meter',1.0]]"
        arcpy.DefineProjection_management(inData, coordinateSystems)
        arcpy.Project_management(inData,out_folder_gdb + "/" + name_gdb + ".gdb", "WGS 1984 UTM Zone 32N","", "Monte_Mario_To_WGS_1984_4")
except arcpy.ExecuteError:
    print(arcpy.GetMessages(2))
    
except Exception as ex:
    print(ex.args[0])

thank you very much
greetings
Tags (2)
0 Kudos
1 Reply
JakeSkinner
Esri Esteemed Contributor
Hi Francesco,

It doesn't look like you are specifying name for the output feature class in the Project tool.  Also, you have a parameter commented out in the Project tool.  Try the following:

try:
    for f in fcs:
        inData = f        
        coordinateSystems = arcpy.SpatialReference(26591)
        arcpy.DefineProjection_management(inData, coordinateSystems)
        output = out_folder_gdb + "\\" + name_gdb + ".gdb" + "\\" + inData.split(".")[0]
        coordinateSystems = arcpy.SpatialReference(32632)
        arcpy.Project_management(inData, output, coordinateSystems,"Monte_Mario_Rome_To_Monte_Mario + Monte_Mario_To_WGS_1984_4")
except arcpy.ExecuteError:
    print(arcpy.GetMessages(2))


Note:  I used arcpy.SpatialReference and the coordinate system code to shorten the amount of text.
0 Kudos