ArcGIS Pro at 2.4/arcpy- FeatureClassToFeatureClass_conversion does not honor overwriteOutput env setting

633
11
08-07-2019 07:35 AM
DavidColey
Frequent Contributor

Hello - I upgraded to Pro to 2.4 yesterday and lo and behold my python scripts for overwriting feature classes using the FeatureClassToFeatureClass_conversion tool no longer honors the arcpy.env.overwriteOutput = True environment setting. 

A whole bunch of my data management scripts depend on this! 

The script now keeps telling me that my feature class already exists.  Of course it does, I'm doing an overwrite.  Or at least I did.

This was working just fine at 2.1, 2.2, 2.3.x  

I can't use Copy for most of my layers because I don't want bring over (in some cases) dozens of related tables....

Example:

# Import system modules
import sys, os, arcpy, time, smtplib
from datetime import date, timedelta
from arcpy import env

# Local variables...
message = ""
current_time = time.asctime()
todaysDate = date.today()
priorYear = str(todaysDate - timedelta(days=547)) #547
starting_time = time.time()
arcpy.SetLogHistory(False)
arcpy.env.configKeyword= "DEFAULTS"
arcpy.env.overwriteOutput = True
arcpy.env.maintainAttachments = False

try:
env.workspace = r"\\scggisis01pw\\agsfed\\data-store\\VantagePoint\\Data" #\\scggisis01pw\\agsfed
coordinate_system = r"C:\\StageDbsAE\\CoordinateSystems.gdb\\WebMercator"
env.outputCoordinateSystem = coordinate_system
env.geographicTransformations = "NAD_1983_HARN_To_WGS_1984_2"
for fc in arcpy.ListFeatureClasses():
outLocation = r"\\scggisis01pw\\agsfed\\data-store\\VantagePoint\\Data\\VpAnno.gdb\\VantagePointLayers" # VantagePoint.gdb\
outFC = fc[:-4] #neg slice for shapes, 4 from right
#if outFC != "UtilityBilling":
print (outLocation + "\\" + outFC)
#disableFC = outLocation + "\\" + outFC
arcpy.FeatureClassToFeatureClass_conversion(fc, outLocation, outFC)
message = message + "\n" + "Added Features: " + outFC
#arcpy.RemoveSpatialIndex_management(disableFC)
#arcpy.AddSpatialIndex_management(disableFC)
#message = message + "\n" + "Handeld Indexing: " + disableFC
#else:
# pass

except Exception:
# If an error occurred, print line number and error message
import traceback, sys
tb = sys.exc_info()[2]
e = sys.exc_info()[1]
#print(e.args[0])
#print "Line %i" % tb.tb_lineno
message = message + "\n" + "Line %i" % tb.tb_lineno
message = message + "\n" + str(e)‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
11 Replies
DanPatterson_Retired
MVP Esteemed Contributor
    if arcpy.Exists(out_fc) and arcpy.env.overwriteOutput:
arcpy.Delete_management(out_fc)

Sometimes a file lock might do it, so you can check to see if the output featureclass exists 'AND' overwriteOutput is True and if they both are, try a Delete.... If it won't delete, then you have other issues.

0 Kudos
DavidColey
Frequent Contributor

I appreciate the response.  Executing the Delete is not an issue and I can easily do that.  However, I shouldn't have to the python 3.16.8 IDLE should honor the environment setting and it's not.  That is the issue.

0 Kudos
DavidColey
Frequent Contributor

My mistake -  the idle is honoring the setting:

import arcpy
from arcpy import env
arcpy.env.overwriteOutput = True

environments = arcpy.ListEnvironments()
# Sort the environment list, disregarding capitalization
#
environments.sort(key=str.lower)
for environment in environments:
# As the environment is passed as a variable, use Python's getattr
# to evaluate the environment's value
#
env_value = getattr(arcpy.env, environment)
# Format and print each environment and its current setting
#
print("{0:<30}: {1}".format(environment, env_value))
0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

So will delete work? (inconvenient or not) even if the overwrite is working? Or will it not delete?

If it will delete and not overwrite, then that is something that should be reported to tech support.

Python wouldn't even be the issue.

0 Kudos
DavidColey
Frequent Contributor

Really?  Respectfully I disagree because we just ran the exact same thing in python IDLE 2.7.16 with the overwrite environment setting set to true and it works there just fine without having to run a delete first. More - the ArcPro 2.4 GP tool runs and honors the overall GP environment setting, as one would expect.

But to answer your question, yes delete does work in python IDLE 3.6.8, then of course the tool works. This occurs whether running against the default python environment or my updated (arcgis package 1.6.2) cloned environment.

0 Kudos
DavidColey
Frequent Contributor

oh also I can say that the maintainAttachments env var is being honored so there is something somewhere that was missed

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor
# ArcGIS Pro uses Python 3.6.8

sys.executable
'C:\\arc_pro\\bin\\Python\\envs\\arcgispro-py3\\pythonw.exe'

sys.base_exec_prefix
'C:\\arc_pro\\bin\\Python\\envs\\arcgispro-py3'

‍‍‍‍‍‍‍‍arcpy.__path__
['C:\\arc_pro\\Resources\\ArcPy\\arcpy']

Change the 'arc_pro' portion to match your installation path.  You can compare the version of python with the version of 'arcpy'

The paths should jive, unless there is a cross-over between arcpy and python in your setup

DavidColey
Frequent Contributor

Ok thanks for the info

0 Kudos
MichaelStranovsky
Occasional Contributor

I got it fixed....honoring overwrite now

Get Outlook for Android<https://aka.ms/ghei36>

0 Kudos