kjohn

geoprocessing service using in_memory produces no results

Discussion created by kjohn on Oct 14, 2013
Latest reply on Oct 24, 2013 by kjohn
Hi, I have a really basic script that I want to run as a geoprocessing service but from server it yields no results.   It works and gives the expected result as a script tool in desktop. It works as expected when wrapped in a model and run from desktop.  But when I publish it to server (10.0 sp3 .net) it doesn't fail, it just doesn't give any results.  I think I've followed the best practices for the folder structure and data paths etc.  Im using in_memory workspace for some of the outputs (hoping to speed up the process) and I think the server isn't actually able to write to in_memory (is that even possible?). 
Any suggestions are welcome, I've been trying to get this to work for a couple days now.
Thanks.  Here's the code:


import arcpy
from arcpy import env
import os
import sys

env.workspace = "in_memory"


APN = arcpy.GetParameterAsText(0)




scriptPath = sys.path[0]
thisFolder = os.path.dirname(scriptPath)
ToolDataPath = os.path.join(thisFolder, "ToolData")
ScratchPath = os.path.join(thisFolder, "Scratch")
ScratchDataPath = os.path.join(ScratchPath, "scratch.gdb")
parcels = os.path.join(ToolDataPath,"County_Parcels.lyr")
ServiceArea = os.path.join(ToolDataPath, "Service_Area.lyr" )

whereclause = '"APN" =  ' + str(APN)

try:
    arcpy.MakeFeatureLayer_management(parcels, "PARCELtobeQueried", whereclause, "", "OBJECTID OBJECTID HIDDEN NONE;SHAPE SHAPE HIDDEN NONE;APN APN VISIBLE NONE;PIN PIN HIDDEN NONE;STREETNUM STREETNUM HIDDEN NONE;STREETDIR STREETDIR HIDDEN NONE;STREET STREET HIDDEN NONE;CITY CITY HIDDEN NONE;FIRSTNAME FIRSTNAME HIDDEN NONE;LASTNAME LASTNAME HIDDEN NONE;MAILING1 MAILING1 HIDDEN NONE;MAILING2 MAILING2 HIDDEN NONE;MAILCITY MAILCITY HIDDEN NONE;MAILSTATE MAILSTATE HIDDEN NONE;MAILZIP MAILZIP HIDDEN NONE;LAND_USE LAND_USE HIDDEN NONE;ZONING ZONING HIDDEN NONE;WATER WATER HIDDEN NONE;SEWER SEWER HIDDEN NONE;ACREAGE ACREAGE HIDDEN NONE;TAXDIST TAXDIST HIDDEN NONE;BEDROOMS BEDROOMS HIDDEN NONE;BATHS BATHS HIDDEN NONE;YEARBLT YEARBLT HIDDEN NONE;LANDASS LANDASS HIDDEN NONE;BUILDASS BUILDASS HIDDEN NONE;TOTALASS TOTALASS HIDDEN NONE;LANDAPR LANDAPR HIDDEN NONE;BUILDAPR BUILDAPR HIDDEN NONE;TOTALAPR TOTALAPR HIDDEN NONE;PROPCODE PROPCODE HIDDEN NONE;STORIES STORIES HIDDEN NONE;TOWNHOUSE TOWNHOUSE HIDDEN NONE;UNITS UNITS HIDDEN NONE;BUILDINGTYPE BUILDINGTYPE HIDDEN NONE;NAME NAME HIDDEN NONE;NUMBER_ NUMBER_ HIDDEN NONE;TOWNSHIP TOWNSHIP HIDDEN NONE;RANGE RANGE HIDDEN NONE;SECT SECT HIDDEN NONE;NBHD NBHD HIDDEN NONE;FACTORDIST FACTORDIST HIDDEN NONE;SALEDATE SALEDATE HIDDEN NONE;SALEPRICE SALEPRICE HIDDEN NONE;SPECPROPCODE SPECPROPCODE HIDDEN NONE;QC QC HIDDEN NONE;ORIG_FID ORIG_FID HIDDEN NONE")
    #below is writing to in memory
    ParcelCentroid = env.workspace + "\\" + "ParcelCentroidFeature"
    arcpy.FeatureToPoint_management("PARCELtobeQueried",ParcelCentroid )
    arcpy.Delete_management("PARCELtobeQueried")
    #below is writing to in memory
    SpatialJoinOUT = env.workspace + "\\" + "ParcelCentroidSJBound"
    arcpy.SpatialJoin_analysis(ParcelCentroid,ServiceArea, SpatialJoinOUT, 'JOIN_ONE_TO_ONE','KEEP_ALL', "APN \"APN\" true true false 4 Long 0 0 ,First,#,{0},APN,-1,-1;DESCRIPTIO \"DESCRIPTIO\" true true false 254 Text 0 0 ,First,#,{1},DESCRIPTIO,-1,-1;NAME \"NAME\" true true false 254 Text 0 0 ,First,#,{2},NAME,-1,-1".format(ParcelCentroid,  ServiceArea,  ServiceArea),   "INTERSECT", "", "")
    arcpy.Delete_management(ParcelCentroid)
    rows = arcpy.SearchCursor(SpatialJoinOUT)
    row = rows.next()
    TestText = ''
    while row:
        print row.DESCRIPTIO
        TestText = str(row.DESCRIPTIO)
        break
    OUTPUT = arcpy.SetParameterAsText(1, TestText)
    print TestText
    del row, rows
    arcpy.Delete_management(SpatialJoinOUT)

except:
    print "cannot find apn"
    msg = arcpy.GetMessages()
    print msg

Outcomes