<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: ExtractMultiValuesToPoints Fails in standalone script in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/extractmultivaluestopoints-fails-in-standalone/m-p/1084819#M61909</link>
    <description>&lt;LI-CODE lang="python"&gt;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) &amp;gt; 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()&lt;/LI-CODE&gt;</description>
    <pubDate>Mon, 02 Aug 2021 08:36:46 GMT</pubDate>
    <dc:creator>GabrielMarcus_C</dc:creator>
    <dc:date>2021-08-02T08:36:46Z</dc:date>
    <item>
      <title>ExtractMultiValuesToPoints Fails in standalone script</title>
      <link>https://community.esri.com/t5/python-questions/extractmultivaluestopoints-fails-in-standalone/m-p/1084296#M61896</link>
      <description>&lt;P&gt;I'm running AGP 2.8.0 with the default python environment.&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;Error Info:
ERROR 160326: The table already exists.
Failed to execute (ExtractMultiValuesToPoints).&lt;/LI-CODE&gt;&lt;P&gt;When I look this error up, under the Solution it says "There is no documented solution at this time."&lt;/P&gt;&lt;P&gt;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.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jul 2021 00:01:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/extractmultivaluestopoints-fails-in-standalone/m-p/1084296#M61896</guid>
      <dc:creator>GabrielMarcus_C</dc:creator>
      <dc:date>2021-07-30T00:01:25Z</dc:date>
    </item>
    <item>
      <title>Re: ExtractMultiValuesToPoints Fails in standalone script</title>
      <link>https://community.esri.com/t5/python-questions/extractmultivaluestopoints-fails-in-standalone/m-p/1084500#M61904</link>
      <description>&lt;P&gt;Are you able to share your script? I think that's the only way forward.&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jul 2021 17:17:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/extractmultivaluestopoints-fails-in-standalone/m-p/1084500#M61904</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2021-07-30T17:17:12Z</dc:date>
    </item>
    <item>
      <title>Re: ExtractMultiValuesToPoints Fails in standalone script</title>
      <link>https://community.esri.com/t5/python-questions/extractmultivaluestopoints-fails-in-standalone/m-p/1084819#M61909</link>
      <description>&lt;LI-CODE lang="python"&gt;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) &amp;gt; 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()&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 02 Aug 2021 08:36:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/extractmultivaluestopoints-fails-in-standalone/m-p/1084819#M61909</guid>
      <dc:creator>GabrielMarcus_C</dc:creator>
      <dc:date>2021-08-02T08:36:46Z</dc:date>
    </item>
    <item>
      <title>Re: ExtractMultiValuesToPoints Fails in standalone script</title>
      <link>https://community.esri.com/t5/python-questions/extractmultivaluestopoints-fails-in-standalone/m-p/1084977#M61920</link>
      <description>&lt;P&gt;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.&amp;nbsp;&lt;/P&gt;&lt;P&gt;A few things:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;I don't use concurrent licensing, so checking in/out the spatial license should have no effect&lt;/LI&gt;&lt;LI&gt;The NetCDF files are from the tkdegrib program produced by the National Weather Service. I download the data before running the script.&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;The point file is just points, not multipoint. Definition query is set to just the US and then to nothing.&amp;nbsp;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 02 Aug 2021 16:13:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/extractmultivaluestopoints-fails-in-standalone/m-p/1084977#M61920</guid>
      <dc:creator>GabrielMarcus_C</dc:creator>
      <dc:date>2021-08-02T16:13:11Z</dc:date>
    </item>
    <item>
      <title>Re: ExtractMultiValuesToPoints Fails in standalone script</title>
      <link>https://community.esri.com/t5/python-questions/extractmultivaluestopoints-fails-in-standalone/m-p/1085128#M61926</link>
      <description>&lt;P&gt;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?&lt;/P&gt;</description>
      <pubDate>Mon, 02 Aug 2021 23:22:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/extractmultivaluestopoints-fails-in-standalone/m-p/1085128#M61926</guid>
      <dc:creator>YuWang1</dc:creator>
      <dc:date>2021-08-02T23:22:55Z</dc:date>
    </item>
    <item>
      <title>Re: ExtractMultiValuesToPoints Fails in standalone script</title>
      <link>https://community.esri.com/t5/python-questions/extractmultivaluestopoints-fails-in-standalone/m-p/1205622#M65398</link>
      <description>&lt;P&gt;This error went away when I commented out the Definition Query for the point file.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The help isn't helpful at all.&amp;nbsp;&lt;BR /&gt;"&lt;SPAN&gt;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."&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Aug 2022 22:14:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/extractmultivaluestopoints-fails-in-standalone/m-p/1205622#M65398</guid>
      <dc:creator>GabrielMarcus_C</dc:creator>
      <dc:date>2022-08-23T22:14:33Z</dc:date>
    </item>
    <item>
      <title>Re: ExtractMultiValuesToPoints Fails in standalone script</title>
      <link>https://community.esri.com/t5/python-questions/extractmultivaluestopoints-fails-in-standalone/m-p/1205821#M65401</link>
      <description>&lt;P&gt;What if you try changing the definition queries using the updateDefinitionQueries() on the layer to be alittle more explicit?&lt;/P&gt;&lt;P&gt;Stepping through the process,&lt;/P&gt;&lt;PRE&gt;definitionQuery = &lt;SPAN&gt;""&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;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()}')
        # -&amp;gt; dq set: [{'name': 'Query 1', 'sql': 'OBJECTID = 1', 'isActive': True}]

        m.definitionQuery = ""
        print(f'dq set to "": {m.listDefinitionQueries()}')
        # -&amp;gt; dq set to "": [{'name': 'Query 1', 'sql': 'OBJECTID = 1', 'isActive': False}]

        updte = [] # &amp;lt;- set to empty list to clear the previous def query or # &amp;lt;- 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()}')
        # -&amp;gt; dq set by update: []&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Aug 2022 14:19:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/extractmultivaluestopoints-fails-in-standalone/m-p/1205821#M65401</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-08-24T14:19:50Z</dc:date>
    </item>
  </channel>
</rss>

