Add a Geoprocessing Select by attribute and zoom to feature

3519
2
Jump to solution
02-29-2012 11:43 AM
DougKnight
New Contributor II
I have created a stand alone python script to select by attribute using wild cards, and then zoom to the selected feature. I imported the script and made a tool from it in arcmap, have published both the GP and map services,  but cant seem to get them to communicate with each other once they are consumed inside the viewer.  The map service pulls into the viewer just fine, and the GP input parameters as text works just fine, but once it has run it doesn't select or zoom to anything in the viewer.  I know it is working in the mxd, but I just can't seem to get the GP to communicate with the map service once they are inside the viewer itself.  Any insight would be greatly appreciated, below is a copy of my code:
import arcpy
from arcpy import env

MXD = arcpy.mapping.MapDocument ('CURRENT')
DF = arcpy.mapping.ListDataFrames (MXD, "web Mercator")[0]

env.workspace = 'CURRENT'
NewAgreeNum = arcpy.GetParameterAsText(0)
in_features = "Easement_Centroids"
lyr = arcpy.mapping.ListLayers(MXD, in_features, DF)[0]

out_features = "Easements_Centroids"
where_clause = "New_Agree_Num LIKE '%" + NewAgreeNum + "%'"


arcpy.AddMessage (where_clause)
#arcpy.Select_analysis(in_features, out_features, where_clause)

arcpy.SelectLayerByAttribute_management (in_features, "NEW_SELECTION", where_clause)

DF.extent = lyr.getSelectedExtent()

#DF.zoomToSelectedFeatures()
arcpy.RefreshActiveView()
0 Kudos
1 Solution

Accepted Solutions
ArokiyaJoseph
New Contributor III
Knightdo,

To understand what's happening try this simple exercise.. Publish a mxd document as map service and use it in SLViewer. Now, open the mxd document in ArcMap and pan, zoom the layer. Will the zoom/pan change reflect in SLViewer? No.
That's exactly what's happening here as well. The gpservice is updating the layer extent in the map document. But, it will not affect the map service.

The SLviewer communicates to MapService and GPService and brings together their functionality at the web browser. In other words, GPService is unaware of map service and vice versa.

You have started out in the right direction, but we need to tweak our logic a bit to accomplish what you are trying to do here.

1. The GPService need to communicate the selected features to SLViewer.
2. The SLViewer should update the map service extent accordingly.

To accomplish Step 1:

Update your python code to  create a output parameter.

#uncomment Select_Analysis
arcpy.AddMessage (where_clause)
arcpy.Select_analysis(in_features, out_features, where_clause)
arcpy.SetParameterAsText(1,out_features)

To accomplish Step 2:

The SLViewer will draw the output features as a layer.
Use the Zoom To Layer tool in SLViewer to zoom to gp output feature layer.

Hope that helps!

View solution in original post

0 Kudos
2 Replies
ArokiyaJoseph
New Contributor III
Knightdo,

To understand what's happening try this simple exercise.. Publish a mxd document as map service and use it in SLViewer. Now, open the mxd document in ArcMap and pan, zoom the layer. Will the zoom/pan change reflect in SLViewer? No.
That's exactly what's happening here as well. The gpservice is updating the layer extent in the map document. But, it will not affect the map service.

The SLviewer communicates to MapService and GPService and brings together their functionality at the web browser. In other words, GPService is unaware of map service and vice versa.

You have started out in the right direction, but we need to tweak our logic a bit to accomplish what you are trying to do here.

1. The GPService need to communicate the selected features to SLViewer.
2. The SLViewer should update the map service extent accordingly.

To accomplish Step 1:

Update your python code to  create a output parameter.

#uncomment Select_Analysis
arcpy.AddMessage (where_clause)
arcpy.Select_analysis(in_features, out_features, where_clause)
arcpy.SetParameterAsText(1,out_features)

To accomplish Step 2:

The SLViewer will draw the output features as a layer.
Use the Zoom To Layer tool in SLViewer to zoom to gp output feature layer.

Hope that helps!
0 Kudos
ToddSmith
New Contributor II
Knightdo,

To understand what's happening try this simple exercise.. Publish a mxd document as map service and use it in SLViewer. Now, open the mxd document in ArcMap and pan, zoom the layer. Will the zoom/pan change reflect in SLViewer? No.
That's exactly what's happening here as well. The gpservice is updating the layer extent in the map document. But, it will not affect the map service.

The SLviewer communicates to MapService and GPService and brings together their functionality at the web browser. In other words, GPService is unaware of map service and vice versa.

You have started out in the right direction, but we need to tweak our logic a bit to accomplish what you are trying to do here.

1. The GPService need to communicate the selected features to SLViewer.
2. The SLViewer should update the map service extent accordingly.

To accomplish Step 1:

Update your python code to  create a output parameter.

#uncomment Select_Analysis
arcpy.AddMessage (where_clause)
arcpy.Select_analysis(in_features, out_features, where_clause)
arcpy.SetParameterAsText(1,out_features)

To accomplish Step 2:

The SLViewer will draw the output features as a layer.
Use the Zoom To Layer tool in SLViewer to zoom to gp output feature layer.

Hope that helps!



Did you ever get this working?  I am trying something similar now and I am not having much luck.  It has the same behavior for me (does not select anything in the silverlight viewer web map).  According to the arcgis help you can only use Models as Geoprocessing services for web applications but how could this be correct when I am able to publish a script similar to this as a Geoprocessing service just fine.  It would be nice to get this figured out soon as I have spent a fair amount of time on it already.
Thanks,
Todd
0 Kudos