Search code examples
pythonarcgisspssarcpy

Call/Define Open Dataset to Run Python Calc in SPSS


I have this ArcGIS python code (using arcpy module) that I need to import and run in SPSS.

The python code works in ArcGIS, and I have been able to successfully set the python library to the ArcGIS x64 python directory.

My question is this: How can I call/define the open (or can be closed) data set that I want to run the calculations on? (My current code defines this in line 2 table "CURRENT_DATABASE_MEMORY")

here is my code that works in ArcGIS/Python. I have not been able to successfully find a solution to this problem.

import arcpy
table = "CURRENT_DATABASE_MEMORY"

valueList = [r[0] for r in arcpy.da.SearchCursor(table, ["FULL_ADDRESS"])]
valueDict = collections.Counter(valueList)
uniqueList = valueDict.keys()
uniqueList.sort() 
updateRows = arcpy.da.UpdateCursor(table, ["FULL_ADDRESS","ALL_LIVE"])
for updateRow in updateRows:
   updateRow[1] = valueDict[updateRow[0]]  
   updateRows.updateRow(updateRow)
del updateRow, updateRows


valueList = [r[0] for r in arcpy.da.SearchCursor(table, ["FULL_ADDRESS_NAME"])]
valueDict = collections.Counter(valueList)
uniqueList = valueDict.keys()
uniqueList.sort() 
updateRows = arcpy.da.UpdateCursor(table, ["FULL_ADDRESS_NAME","ALL_LIVE"])
for updateRow in updateRows:
   updateRow[1] = valueDict[updateRow[0]]  
   updateRows.updateRow(updateRow)
del updateRow, updateRows

uniqueValues = {}
values = []
newID = 0

with arcpy.da.UpdateCursor(table, ["FULL_ADDRESS_NAME","FEAT_SEQ"]) as updateRows:
    for row in updateRows:
        nameValue = row[0]
        if nameValue in uniqueValues:
            row[1] = uniqueValues[nameValue]
        else:
            newID += 1
            uniqueValues[nameValue] = newID
            row[1] = newID
        updateRows.updateRow(row)


del row, updateRows

Solution

  • Adding to what Andy wrote, you might want to consider issuing a command to SPSS using the Submit api to read the dataset via ODBC (assuming that you have a driver for that source), or you could read the datas source directly in the Python code, manipulate it, and then write it to SPSS using the various apis provided for that in the Python plugin. The best choice will depend on the role that you want SPSS to play in processing this data.