I have a python script tool that I have published to a geoprocessing service. Every time I run the service it fails. Here's what I'm getting for errors:

enter image description here

The python code in the tool is below:

import arcpy, arcgisscripting, sys, os
MapIndexFC = r'C:\Users\p04729\AppData\Roaming\ESRI\Desktop10.2\ArcCatalog\Testing.sde\MapSets_D04_ALL_HFs_MapIndex_WGS84'
MapIndexLyr = r'\\sv04esri\Records\GIS\MapSheetImages\MapIndexSelected.lyr'
ImageOutput = r'\\sv04esri\Records\GIS\MapSheetImages\Testing.gdb\Image.lyr'
MI_FC_field = 'filename'
out_buffer_FC = r'C:\Users\p04729\AppData\Roaming\ESRI\Desktop10.2\ArcCatalog\Testing.sde\Buffer'
MapIndexSelect = r'C:\Users\p04729\AppData\Roaming\ESRI\Desktop10.2\ArcCatalog\Testing.sde\Selected_Features'

arcpy.env.overwriteOutput = True

Input = arcpy.GetParameterAsText(0)
Fset = arcpy.FeatureSet()

arcpy.Buffer_analysis(Fset,out_buffer_FC,'5 FEET','FULL','ROUND','ALL')


arcpy.AddMessage('selecting features in Map Index layer...')

matchcount = int(arcpy.GetCount_management(MapIndexLyr).getOutput(0))
if matchcount == 0:
    print('no Map Index features were selected...')
    arcpy.AddError('You must select a feature from the Map Index layer, exiting script')
    arcpy.CopyFeatures_management(MapIndexLyr, MapIndexSelect)

    for row in arcpy.da.SearchCursor(MapIndexSelect,MI_FC_field):
        selected_val = row[0]
        img_name = selected_val.split('.')[0]
        arcpy.AddMessage('iterating over selected Map Index features. ..')
        arcpy.AddMessage('looking for image...')
        for dirpath, dirnames, filenames in os.walk(r'\\sv04esri\Records\GIS\MapSheetImages'):
            for file in filenames:
                if file.endswith('.tif') or file.endswith('.sid'):
                    if img_name in file:
                        Out = arcpy.MakeRasterLayer_management(dirpath+'\\'+file)
         del row, selected_val, img_name

The error is telling me that my Buffer output does not exist or is not supported. I know it does exist, and I'm unsure why it would not be supported?

  • Does the file already exist? Just do a quick check to make sure you're copying the file path correctly in ArcCatolog: imgur.com/cy0ysiI – Roy Jul 30 '14 at 18:15
  • yes it does exist - I can't get to the link you posted unfortunately its blocked for me – kflaw Jul 30 '14 at 18:20
  • Actually I was able to load the link. so it is that my path for the layers in SDE are causing problems, since I am referencing the connections on the C drive? – kflaw Jul 30 '14 at 18:28
  • By going through Catalog it'll give you the path to the file that ArcGIS will definitely take. I would give it a try -- you'll have to re-publish your service, but it's worth a shot. – Roy Jul 30 '14 at 18:31
  • Out of curiosity, try using a simple string in your MakeFeatureLayer rather than the long string path of the MapIndexLyr variable, e.g. "mapindexlyr". The layer is a temporary rep of MapIndexFc so I'm not sure why you're using a path as a string. – Sleep6 Jul 30 '14 at 18:38

Theres a bunch of things I'd suggest changing. I'm not being picky, I'm listing them all because if you get past the problem you're having, you don't want to get stuck in another section of code.

1) Why are you loading your input into a featureset? I can't think of why this is necessary. Just pass whatever value you're getting directly into buffer.

Input = arcpy.GetParameterAsText(0)
Fset = arcpy.FeatureSet()
arcpy.Buffer_analysis(Fset,out_buffer_FC,'5 FEET','FULL','ROUND','ALL')


 Input = arcpy.GetParameterAsText(0)
 arcpy.Buffer_analysis(Input,out_buffer_FC,'5 FEET','FULL','ROUND','ALL')

2) While I guess its not technically incorrect, you're trying to make featurelayer output point to a .lyr file. You dont need the .lyr at the end.

MapIndexLyr = r'\\sv04esri\Records\GIS\MapSheetImages\MapIndexSelected.lyr'

3) Dont use make feature layer. From what I see theres no need for it here. Instead, bring your SDE layer into ArcMap, where it resides in the Table of Contents. Then, from there you make a variable that points to whatever you've named it. If you dragged this layer into your ToC and name it "MapSet", your code goes from this....to this....

#MapIndexFC = r'C:\Users\p04729\AppData\Roaming\ESRI\Desktop10.2\ArcCatalog\Testing.sde\MapSets_D04_ALL_HFs_MapIndex_WGS84'
MapIndexFC = "MapSet"

Its just a name match. The MapIndexFC variable is a layer and can be used like a layer in the code. Thus you can select on it and no need to use make feature layer. (Of course noting you need to run the tool inside ArcMap when that layer exists for it to work and publish)

4) Wild guess - you didnt register your database with the datastore. I could be wrong here, but if you haven't, go back, register it, then re-publish. But this actually might be point #2 which is causing me to think its not registered. So more importantly, remove the .lyr if you insist on using make feature layer.

5) Is there a reason you're writing the output back to SDE? If there isn't a reason, change this to scratch.

#out_buffer_FC = r'C:\Users\p04729\AppData\Roaming\ESRI\Desktop10.2\ArcCatalog\Testing.sde\Buffer'
out_buffer_FC = os.path.join(arcpy.env.scratchGDB, "bufferoutput")
#MapIndexSelect =   r'C:\Users\p04729\AppData\Roaming\ESRI\Desktop10.2\ArcCatalog\Testing.sde\Selected_Features'
MapIndexSelect = os.path.join(arcpy.env.scratchGDB, "SelectedFeatures")
arcpy.Buffer_analysis(Fset,out_buffer_FC,'5 FEET','FULL','ROUND','ALL')
arcpy.CopyFeatures_management(MapIndexLyr, MapIndexSelect)

6) Theres no need for this in a gp service. I'd only use this in a stand alone script.

arcpy.env.overwriteOutput = True

7) "Adding" paths is bad. Better is to use os.path

#Out = arcpy.MakeRasterLayer_management(dirpath+'\\'+file)
Out = arcpy.MakeRasterLayer_management(os.path.join(dirpath, file))
|improve this answer|||||
  • It's my first attempt at creating a python script tool, and for to be used as a geoprocessing service. All data is registered with the server. Point taken about not needing to load the data into a feature set as it's already defined by the parameter - first time using feature sets. I'm writing all the intermediate data now out to memory, and the final result is a layer file from which I've removed the path. I used make feature layer because I believe I need a feature layer as one input for the select by location function. Got the tool working and I will make some clean ups as you suggest. thx – kflaw Jul 30 '14 at 21:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.