Python Geoprocessing Service return output features (GPFeatureRecordSetLayer?)

892
3
Jump to solution
07-18-2022 06:18 AM
RichardReinicke
Occasional Contributor II

Hi,

I actually want to create a Geoprocessing Service published from a Python Toolbox and ArcGIS Pro 2.8.3.

From a third party service I get geojson in my server-side process which I can transform into esri json or Features / FeatureLayer. But from there, how do I provide these features as output of my geoprocessing service? What kind of output data format do I have to use?

Docu says the server only supports a few data formats like GPFeatureRecordSetLayer which expects a special json input. But how can I automatically get such a json from my features?
  

 

 

        search_results = arcpy.Parameter(
            displayName="Search Results",
            name="search_results",
            datatype="GPFeatureRecordSetLayer",
            parameterType="Derived",
            direction="Output")

 

 

 

Esri Json doesn't seem to work.

 

 

esri_search_data = r"{0}\search_data.json".format(arcpy.env.scratchFolder)
arcpy.FeaturesToJSON_conversion(search_data_path, esri_search_data)
esri_data = self.read_textfile(esri_search_data)
parameters[1].value = esri_data

 

 

 

As a result the client should create a feature layer. 

My geoprocessing service should be used mainly by ArcGIS Pro clients. Optionally it would be great if the output could be used by esri web clients as well like Esri JS API. 

Does anybody know how this can be achieved?

0 Kudos
1 Solution

Accepted Solutions
RichardReinicke
Occasional Contributor II

With GPFeatureLayer as outpt datatype my ArcGIS Pro adds the local processing result as a new layer.

But for some reason that I don't know (are there logs, console, anything???) I'm not able to publish my tool to the server. ANLYZE and PUBLISH buttons are disabled without any hint whats wrong. Again my tool runs successfully in ArcGIS Pro. Pls Esri help the developer a little bit.

RichardReinicke_0-1658325407933.png

 

View solution in original post

0 Kudos
3 Replies
RichardReinicke
Occasional Contributor II

Nobody an idea? No one using Python geoprocessing services that return features to clients like ArcGIS Pro? From my understanding this should be a common task.

My process successfully creates a feature class from my third party data but I'm still unable to return this feature class in a way from my service, so that clients like ArcGIS Pro add them as a new layer to the active map.

search_results = arcpy.Parameter(
            displayName="Search Results",
            name="search_results",
            datatype="GPFeatureRecordSetLayer",
            parameterType="Derived",
            direction="Output")

srs_etrs89 = arcpy.SpatialReference(25832)
search_fc = arcpy.CreateFeatureclass_management(scratch_db_path, 
    "search_results", "POLYGON",
    "", "DISABLED", "DISABLED", srs_etrs89)

fields = ['text', 'typ', 'score', 'bbox'] # Only use common bkg fields
search_results_cursor = None

for index, feature in enumerate(result_features, start=0):
    if index == 0:
        for field in fields:
            arcpy.AddField_management(search_fc, field, "TEXT")
            fields.append('SHAPE@')
            search_results_cursor = arcpy.da.InsertCursor(search_fc, fields)
    self.write_feature_row(search_results_cursor, feature, srs_etrs89)

del search_results_cursor
parameters[1].value = search_fc

 

0 Kudos
RichardReinicke
Occasional Contributor II

With GPFeatureLayer as outpt datatype my ArcGIS Pro adds the local processing result as a new layer.

But for some reason that I don't know (are there logs, console, anything???) I'm not able to publish my tool to the server. ANLYZE and PUBLISH buttons are disabled without any hint whats wrong. Again my tool runs successfully in ArcGIS Pro. Pls Esri help the developer a little bit.

RichardReinicke_0-1658325407933.png

 

0 Kudos
RichardReinicke
Occasional Contributor II

Publishing worked after restart of ArcGIS Pro. 

0 Kudos