Python to GP service mystery

2449
2
10-08-2015 08:31 AM
BillChappell
Occasional Contributor II

Hi, I have this python script that basically selects a point by it's ID, then selects all points within a distance and returns only a subset of those that match the type field.  i.e. find all hospitals within 3 miles of this location..

My python script works, does what it's supposed to. So I create a GP service from it. Add the service back into the map and run it. Now I notice no matter what distance I use, the data doesn't change. If I delete the created Featureclass to see if it's really working. It does not create a new featureclass but it says it completed successfully.

Now the weird part, if I hit the GP service at the rest endpoint with the parameters it says it works but returns no records. I've been careful to avoid schema locks when using the Rest endpoint ArcMap and ArcCatalog are closed.

It's like the GP service doesn't have permission to write to the sde database, However my sde connection works fine on my PC.

Any ideas?

0 Kudos
2 Replies
DanielStauning
Esri Contributor

Bill,

Here are some questions I'd start with:

Are you overwriting the outputs of existing geoproceessing operations?

Where are you you writing intermediate data to? Is the output fc being written to your default gdb?

Have you parameterized the output layer?

What do you have set for your current and scratch workspace environments?

Thanks,

-Dan

0 Kudos
BillChappell
Occasional Contributor II

I am writing to the SDE database, overwriting the existing FC, after the points have been collected, I go from a feature layer to a featureclass.

Maybe my code will help, it's fairly simple.

import arcpy, os, string
from arcpy import env


theworkspace
= r"Connection to racdev1.sde"
arcpy
.env.workspace = theworkspace

arcpy
.env.overwriteOutput = True

#facilityID = '1249'
facilityID
= arcpy.GetParameterAsText(0)
#facilityIDType= 'PFI'
facilityIDType
= arcpy.GetParameterAsText(1)

thedistance
= arcpy.GetParameterAsText(2)
#thedistance = '3 miles'
#withindistance = "3 Miles"
withindistance
=  thedistance + ' Miles'

sql_query
= "\"%s\" = '%s'" % ("ID", facilityID)  
sql_query2
= "\"%s\" = '%s'" % ("IDTYPE", facilityIDType)

# Local variables:
Facilities = "DOHGIS.NYSDOH_CI_DATA"
featLayer
= "thePts"

arcpy
.MakeFeatureLayer_management(Facilities, featLayer)

# Process: Select Layer By Attribute
arcpy
.SelectLayerByAttribute_management(featLayer, "NEW_SELECTION", sql_query)

# Process: Select Layer By Location 311
arcpy
.SelectLayerByLocation_management(featLayer, "WITHIN_A_DISTANCE",featLayer, withindistance, "NEW_SELECTION")

#print " now for the subset"
arcpy
.SelectLayerByAttribute_management("thePts", "SUBSET_SELECTION", sql_query2  )

# creaate the new featureclss..
arcpy
.CopyFeatures_management("thePts",'DOHGIS.NYSDOH_FacilitiesQuery')
#print "Done"

0 Kudos