Feature layer output in webappbuilder / add to map

1196
3
04-05-2017 02:24 AM
HugoBouckaert
New Contributor II

Hi 

 

I have a python script that outputs to a feature layer.  The input is a CSV, but also could be something else. Using this on the desktop in ArcMap works. I then publish this as a geoprocessing service. However when I add the geoprocessing services as a geoprocessing widget in webappbuilder I get an error that I need to specify the feature layer output.

 

What I really want to do is to load a shapefile or a CSV and add that to the map. I had a look at

https://github.com/magis-nc/esri-webappbuilder-widget-FileImporter but to create a geoprocessing service, here also I have three output layers (point, line and polygon). The GP service cannot be created in webappbuilder because the feature layer outputs cannot be defined in webappbuilder (in the tool the output must be set to feature layer). Do I have to connect the feature layer output to an existing layer in Portal perhaps?

 

Anyway  the short question is when the output of a geoprocessing service is a feature layer, how can this be made to work in webappbuilder with the layer added to a map.  A code example that I can use to get me started (i.e. something I can publish as a geoprocessing service) would be great of course. 

 

Thanks

 

Hugo 

0 Kudos
3 Replies
JamesCrandall
MVP Frequent Contributor

Edit: I didn't notice at first and still can't quite tell if you are actually implementing jcornet's solution from GitHub, but it looks to be pretty close to what you need.  Just publish the GP service on your ArcGIS Server and it looks like they also supply a widget (I think that's what it is) you can add to your WAB solution.

There's likely a few things to consider but without looking at anything specific you have it will be difficult to locate the issue(s) you've run into.  Just some things to keep in mind:

1. Perhaps there is an alternative way to perform your task client-side.  I'd personally go down the path of just building a new widget that you can add to the WAB app.  The JavaScript API is quite powerful but you'd have to migrate everything to that language and I'm unsure if all of the tools you'd need are available but it's probably worth the time to investigate.

2. I do beleive the ArcGIS Server would need to be setup to allow uploads (your csv), although I have not gone down this route to see what is involved. 

3. I see that there is an input parameter type "File" available. That's where I'd start.

4. The output parameter should be set to Feature Layer.

5. Perform the conversion from your CSV to Featuer Layer and then create an arcpy.FeatureSet variable that you would set the output parameter to.

feature_class = "tmpfc"
arcpy.Clip_analysis(lyr1, lyr2, feature_class)
feature_class_lyr = arcpy.MakeFeatureLayer_management (feature_class, "feature_class_lyr")
feature_set = arcpy.FeatureSet(feature_class)
arcpy.SetParameter(1, feature_set)‍‍‍‍‍

6. Run the tool in ArcMap and see if it successfully adds your feature layer to the TOC.  If so, publish it.

7. Add the Geoprocessing widget to your WAB and specify the url pointing to the GP service you just published and it should automatically understand the input/output parameters required.

JamesCrandall
MVP Frequent Contributor

I gave it a go but because our AGS site is not configured to copy the data to it. 

I am able to add the widget to WAB Developer and it looks great, seems to be a good solution but I'm stopped due to not being able to publish the service.  I think you just need to:

1. Publish the supplied GP service.

2. Add the widget to your stemapps widgets folder.

3. Add the widget to your WAB and configure it to point to the service you published.

0 Kudos
HugoBouckaert
New Contributor II

Hi James

Thanks for that. I did get it to work, using a shapefile as the input parameter. At the moment what I comes out is the same as what I put in, but of course in the code you would do some sort of a transformation i.e. the Clip_Analysis which is in your original code.

My code now is this:

import arcpy
feature_class = arcpy.GetParameterAsText(0)
#arcpy.Clip_analysis(lyr1, lyr2, feature_class)
feature_class_lyr = arcpy.MakeFeatureLayer_management (feature_class, "feature_class_lyr")
feature_set = arcpy.FeatureSet(feature_class)
arcpy.SetParameter(1, feature_set) 

So the input parameter  in the toolbox script is set to shapefile, which, if executed from ArcMap looks for an actual shapefile, but from webappbuilder and Portal looks for a zip file (I was wondering if that would work). 

The output parameter is set to "Output" in the toolbox script and the type is Feature Set. If you then publish this as a geoprocessing service and then use geoprocessing URL in webappbuilder it works (setting  the input as shape file of course). 

Note that in this case (following your example) I am creating a Feature set directly from the feature class (i.e.the shapefile). It looks like you can only create a Feature set from a feature class, so if you need a feature layer for the output to add to the map, I suppose the order is:

Input shapefile

create feature layer to do certain operations. 

use CopyFeatures_management to create a feature class from the (now changed) feature layer. 

Create a feature set from the feature class

The feature set is the output added to the map. 

Would this be right? 

 

Thanks

Hugo