AnsweredAssumed Answered

Exporting SHP file on ArcGIS Server with Geoprocessing Widget

Question asked by aarcichowski@invenergy.com_invenergyllc on Oct 6, 2020



I'm having a bit of an issue with zipping up a shapefile on ArcGIS Server from calling a GP tool with WAB. 

My code is below.  It works for kmz and excels but having some trouble with the zipping and shpfile part. 

This is what gets outputted by the tool 

That link is invalid, however when I change it to (remove the extra scratch at the end) 
It works, but then when I look in there, there is a scratch.gdb with nothing in it. When I run this in ArcMap it does produce the with the shpfile in it. C:\Users\adam\Documents\ArcGIS\ 


featureLayer = arcpy.GetParameter(0)
outputFormat = arcpy.GetParameterAsText(1)

if outputFormat == ".kmz (Google Earth)":
          kmzFile = os.path.join(arcpy.env.scratchFolder, "export.kmz")
          arcpy.MakeFeatureLayer_management(featureLayer, "in_memory\layer")
          arcpy.LayerToKML_conversion("in_memory\layer", kmzFile)
          arcpy.AddMessage("Success. You can find the kmz in the link below")
          outputName = arcpy.SetParameterAsText(2,kmzFile)
          arcpy.AddMessage("Error exporting kmz")
if outputFormat == ".xls (Excel)":
          excelFile = os.path.join(arcpy.env.scratchFolder, "export.xls")
          arcpy.TableToExcel_conversion(featureLayer, excelFile)
          outputName = arcpy.SetParameterAsText(2,excelFile)
          arcpy.AddMessage("Error exporting kmz")
if outputFormat == ".shp (Shapefile)":     
     #shpFile = os.path.join(arcpy.env.scratchFolder, "export.shp")
     arcpy.AddMessage("shp file")
     #createFolder(outFolder + r'\data')
     #a = outFolder + r'\data'
     arcpy.FeatureClassToShapefile_conversion(featureLayer, arcpy.env.scratchFolder)
     shutil.make_archive(arcpy.env.scratchFolder, 'zip', arcpy.env.scratchFolder)
     outputFile = arcpy.env.scratchFolder + ".zip"
     outputName = arcpy.SetParameterAsText(2, outputFile)