Geoprocessing service that returns features to ArcMap

6113
13
Jump to solution
06-24-2015 10:36 AM
BrendanDwyer
Occasional Contributor

I have a python tool that will take a point feature class and does some magic and returns a polygon feature class (it works out areas where the points are clustered, adds fields, yadda yadda yadda).  It runs great, does what I want it to do.

I need to turn that into a geoprocessing service that a user can run from arcmap and returns the polygon features as a layer to arcmap.  How do I do that?  I am able to run the tool and share the result as a service, but the service returns an empty result.

I think I'm just not able to follow the documentation on how to return a feature set to the user.  Do I need to start a feature service using the results?  If so, every time a user runs the tool does it start a new service?  What parameters in python and on the service creation wizard do I need to set to enable this?

Thanks in advance...

-Brendan

13 Replies
TerryGustafson
Occasional Contributor II

Yeah I have been tinkering with the python script that was exported. I have it working till the merge and then it completely crashes ArcMap.. Is there another was to combine 2 tables?

0 Kudos
TerryGustafson
Occasional Contributor II

Ok, I used append and it worked so looking good.  thanks for your help.

0 Kudos
TerryGustafson
Occasional Contributor II

Maybe you can point me in the right direction on this.  So I have the python script running and I added the script to the tool box.  the problem is that I need to be able to have the user enter the First_point and then end_point.  when I run the script through the tool box it says this tool has no parameters.  Here is the working python script.

# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------
# new_seg4.py
# Created on: 2015-10-29 07:32:00.00000
#   (generated by ArcGIS/ModelBuilder)
# Usage: new_seg4 <first_point> <end_point> <first_point__2_> <end_point__3_> <beg_point> <end_pt> <first_pt_loc> <end_pt_loc> <points> <segment> <temp__2_> 
# Description: 
# ---------------------------------------------------------------------------
# Import arcpy module
import arcpy
arcpy.env.overwriteOutput = True
toolbox = ("E:/MDTAPPS/interactive/refmseg.tbx")
# Load required toolboxes
arcpy.ImportToolbox("E:/MDTAPPS/interactive/refmseg.tbx")
# Script arguments
first_point = arcpy.GetParameterAsText(0)
if first_point == '#' or not first_point:
    first_point = "E:\\MDTAPPS\\interactive\\interactive.mdb\\first_point" # provide a default value if unspecified
end_point = arcpy.GetParameterAsText(1)
if end_point == '#' or not end_point:
    end_point = "E:\\MDTAPPS\\interactive\\interactive.mdb\\end_point" # provide a default value if unspecified
first_point__2_ = arcpy.GetParameterAsText(2)
if first_point__2_ == '#' or not first_point__2_:
    first_point__2_ = "E:\\MDTAPPS\\interactive\\interactive.mdb\\first_point" # provide a default value if unspecified
end_point__3_ = arcpy.GetParameterAsText(3)
if end_point__3_ == '#' or not end_point__3_:
    end_point__3_ = "E:\\MDTAPPS\\interactive\\interactive.mdb\\end_point" # provide a default value if unspecified
beg_point = arcpy.GetParameterAsText(4)
if beg_point == '#' or not beg_point:
    beg_point = "beg_point" # provide a default value if unspecified
end_pt = arcpy.GetParameterAsText(5)
if end_pt == '#' or not end_pt:
    end_pt = "end_pt" # provide a default value if unspecified
first_pt_loc = arcpy.GetParameterAsText(6)
if first_pt_loc == '#' or not first_pt_loc:
    first_pt_loc = "E:\\MDTAPPS\\interactive\\interactive.mdb\\first_pt_loc" # provide a default value if unspecified
end_pt_loc = arcpy.GetParameterAsText(7)
if end_pt_loc == '#' or not end_pt_loc:
    end_pt_loc = "E:\\MDTAPPS\\interactive\\interactive.mdb\\end_pt_loc" # provide a default value if unspecified
points = arcpy.GetParameterAsText(8)
if points == '#' or not points:
    points = "E:\\MDTAPPS\\interactive\\interactive.mdb\\points" # provide a default value if unspecified
segment = arcpy.GetParameterAsText(9)
if segment == '#' or not segment:
    segment = "segment" # provide a default value if unspecified
temp__2_ = arcpy.GetParameterAsText(10)
if temp__2_ == '#' or not temp__2_:
    temp__2_ = "E:\\MDTAPPS\\interactive\\interactive.mdb\\temp" # provide a default value if unspecified
# Local variables:
Output_Event_Table_Properties = "RID POINT MEAS"
Output_Event_Table_Properties__2_ = "RID POINT MEAS"
MDTGIS_ROUTES_LRM_RM = "MDTGIS.ROUTES_LRM_RM"
MDTGIS_ROUTES_LRM_DC_MI = "MDTGIS.ROUTES_LRM_DC_MI"
MDTGIS_ROUTES_LRM_DC_MI__2_ = "MDTGIS.ROUTES_LRM_DC_MI"
interactive_mdb = "E:\\MDTAPPS\\interactive\\interactive.mdb"
MDTGIS_ROUTES_LRM_DC = "MDTGIS_ROUTES_LRM_DC"
temp = "E:\\MDTAPPS\\interactive\\interactive.mdb\\temp"
# Process: Calculate Field
arcpy.CalculateField_management(first_point, "Corridor", "str(!Corridor!) + \"_\" + str(!RM!)", "PYTHON_9.3", "")
# Process: Calculate Field (2)
arcpy.CalculateField_management(end_point, "Corridor", "str(!Corridor!) + \"_\" + str(!RM!)", "PYTHON_9.3", "")
# Process: Make Route Event Layer (2)
arcpy.MakeRouteEventLayer_lr(MDTGIS_ROUTES_LRM_RM, "ROUTE_ID", end_point__3_, "Corridor POINT end_offset", end_pt, "", "ERROR_FIELD", "NO_ANGLE_FIELD", "NORMAL", "ANGLE", "LEFT", "POINT")
# Process: Make Route Event Layer
arcpy.MakeRouteEventLayer_lr(MDTGIS_ROUTES_LRM_RM, "ROUTE_ID", first_point__2_, "Corridor POINT beg_offset", beg_point, "", "ERROR_FIELD", "NO_ANGLE_FIELD", "NORMAL", "ANGLE", "LEFT", "POINT")
# Process: Locate Features Along Routes
arcpy.LocateFeaturesAlongRoutes_lr(beg_point, MDTGIS_ROUTES_LRM_DC_MI, "CORRIDOR", "0 Meters", first_pt_loc, Output_Event_Table_Properties, "ALL", "NO_DISTANCE", "ZERO", "NO_FIELDS", "NO_M_DIRECTION")
# Process: Locate Features Along Routes (2)
arcpy.LocateFeaturesAlongRoutes_lr(end_pt, MDTGIS_ROUTES_LRM_DC_MI__2_, "CORRIDOR", "0 Meters", end_pt_loc, Output_Event_Table_Properties__2_, "FIRST", "NO_DISTANCE", "ZERO", "NO_FIELDS", "NO_M_DIRECTION")
# Process: Append
arcpy.Append_management("E:\\MDTAPPS\\interactive\\interactive.mdb\\first_pt_loc;E:\\MDTAPPS\\interactive\\interactive.mdb\\end_pt_loc", temp, "", "RID \"CORRIDOR\" true true false 10 Text 0 0 ,First,#,E:\\MDTAPPS\\interactive\\interactive.mdb\\first_pt_loc,RID,-1,-1,E:\\MDTAPPS\\interactive\\interactive.mdb\\end_pt_loc,RID,-1,-1;beg_offset \"beg_offset\" true true false 8 Double 0 0 ,First,#;end_offset \"end_offset\" true true false 8 Double 0 0 ,First,#", "")
# Process: Table to Table
arcpy.TableToTable_conversion(temp__2_, interactive_mdb, "points", "", "RID \"CORRIDOR\" true true false 10 Text 0 0 ,First,#,E:\\MDTAPPS\\interactive\\interactive.mdb\\temp,RID,-1,-1;beg_offset \"beg_offset\" true true false 8 Double 0 0 ,First,#,E:\\MDTAPPS\\interactive\\interactive.mdb\\temp,beg_offset,-1,-1;end_offset \"end_offset\" true true false 8 Double 0 0 ,First,#,E:\\MDTAPPS\\interactive\\interactive.mdb\\temp,end_offset,-1,-1", "")
# Process: Make Route Event Layer (3)
arcpy.MakeRouteEventLayer_lr(MDTGIS_ROUTES_LRM_DC, "CORRIDOR", points, "rid LINE beg_offset end_offset", segment, "", "ERROR_FIELD", "NO_ANGLE_FIELD", "NORMAL", "ANGLE", "LEFT", "POINT")
# Process: Script1
arcpy.Script1_ref()

0 Kudos
FilipKrál
Occasional Contributor III

Hi,

You've made quite some progress here.

In order to see the tool parameters in the tool dialog, you have to configure them in the script tool properties as it is described in Adding a script tool​ and in Setting script tool parameters​. Make sure the order of parameters in the table matches the numbers you assigned to them in the script (0 is the first parameter).

You will also likely need to use the SetParameter ​​function by the end of your script to let ArcGIS know what values should the tool return. For example, say that the end point parameter is the third parameter of your tool and its direction is "output". In your script you will write arcpy.GetParameter(2) to access the value provided by the user and eventually arcpy.SetParameter(2, 'some value') to notify ArcGIS what the resulting value is.

Hope this makes sense.

Filip.