Overwrite Output Error 999999

523
6
Jump to solution
09-08-2018 09:28 AM
JacobHorwitz1
New Contributor II

(Edit: I shortened the script as a big portion of it wasn't part of the main problem.)

I'm working on a script to re-project shapefiles from a selected shapefile with a different projection. While the execution of the tool works, it fails when overwriting the same file regardless of adding in arcpy.env.overwriteOutput = True.

Here is the script used:

if srcDesc.SpatialReference.Name == targetDesc.SpatialReference.Name:
continue

#Shapefiles in the targeted folder that don't match will reprojected to the selected shapefile.

else:

#Replaces the TargetFolder's ".shp" at the end  of the end of the name with "_projected."

ReprojectedData = InFolder.replace(".shp", "_projected")

#Tool re-projects the datasets that doesn't match the spatial reference of the targeted shapefile.

arcpy.Project_management(InFolder, ReprojectedData, InFile)

#Displays a message of success of the projected datasets.print "Projected " + str(InFolder)
arcpy.AddMessage("Projected " + str(InFolder))‍‍‍‍‍‍‍‍‍‍‍‍

Is there a different way of using an overwrite output for a script such as this?

0 Kudos
1 Solution

Accepted Solutions
JacobHorwitz1
New Contributor II

I was able to finally find the solution! I had to add an extra ".shp" to "_projected" as "_projected.shp." to fix the Error: 999999.

View solution in original post

0 Kudos
6 Replies
DanPatterson_Retired
MVP Esteemed Contributor

Jacob could you format your code so that it has line numbers

/blogs/dan_patterson/2016/08/14/script-formatting 

0 Kudos
JacobHorwitz1
New Contributor II

Reupdated the post for Syntax Highlighter.

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

Is your destination workspace a file geodatabse? I ask since you are replacing *.shp with _projected, implying such.

I also suggest that you dump the try-except block and dedent everything since the exception is not informative.  It is better to get a real error than a message that something failed.  Exception tracking will return the same error message for the most part, as dumping the try except block.

Sometimes it is just better to use a Delete_management, to delete existing data rather than relying on the overwriteOutput

JacobHorwitz1
New Contributor II

I was able to finally find the solution! I had to add an extra ".shp" to "_projected" as "_projected.shp." to fix the Error: 999999.

0 Kudos
forestknutsen1
MVP Regular Contributor

I have noticed the env overwrite is not always honored. I typically delete (as Dan suggested) or add a number to the end of my names and increment it to generate unqunie names, 

0 Kudos
BrianWilson7
Occasional Contributor III

I've done this many many times when "overwriting" because setting overwrite to True often fails, causing my scripts to exit, 

if arcpy.Exists(fc): arcpy.management.Delete(fc)

 

The problem I've been seeing is when I publish a feature class to Portal with overwrite True and it creates a new service with the same name. You can't do "delete old and create new" because it will give the new layer a different unique ID and that means all your maps are broken.

(I came here because I saw Error 999999 and Overwrite in the "Related" column and got excited. :)

(I'm thinking of running off Error 999999 t-shirts, I think it would be a great inside joke for Esri users.)

0 Kudos