[GIS] ArcGIS Geoprocesing Service using map service data for input

arcgis-10.2arcgis-rest-apiarcgis-servergeoprocessing-servicemap-service

I'd like to create a geoprocessing service in ArcGIS Server (10.2) which uses an existing map service as input. I have been trying to do this with a ModelBuilder model, but it's copying the existing map service data to my GP service.

More precisely, what I am doing is using a NRCS soil map unit layer and intersecting with a farm field boundary layer. Both the soil layer and the farm field layer get published with another process.

None of the ESRI examples of GP services show using existing map services as inputs, unless I am missing something.

Best Answer

The answer for me was to look at http://blogs.esri.com/esri/arcgis/2013/10/10/quick-tips-consuming-feature-services-with-geoprocessing/ and then create Python scripts which directly extract what's needed out of me map services.

Below is an example, which is running off an ArcGIS server on my desktop. It's doing what Select by Attribute would otherwise do. In this case, it's selecting a farm field boundary by name. The field boundary runs as a feature service and users draw the boundaries using the JSAPI Edit Dijit.

I'd hope that ESRI would add some more standard tools which would directly do this sort of thing. Maybe in 10.4, since 10.3 is already out the door this week...

# SelectFieldByName.py
# Get an ArcGIS server feature set
# input
#   0: FeatureService URL
#   1: Field Name
# output
#   Feature Set
# Modification History
# dhh   15Dec2014   Original
import arcpy
import os
import sys
import traceback
import urllib

# Get the Parameters
fsBaseURL = arcpy.GetParameterAsText(0)
fieldName = arcpy.GetParameterAsText(1)
where = urllib.quote(r"Name='{}'".format(fieldName))
fields = '*'
token = ''

# REST query of mapservice
query = r"/query?where={}&outFields={}&returnGeometry=true&f=json&token={}".format(where, fields, token)
fs = arcpy.FeatureSet()
fsURL = fsBaseURL + query
arcpy.AddMessage("Loading {}.".format(fsURL))
fs.load(fsURL)
arcpy.AddMessage("Loaded {} finished.".format(fsURL, fs.JSON))
arcpy.SetParameter(2, fs);
Related Question