I have a script that uses the Project geoprocessing tool and my script is giving me the "Parameters are not valid" error.
The weird thing is my script works fine in python 2.7 but not in the python environment created by ArcGIS Pro 3.0.3 (python 3.9.11). I have tried os.path.exists and it comes back as True in both versions. I have tried the tool in ArcGIS Pro using the same file paths, tool works, I then export the tool as python script, doesn't work.
workspaceforCodes = "W:\\GIS\\Tools\\WorkspacesForTools\\Sync.gdb"
PBCGIS_BaseConnection = "W:\\GIS\\WORKING FILES\\EM Working Files\\Databases\\Source.sde"
fcSource = PBCGIS_BaseConnection + "\\PARCELS"
projectedOutput = workspaceforCodes + "\\PARCELS_reprojected"
print("Cleaning up workspace. Removing old Reprojected Parcels.")
if arcpy.Exists(projectedOutput):
arcpy.Delete_management(projectedOutput)
try:
print("Reprojecting PARCELS to be Florida State Plane.") # arcpy.Project_management
arcpy.management.Project(in_dataset=fcSource, out_dataset=projectedOutput,
out_coor_system="102658",
transform_method="NAD_1983_To_HARN_Florida",
in_coor_system="102258",
preserve_shape="NO_PRESERVE_SHAPE", max_deviation="", vertical="NO_VERTICAL")
print("PAO.PARCELS dataset reprojected to 'NAD_1983_StatePlane_Florida_East_FIPS_0901_Feet'"
" from 'NAD_1983_HARN_StatePlane_Florida_East_FIPS_0901'")
except():
print("Projecting PBC Parcels failed. Check the variables for the 'Project' geoprocessing tool")
Solved! Go to Solution.
Code appears sound, besides the spaces in the file paths making my eye twitch. 😉
I'm not sure why those paths are tripping up the tool. In additon to os.path.exists, you could try os.access(fcSource, os.R_OK):
import os
# Check if the file is readable
if os.access(fcSource, os.R_OK):
print(f"You have read permission on the file {fcSource}")
else:
print(f"You do not have read permission on the file {fcSource}")
Also, you shouldn't need to... but you could try using "pathlib".
from pathlib import Path
import arcpy
workspaceforCodes = Path("W:/GIS/Tools/WorkspacesForTools/Sync.gdb")
PBCGIS_BaseConnection = Path("W:/GIS/WORKING FILES/EM Working Files/Databases/Source.sde")
fcSource = PBCGIS_BaseConnection / "PARCELS"
projectedOutput = workspaceforCodes / "PARCELS_reprojected"
print("Cleaning up workspace. Removing old Reprojected Parcels.")
if arcpy.Exists(str(projectedOutput)):
arcpy.Delete_management(str(projectedOutput))
try:
print("Reprojecting PARCELS to be Florida State Plane.")
arcpy.management.Project(in_dataset=str(fcSource), out_dataset=str(projectedOutput), out_coor_system="102658", transform_method="NAD_1983_To_HARN_Florida", in_coor_system="102258", preserve_shape="NO_PRESERVE_SHAPE", max_deviation="", vertical="NO_VERTICAL")
print("PAO.PARCELS dataset reprojected to 'NAD_1983_StatePlane_Florida_East_FIPS_0901_Feet' from 'NAD_1983_HARN_StatePlane_Florida_East_FIPS_0901'")
except Exception as e:
print(f"Projecting PBC Parcels failed. Check the variables for the 'Project' geoprocessing tool: {e}")
Did you migrate the python script from python 2.7 to 3.x by just making the appropriate code changes?
I originally made this script for python 2.7 and updated the syntax or tool name changes.
Code appears sound, besides the spaces in the file paths making my eye twitch. 😉
I'm not sure why those paths are tripping up the tool. In additon to os.path.exists, you could try os.access(fcSource, os.R_OK):
import os
# Check if the file is readable
if os.access(fcSource, os.R_OK):
print(f"You have read permission on the file {fcSource}")
else:
print(f"You do not have read permission on the file {fcSource}")
Also, you shouldn't need to... but you could try using "pathlib".
from pathlib import Path
import arcpy
workspaceforCodes = Path("W:/GIS/Tools/WorkspacesForTools/Sync.gdb")
PBCGIS_BaseConnection = Path("W:/GIS/WORKING FILES/EM Working Files/Databases/Source.sde")
fcSource = PBCGIS_BaseConnection / "PARCELS"
projectedOutput = workspaceforCodes / "PARCELS_reprojected"
print("Cleaning up workspace. Removing old Reprojected Parcels.")
if arcpy.Exists(str(projectedOutput)):
arcpy.Delete_management(str(projectedOutput))
try:
print("Reprojecting PARCELS to be Florida State Plane.")
arcpy.management.Project(in_dataset=str(fcSource), out_dataset=str(projectedOutput), out_coor_system="102658", transform_method="NAD_1983_To_HARN_Florida", in_coor_system="102258", preserve_shape="NO_PRESERVE_SHAPE", max_deviation="", vertical="NO_VERTICAL")
print("PAO.PARCELS dataset reprojected to 'NAD_1983_StatePlane_Florida_East_FIPS_0901_Feet' from 'NAD_1983_HARN_StatePlane_Florida_East_FIPS_0901'")
except Exception as e:
print(f"Projecting PBC Parcels failed. Check the variables for the 'Project' geoprocessing tool: {e}")
I tried the first suggestion in the ArcGIS Pro python window and I got the message: "You do not have read permission on the file...". I am not sure how this makes sense when I can run the script in python 2.7?
I also tried the code changes from your second suggestion and I get the same message in the Try Statement and I also get this:
Traceback (most recent call last):
File "W:\GIS\WORKING FILES\EM Working Files\Python Projects\Testing Phase\Update_WUD_PARCELS_toPBC.py", line 135, in <module>
Parcels(prodDB_LandBase, prodDB_BaseConnection, workspaceforCodes, PBCGIS_BaseConnection, pbcgis_PropInfo)
File "W:\GIS\WORKING FILES\EM Working Files\Python Projects\Testing Phase\Update_WUD_PARCELS_toPBC.py", line 70, in Parcels
arcpy.CopyFeatures_management(fcInput, fcInput_copy)
File "C:\Program Files\ArcGISPro\Resources\ArcPy\arcpy\management.py", line 4323, in CopyFeatures
raise e
File "C:\Program Files\ArcGISPro\Resources\ArcPy\arcpy\management.py", line 4320, in CopyFeatures
retval = convertArcObjectToPythonObject(gp.CopyFeatures_management(*gp_fixargs((in_features, out_feature_class, config_keyword, spatial_grid_1, spatial_grid_2, spatial_grid_3), True)))
File "C:\Program Files\ArcGISPro\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 512, in <lambda>
return lambda *args: val(*gp_fixargs(args, True))
RuntimeError: Object: Error in executing tool
I took a second look at my code and made a couple changes. First one was replacing the PBC connection to a local copy which is obtained from their hosted FeatureServer and using the Copy Features geoprocessing tool. I then went through all my folder paths and changed them to what you suggested (Path(W:\blah)).
I noticed my script would get stuck on a geoprocessing tool that involved that particular feature class, which was stored on an Oracle geodatabase. Do newer versions of arcpy have issues with Oracle geodatabase connections?
Seems there's an unexpected difference in the way that windows, python, or arcpy is handling file permissions on your system.
Could you try executing the script as administrator? If you're running it inside ArcGIS Pro, you could try launching Pro as admin.
I just tried it as Admin and its the same error message as above.
Sorry about that. I recommend getting further help from your IT resources or Esri technical support.
What's the W drive? Can you specify it as a UNC path? Have previously had issues with drive mappings for scheduled tasks.