Exporting SHP file on ArcGIS Server with Geoprocessing Widget

200
0
10-06-2020 09:17 PM
by Anonymous User
Not applicable

Hello, 

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 
https://xxxxxx.com/server/rest/directories/arcgisjobs/gp/export/j0ba310e06ab92dsdsde8f71690faba/scra... 

That link is invalid, however when I change it to (remove the extra scratch at the end) 
https://xxxxxx.com/server/rest/directories/arcgisjobs/gp/export/j0ba310e06ab92dsdsde8f71690faba/scra... 
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 scratch.zip with the shpfile in it. C:\Users\adam\Documents\ArcGIS\scratch.zip 

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



if outputFormat == ".kmz (Google Earth)":
	try:
		kmzFile = os.path.join(arcpy.env.scratchFolder, "export.kmz") 
		arcpy.MakeFeatureLayer_management(featureLayer, "in_memory\layer")
		#arcpy.ApplySymbologyFromLayer_management("in_memory\layer",lyr)
		arcpy.LayerToKML_conversion("in_memory\layer", kmzFile)
		arcpy.AddMessage("Success. You can find the kmz in the link below")
		arcpy.AddMessage(kmzFile)
		outputName = arcpy.SetParameterAsText(2,kmzFile)
	except:
		arcpy.AddMessage("Error exporting kmz")
		sys.exit()
	
if outputFormat == ".xls (Excel)":
	try:
		excelFile = os.path.join(arcpy.env.scratchFolder, "export.xls")
		arcpy.TableToExcel_conversion(featureLayer, excelFile)
		outputName = arcpy.SetParameterAsText(2,excelFile)
	except:
		arcpy.AddMessage("Error exporting kmz")
		sys.exit()
	
	
	
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)‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

0 Kudos
0 Replies