I'm running AGP 2.8.0 with the default python environment.
I can execute the same script fine through the toolbox, but if I schedule it for a later time, or run it in the IDE it fails with the error below.
Error Info:
ERROR 160326: The table already exists.
Failed to execute (ExtractMultiValuesToPoints).
When I look this error up, under the Solution it says "There is no documented solution at this time."
I have env.overwriteOutput=True, but I also go through and check for the field names that are generated and delete them before I get to this step in the script.
Solved! Go to Solution.
This error went away when I commented out the Definition Query for the point file.
The help isn't helpful at all.
"While this error can occur, it occurs so rarely that the typical causes have not been identified so no solution is available at this time."
Are you able to share your script? I think that's the only way forward.
import arcpy, os
from arcpy.ia import *
from arcpy.sa import *
from arcpy import env
import pandas as pd
import sys
import traceback
# Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")
#####
##### Script Variables
#####
#####
aprx = arcpy.mp.ArcGISProject(r"C:\Users\Devel\Aug2021Wx\Aug2021Wx.aprx")
adm = r"C:\Geodata\Locations.gdb"
cLocs = os.path.join(adm, "Locations2021")
NDFDOutConus = r"C:\ndfd\degrib\output\conus"
wspd = os.path.join(NDFDOutConus,"wspd.nc")
wgust = os.path.join(NDFDOutConus,"wgust.nc")
snow = os.path.join(NDFDOutConus,"snow.nc")
rain = os.path.join(NDFDOutConus,"qpf.nc")
ice = os.path.join(NDFDOutConus,"iceaccum.nc")
mint = os.path.join(NDFDOutConus,"mint.nc")
maxt = os.path.join(NDFDOutConus,"maxt.nc")
apt = os.path.join(NDFDOutConus,"apt.nc")
locFile = cLocs.split("\\")[-1]
aprxMap = aprx.listMaps("Map")[0]
env.workspace = r"C:\Users\Devel\Aug2021Wx"
arcpy.env.overwriteOutput = True
def exec():
# wind Speed
out_multidimensional_raster_wspd = arcpy.ia.AggregateMultidimensionalRaster(wspd, "StdTime", "MAXIMUM", "WindSpd_10_HTGL", "ALL", '', None, '', None, '', "DATA")
out_multidimensional_raster_wspd.save("wspd_Aggregate.crf")
arcpy.AddMessage("Loaded and saved windspeed")
# wind gusts
out_multidimensional_raster_wgust = arcpy.ia.AggregateMultidimensionalRaster(wgust, "StdTime", "MAXIMUM",
"WindGust_10_HTGL", "ALL", '', None,
'', None, '', "DATA")
out_multidimensional_raster_wgust.save("wgust_Aggregate.crf")
arcpy.AddMessage("Loaded and saved windgusts")
# Snow
out_multidimensional_raster_snow = arcpy.ia.AggregateMultidimensionalRaster(snow, "StdTime", "SUM", "SnowAmt_SFC",
"ALL", '', None, '', None, '', "DATA")
out_multidimensional_raster_snow.save( "snow_Aggregate.crf")
arcpy.AddMessage("Loaded and saved snow")
# Rain
out_multidimensional_raster_qpf = arcpy.ia.AggregateMultidimensionalRaster(rain, "StdTime", "SUM", "QPF_SFC", "ALL",
'', None, '', None, '', "DATA")
out_multidimensional_raster_qpf.save( "qpf_Aggregate.crf")
arcpy.AddMessage("Loaded and saved QPF")
# Ice
out_multidimensional_raster_ice = arcpy.ia.AggregateMultidimensionalRaster(ice, "StdTime", "SUM", "IceAccum_SFC",
"ALL", '', None, '', None, '', "DATA")
out_multidimensional_raster_ice.save( "iceaccum_Aggregate.crf")
arcpy.AddMessage("Loaded and saved ice")
# Min Temp
out_multidimensional_raster_mint = arcpy.ia.AggregateMultidimensionalRaster(mint, "StdTime", "MINIMUM",
"MinT_2_HTGL", "ALL", '', None, '',
None, '', "DATA")
out_multidimensional_raster_mint.save( "mint_Aggregate.crf")
arcpy.AddMessage("Loaded and saved Min T")
# Max Temp
out_multidimensional_raster_maxt = arcpy.ia.AggregateMultidimensionalRaster(maxt, "StdTime", "MAXIMUM",
"MaxT_2_HTGL", "ALL", '', None, '',
None, '', "DATA")
out_multidimensional_raster_maxt.save( "maxt_Aggregate.crf")
arcpy.AddMessage("Loaded and saved Max T")
out_multidimensional_raster_apt = arcpy.ia.AggregateMultidimensionalRaster(apt, "StdTime", "MAXIMUM",
"ApparentT_2_HTGL", "ALL", '', None, '',
None, '', "DATA")
out_multidimensional_raster_apt.save("apt_Aggregate.crf")
arcpy.AddMessage("Loaded and saved apt")
def extractFields():
inRasterList = [["wspd_Aggregate.crf", "WindSpeed"],
["wgust_Aggregate.crf", "WindGust"],
["snow_Aggregate.crf", "Snow"],
["qpf_Aggregate.crf", "QPF"],
["iceaccum_Aggregate.crf", "Ice"],
["mint_Aggregate.crf", "minT"],
["maxT_Aggregate.crf", "maxT"],
["apt_Aggregate.crf", "apt"]]
arcpy.AddMessage("Dropping old fields...")
# checking to see if the weather value fields are already in the table
dropFields = []
field_names = [f.name for f in arcpy.ListFields(cLocs)]
for d in field_names:
if d in ["WindSpeed", "WindGust", "Snow", "QPF", "Ice", "minT", "maxT","apt"]:
dropFields.append(d)
arcpy.AddMessage("Found {}".format(d))
if len(dropFields) > 0:
arcpy.DeleteField_management(cLocs, dropFields)
arcpy.AddMessage("Multi Values to Points...")
for m in aprxMap.listLayers(locFile + "*"):
if m.supports("DEFINITIONQUERY"):
m.definitionQuery = ""
m.definitionQuery = "CTRY = 'US'"
try:
arcpy.env.extent = "MINOF"
arcpy.sa.ExtractMultiValuesToPoints(cLocs, inRasterList, "NONE")
arcpy.AddMessage("Successfully completed!")
except Exception as e:
e = sys.exc_info()[1]
arcpy.AddError(e.args[0])
print(e.args[0])
# Get the traceback object
tb = sys.exc_info()[2]
tbinfo = traceback.format_tb(tb)[0]
finally:
for m in aprxMap.listLayers(locFile + "*"):
if m.supports("DEFINITIONQUERY"):
m.definitionQuery = ""
arcpy.CheckInExtension("Spatial")
if __name__ == "__main__":
exec()
extractFields()
I'm running the same script from the toolbox and scheduling it to run. It just fails on the scheduled attempts. I initially thought that it was something with paths not being fully written out, but I don't think that's the case.
A few things:
Thanks!
Hello. Thank you so much for your post about Extract Multivalues to Point. I am a Product Engineer on the Spatial Analyst team. We'd like to reproduce this issue and then try to solve it. Is it possible for us to get a copy of the data you used in this process?
This error went away when I commented out the Definition Query for the point file.
The help isn't helpful at all.
"While this error can occur, it occurs so rarely that the typical causes have not been identified so no solution is available at this time."
What if you try changing the definition queries using the updateDefinitionQueries() on the layer to be alittle more explicit?
Stepping through the process,
definitionQuery = ""
Only deactivates the previously active definition query, but keeps the query in the def query list and maybe(?) it's causing a conflict that throws the error.
for m in aprxMap.listLayers():
if m.supports("DEFINITIONQUERY"):
print(f'existing dq: {m.listDefinitionQueries()}')
# existing dq: []
m.definitionQuery = "OBJECTID = 1"
print(f'dq set: {m.listDefinitionQueries()}')
# -> dq set: [{'name': 'Query 1', 'sql': 'OBJECTID = 1', 'isActive': True}]
m.definitionQuery = ""
print(f'dq set to "": {m.listDefinitionQueries()}')
# -> dq set to "": [{'name': 'Query 1', 'sql': 'OBJECTID = 1', 'isActive': False}]
updte = [] # <- set to empty list to clear the previous def query or # <- set to empty list or [{'name': 'Query 1', 'sql': 'OBJECTID = 2', 'isActive': True}] as new def query
df_done = m.updateDefinitionQueries(updte)
print(f'dq set by update: {m.listDefinitionQueries()}')
# -> dq set by update: []