PRJ files define the projection of the shapefile. To create one define the projection in ArcCatalog either by using the tool Define Projection or right click on the layer and select properties (there's a whole dialog there).
It would also be sufficient to copy the prj file from your input and rename it to match the shape file.
Considering you're doing this as part of a tool I'd go with define projection...
# get spatial reference from an existing object
desc = arcpy.Describe(InputData)
SR = desc.spatialReference
# set the spatial reference of a feature class
arcpy.DefineProjection_management(outFeatureClass,SR)
I notice your script has spatial_ref = arcpy.GetParameter(2)
, there may be problems with that.. perhaps you should be using spatial_ref = arcpy.GetParameterAsText(2)
or there may be problems with the definition. I generally use sys.argv[n]
to access parameters I don't experience problems there. Check to see if your spatial reference is an object:
SR = arcpy.SpatialReference(28355) # one for example
print type(SR)
<class 'arcpy.arcobjects.arcobjects.SpatialReference'>
print len(SR)
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
TypeError: object of type 'SpatialReference' has no len()
Where defining as text:
SR = "PROJCS['GDA_1994_MGA_Zone_55',GEOGCS['GCS_GDA_1994',DATUM['D_GDA_1994',SPHEROID['GRS_1980',6378137,298.257222101]],PRIMEM['Greenwich',0],UNIT['Degree',0.017453292519943295]],PROJECTION['Transverse_Mercator'],PARAMETER['False_Easting',500000],PARAMETER['False_Northing',10000000],PARAMETER['Central_Meridian',147],PARAMETER['Scale_Factor',0.9996],PARAMETER['Latitude_Of_Origin',0],UNIT['Meter',1]]"
print type(SR)
<type 'str'>
print len(SR)
396
To ensure that your spatial reference as passed contains a value, if it's a string check the length of the string to ensure it's not ''