Geoprocessing Service Widget Clear In_Memory Input

2531
4
06-20-2013 01:54 PM
by Anonymous User
Not applicable
Original User: jwbarge

Hello,

I have a model published as a geoprocessing widget in Flex 3.3 that enables data entry staff to draw a line, have it buffered, and then have the buffer polygon appended to our master ArcSDE database.

This all works fine except that when the user finishes processing a line (the buffer is generated and appended to sde DB) and is ready to map a new line, I want the first line drawn to be GONE from memory. The way it's working now, unless the user remembers to click "Clear" (see attached widget image) to clear the preceeding drawings, all of the lines get re-buffered and appended again to my master DB each time a new line is drawn and submitted.

My input line is a Feature Set data type set as an in_memory variable and as a model parameter.

I've put a Delete command near the end of my model to delete the in_memory line, but the Geoprocessing Service widget doesn't seem to recognize the Delete.

How do I auto clear (delete) the in_memory feature set (line) before the widget (model) runs (is submitted) again?

Thanks for any help,
John
[ATTACH=CONFIG]25391[/ATTACH]
[ATTACH=CONFIG]25392[/ATTACH]
0 Kudos
4 Replies
by Anonymous User
Not applicable
Original User: Glomar

John,

Not sure if this will work but I think it will.

Export your model to a python script. Edit the script by adding a line deleting the in_memory feature. Publish the python script as a geoprocessing service.

Model builder doesn't have all the available functions in arcpy.

Patrick
0 Kudos
JohnBarge
New Contributor
Patrick,

Thanks for the suggestion. It required me to learn some new things which is all good. I exported the model to a python script, added the script to a toolbox, set up the input and output parameters. I ran the script in ArcMap (10.1 sp1) with appropriate layers in my mxd and, it didn't work. The error said the Buffer command used the same input and output in_memory feature set. I then defined an output feature set from a scratch feature class in a file geodatabase. I added the arcpy delete commands to the end of my script for the input in_memory line and output buffer feature set. This was successful in ArcMap.

Unfortunately, after publishing this script tool to a geoprocessing service and running it in my Flex viewer, I'm right back where I started. The delete command doesn't remove the input lines drawn after each time the Submit button is executed. The end-user still has to push the Clear button to delete previously drawn in_memory lines.

I'm still glad I have a better working knowledge of python scripts - so, thanks. Further suggestions are greatly appreciated.

Here's my script that works in ArcMap but doesn't clear the in_memory features in ArcServer:

# Usage: LineToProjectTransaction <Distance> <Feature_Set> <xxbuf_shp>
# Description:
# Add Agency Projects to the master GIS Project database that are best mapped as linear features such as road or utility corridors.
# User enters the project transaction year, project number, and their initials, then digitizes a line on the map. A 100 foot wide buffer polygon is calculated from the digitized line.
# The buffer polygon is appended with attributes to Transaction_poly layer in GIS_MAD sde db.
# ---------------------------------------------------------------------------

# Import arcpy module
import arcpy

# Script arguments
Project_Year = arcpy.GetParameterAsText(0)
if Project_Year == '#' or not Project_Year:
    Project_Year = "2013" # provide a default value if unspecified

Project_Number_eg_0025 = arcpy.GetParameterAsText(1)

Your_initials = arcpy.GetParameterAsText(2)

Distance = arcpy.GetParameterAsText(3)
if Distance == '#' or not Distance:
    Distance = "50 Feet" # provide a default value if unspecified

Input_Line = arcpy.GetParameterAsText(4)
if Input_Line == '#' or not Input_Line:
    Input_Line = "M:\\ApaGis\\Scratch\\scratch.gdb\\xxline2" # provide a default value if unspecified

TransactionPoly2 = arcpy.GetParameterAsText(5)
if TransactionPoly2 == '#' or not TransactionPoly2:
    TransactionPoly2 = "Database Connections\\GIS_MAD.sde\\GIS_MAD.DBO.Transaction_Poly" # provide a default value if unspecified

# Local variables:
xxbuffer = "M:\\ApaGis\\Scratch\\scratch.gdb\\xxbuf"
GIS_MAD_DBO_Transaction_Poly = "Database Connections\\GIS_MAD.sde\\GIS_MAD.DBO.Transaction_Poly"
APANUMBER = "'"+'P'+Project_Year+"-"+Project_Number_eg_0025.upper()+"'"

# Check for the existance of in_memory\\BufferedLine output data before running Buffer.
if arcpy.Exists("M:\\ApaGis\\Scratch\\scratch.gdb\\xxbuf"):
    arcpy.Delete_management("M:\\ApaGis\\Scratch\\scratch.gdb\\xxbuf")

# Process: Buffer
arcpy.Buffer_analysis(Input_Line, xxbuffer, Distance, "FULL", "FLAT", "NONE", "")

# Process: Calculate Transaction Type
arcpy.CalculateField_management(xxbuffer, "TRANSACTIONTYPE", "'P'", "PYTHON", "")

# Process: Calculate APA Number
arcpy.CalculateField_management(xxbuffer, "APANUMBER", APANUMBER, "PYTHON", "")

# Process: Calculate Data Entry Date
arcpy.CalculateField_management(xxbuffer, "FEATUREDATE", "datetime.datetime.now( )", "PYTHON", "")

# Process: Calculate Feature Source
arcpy.CalculateField_management(xxbuffer, "FEATURESOURCE", "'20'", "PYTHON", "")

# Process: Calculate Staff
arcpy.CalculateField_management(xxbuffer, "STAFF", '"'+Your_initials.upper()+'"', "PYTHON", "")

# Process: Append
arcpy.Append_management(xxbuffer, GIS_MAD_DBO_Transaction_Poly, "No_TEST", "", "")

# Process: Delete
arcpy.Delete_management(Input_Line)

# Process: Delete
arcpy.Delete_management(xxbuffer)

arcpy.RefreshActiveView()
0 Kudos
by Anonymous User
Not applicable
Original User: GISDev01

You just want to clear the line after they Submit the job?

Why not run a .clear() function on your graphics layer which the line is being added to?

graphicsLayerName.clear();
0 Kudos
PatrickMullen1
New Contributor III
John,

In order to clear the graphics after every successful completion of the script, you will need to edit the source code to fire the function that clears the graphics after the geoprocessing tool completes its task. I am not sure where in the code this would be, but I will take a look around Friday when I have access to it.

I am curious if the python script takes a while to complete. If so, you can use the in_memory workspace instead of a scratch gdb. Check out this help section for more details: http://resources.arcgis.com/en/help/main/10.1/index.html#//002w0000005s000000

Patrick
0 Kudos