<?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: Reclassify raster using variables from a SQL Server table (connecting with pyodbc in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/reclassify-raster-using-variables-from-a-sql/m-p/183638#M14107</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Not sure why it's not working. Can you do a test and harcode your remap_cur variable such as:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;remap_cur = arcpy.sa.RemapValue([7, 777][8,888],[9,999],...) ? You &lt;/SPAN&gt;&lt;SPAN style="text-decoration:underline;"&gt;are&lt;/SPAN&gt;&lt;SPAN&gt; able to use variable in the remap tables, so I don't think that's the issue... More likely you are not retreiving the variables you want to use in the correct way.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Are the row's field values you are retreving indeed integers - or as the error suggests, a tuple object? For example something weird and unexpected like (None, 3).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What does:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;print row.BIOME_7&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;evaluate to?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also, where in your code do you define the "row" object (as in row.BIOME_7)... shouldn't it be something like "cursor.BIOME_7"?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 23 Aug 2012 17:36:32 GMT</pubDate>
    <dc:creator>ChrisSnyder</dc:creator>
    <dc:date>2012-08-23T17:36:32Z</dc:date>
    <item>
      <title>Reclassify raster using variables from a SQL Server table (connecting with pyodbc)</title>
      <link>https://community.esri.com/t5/python-questions/reclassify-raster-using-variables-from-a-sql/m-p/183635#M14104</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello all,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So I am trying to reclass a raster file (representing vegetation and land cover types) using values stored in a SQL Server Express table.&amp;nbsp; I have a set of ~400 species records in the table, with each row representing a different species, and a column for each vegetation type.&amp;nbsp; Each vegetation type is coded as either "1" if it is suitable habitat for that species, or "0" if it's unsuitable. The vegetation raster will then be reclassified to two values,&amp;nbsp; "1" or "0", based on the values associated with the species record (this will be slightly different for each species).&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In PythonWin, I'm using pyodbc to connect to the SQL Server Express database table, then executing a select query statement to collect the values for a species record (row) into the pyodbc cursor.&amp;nbsp; Then I want to assign each column value to the output raster value in the remap statement (see code attached).&amp;nbsp; Unfortunately, I keep getting the following error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;TypeError: list indices must be integers, not tuple&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;RasterCalculator seems to just want integers in the remap statement, not variables, but I don't know how to get around that.&amp;nbsp; Any ideas?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jesse Langdon&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Research Assistant&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;University of Washington&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
# Load Python libraries&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
import pyodbc
import arcpy
from arcpy import env
from arcpy.sa import *
import os

arcpy.env.overwriteOutput = 1

# Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")

# set variables
modelList = arcpy.ListFiles() # build list of species model names for loop
biome_Cur = ("xxxxxxx/xxxx/xxxxxx/1_Input.gdb/biome_current") # the original raster which will be reclassed

# connect to SQL Server Express database
cnxn = pyodbc.connect('DRIVER={SQL Server Native Client 10.0};SERVER=DESKTOP\SQLEXPRESS;DATABASE=Species;UID=sa;PWD=XXXXXX')
cursor = cnxn.cursor()

# main processing loop
for model in modelList:

&amp;nbsp;&amp;nbsp;&amp;nbsp; # reclassifies biome raster based on suitability code from SQL Server Species database
&amp;nbsp;&amp;nbsp;&amp;nbsp; # sql SELECT query
&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor.execute("""
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SELECT [BIOME_1],[BIOME_6],[BIOME_7],[BIOME_8],[BIOME_9],[BIOME_10],[BIOME_14],[BIOME_19],[BIOME_20],
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [BIOME_21],[BIOME_22],[BIOME_23],[BIOME_24],[BIOME_25],[BIOME_27],[BIOME_29],[BIOME_30],[BIOME_31],
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [BIOME_32],[BIOME_35],[BIOME_36],[BIOME_37],[BIOME_38],[BIOME_39],[BIOME_40],[BIOME_41],[BIOME_42],
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [BIOME_43],[BIOME_44],[BIOME_45],[BIOME_46],[BIOME_47],[BIOME_48],[BIOME_50],[BIOME_100],[BIOME_200]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FROM Species.dbo.BiomesPerSpp_Rehfeldt
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WHERE ID = ?""", (model))

&amp;nbsp;&amp;nbsp;&amp;nbsp; # assign remap variable for reclassification
&amp;nbsp;&amp;nbsp;&amp;nbsp; remap_cur = RemapValue([7, row.BIOME_7][8, row.BIOME_8],[9, row.BIOME_9],[14, row.BIOME_14],[20, row.BIOME_20],
&amp;nbsp;&amp;nbsp;&amp;nbsp; [21, row.BIOME_21], [22, row.BIOME_22], [23, row.BIOME_23], [25, row.BIOME_25], [30, row.BIOME_30],&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; [31,row.BIOME_31],[32, row.BIOME_32], [36, row.BIOME_36], [38, row.BIOME_38], [41, row.BIOME_41], 
&amp;nbsp;&amp;nbsp;&amp;nbsp; [42, row.BIOME_42], [43, row.BIOME_43],[44, row.BIOME_44], [45, row.BIOME_45], [46, row.BIOME_46], 
&amp;nbsp;&amp;nbsp;&amp;nbsp; [47, row.BIOME_47], [50, row.BIOME_50], [100, row.BIOME_100],[200, row.BIOME_200])

&amp;nbsp;&amp;nbsp;&amp;nbsp; biomeReClass_cur = arcpy.sa.Reclassify(biome_Cur, "Value", remap_cur, "NODATA")&amp;nbsp; &lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Aug 2012 20:24:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/reclassify-raster-using-variables-from-a-sql/m-p/183635#M14104</guid>
      <dc:creator>JesseLangdon</dc:creator>
      <dc:date>2012-08-22T20:24:35Z</dc:date>
    </item>
    <item>
      <title>Re: Reclassify raster using variables from a SQL Server table (connecting with pyodbc</title>
      <link>https://community.esri.com/t5/python-questions/reclassify-raster-using-variables-from-a-sql/m-p/183636#M14105</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I think the sytax for using the remap table is:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.sa.RemapValue()&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;as in...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;temp3Grd = arcpy.sa.Reclassify(temp2Grd, "Value", arcpy.sa.RemapValue([[1,1],[0,"NODATA"]]), "DATA")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I think you are getting an error because you are not specifying the arcpy.sa... part of the Remap command.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Aug 2012 21:05:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/reclassify-raster-using-variables-from-a-sql/m-p/183636#M14105</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2012-08-22T21:05:15Z</dc:date>
    </item>
    <item>
      <title>Re: Reclassify raster using variables from a SQL Server table (connecting with pyodbc</title>
      <link>https://community.esri.com/t5/python-questions/reclassify-raster-using-variables-from-a-sql/m-p/183637#M14106</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Chris,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for the feedback.&amp;nbsp; I tried adding the "arcpy.sa" prefix to the RemapValue command, but I'm still getting the same error message.&amp;nbsp; I just wonder if the RemapValue command will only take actual integers, and not variables.&amp;nbsp; I'm wondering if I have to do something ugly like create a temporary ascii table based on the data returned from the SQL query, and then Reclass by ASCII file.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jesse&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Aug 2012 02:50:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/reclassify-raster-using-variables-from-a-sql/m-p/183637#M14106</guid>
      <dc:creator>JesseLangdon</dc:creator>
      <dc:date>2012-08-23T02:50:23Z</dc:date>
    </item>
    <item>
      <title>Re: Reclassify raster using variables from a SQL Server table (connecting with pyodbc</title>
      <link>https://community.esri.com/t5/python-questions/reclassify-raster-using-variables-from-a-sql/m-p/183638#M14107</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Not sure why it's not working. Can you do a test and harcode your remap_cur variable such as:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;remap_cur = arcpy.sa.RemapValue([7, 777][8,888],[9,999],...) ? You &lt;/SPAN&gt;&lt;SPAN style="text-decoration:underline;"&gt;are&lt;/SPAN&gt;&lt;SPAN&gt; able to use variable in the remap tables, so I don't think that's the issue... More likely you are not retreiving the variables you want to use in the correct way.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Are the row's field values you are retreving indeed integers - or as the error suggests, a tuple object? For example something weird and unexpected like (None, 3).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What does:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;print row.BIOME_7&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;evaluate to?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also, where in your code do you define the "row" object (as in row.BIOME_7)... shouldn't it be something like "cursor.BIOME_7"?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Aug 2012 17:36:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/reclassify-raster-using-variables-from-a-sql/m-p/183638#M14107</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2012-08-23T17:36:32Z</dc:date>
    </item>
    <item>
      <title>Re: Reclassify raster using variables from a SQL Server table (connecting with pyodbc</title>
      <link>https://community.esri.com/t5/python-questions/reclassify-raster-using-variables-from-a-sql/m-p/183639#M14108</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Just realized I never closed this thread out.&amp;nbsp; I solved the problem by changing the SQL query from&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor.execute("""
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SELECT [BIOME_1],[BIOME_6],[BIOME_7],[BIOME_8],[BIOME_9],[BIOME_10],[BIOME_14],[BIOME_19],[BIOME_20],
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [BIOME_21],[BIOME_22],[BIOME_23],[BIOME_24],[BIOME_25],[BIOME_27],[BIOME_29],[BIOME_30],[BIOME_31],
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [BIOME_32],[BIOME_35],[BIOME_36],[BIOME_37],[BIOME_38],[BIOME_39],[BIOME_40],[BIOME_41],[BIOME_42],
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [BIOME_43],[BIOME_44],[BIOME_45],[BIOME_46],[BIOME_47],[BIOME_48],[BIOME_50],[BIOME_100],[BIOME_200]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FROM Species.dbo.BiomesPerSpp_Rehfeldt
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WHERE ID = ?""", (model))
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;to:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor.execute("""
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SELECT *
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FROM Species.dbo.BiomesPerSpp_Rehfeldt
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WHERE ID = ?""", (model))
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For whatever reason, changing the SELECT to a wildcard worked. Thanks for the responses Chris!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jesse&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:20:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/reclassify-raster-using-variables-from-a-sql/m-p/183639#M14108</guid>
      <dc:creator>JesseLangdon</dc:creator>
      <dc:date>2021-12-11T09:20:38Z</dc:date>
    </item>
  </channel>
</rss>

