GP Tool export FeatureSet with symbology

412
1
03-10-2021 02:36 AM
Robert_van_Gilst
New Contributor III

Hi,

I am creating a GP tool, with a Python toolbox, that should return FeatureSets with symbology.

To simplify my process, I try the following, inspired by the FeatureSet documentation (https://pro.arcgis.com/en/pro-app/latest/arcpy/classes/featureset.htm). It is just a combination of example 1 and 2.

 

    def execute(self, parameters, messages):
        """The source code of the tool."""
        coordinates = [[-117.196717216, 34.046944853],
               [-117.186226483, 34.046498438],
               [-117.179530271, 34.038016569],
               [-117.187454122, 34.039132605],
               [-117.177744614, 34.056765964],
               [-117.156205131, 34.064466609],
               [-117.145491191, 34.068261129],
               [-117.170825195, 34.073618099],
               [-117.186784501, 34.068149525],
               [-117.158325598, 34.03489167]]

        # Create an in_memory feature class to initially contain the coordinate pairs
        feature_class = arcpy.CreateFeatureclass_management(
            "in_memory", "tempfc", "POINT")[0]

        # Open an insert cursor
        with arcpy.da.InsertCursor(feature_class, ["SHAPE@XY"]) as cursor:
            # Iterate through list of coordinates and add to cursor
            for (x, y) in coordinates:
                cursor.insertRow([(x, y)])
        renderer = '''{
            "renderer": {
                "type": "simple",
                "symbol": {
                    "type": "esriSFS",
                    "style": "esriSFSSolid",
                    "color": [
                        255,
                        0,
                        0,
                        255
                    ],
                    "outline": {
                        "type": "esriSLS",
                        "style": "esriSLSSolid",
                        "color": [
                            110,
                            110,
                            110,
                            255
                        ],
                        "width": 2
                    }
                },
                "label": "",
                "description": "",
                "rotationType": "geographic",
                "rotationExpression": ""
            }
        }'''

        # Create empty FeatureSet
        feature_set = arcpy.FeatureSet()

        # Load data into FeatureSet with query
        feature_set.load(feature_class, None, None, renderer, True)
        parameters[2].value = feature_set

        return

 

In the tool I have the following output parameter:

out_features = arcpy.Parameter(
  displayName="Observationer",
  name="Observationer",
  datatype="DEFeatureClass",
  #datatype="GPFeatureRecordSetLayer",
  parameterType="Optional",
  direction="Derived")

Until now I use datatype="DEFeatureClass" in stead of the more logical GPFeatureRecordSetLayer. Because the latter one will not return any records when I use that.

Returning using DEFeatureClass:

{
 "paramName": "Observationer",
 "dataType": "GPFeatureRecordSetLayer",
 "value": {
  "displayFieldName": "",
  "geometryType": "esriGeometryPoint",
  "spatialReference": {"wkid": null},
  "fields": [{
   "name": "OID",
   "type": "esriFieldTypeOID",
   "alias": "OID"
  }],
  "features": [
   {
    "attributes": {"OID": 1},
    "geometry": {
     "x": -117.19671630859375,
     "y": 34.046875
    }
   },
   {
    "attributes": {"OID": 2},
    "geometry": {
     "x": -117.18621826171875,
     "y": 34.0465087890625
    }
   },
   .....
  ],
  "exceededTransferLimit": false
 }
}

But no symbology/renderer

Using GPFeatureRecordSetLayer returns:

{
 "paramName": "Observationer",
 "dataType": "GPFeatureRecordSetLayer",
 "value": {
  "displayFieldName": "",
  "geometryType": "esriGeometryPoint",
  "spatialReference": {"wkid": null},
  "fields": [{
   "name": "OID",
   "type": "esriFieldTypeOID",
   "alias": "OID"
  }],
  "features": [],
  "exceededTransferLimit": false
 }
}

No features!!

When I read the following https://developers.arcgis.com/rest/services-reference/gp-data-types.htm#ESRI_SECTION2_8DE491EA13D843... under the FeatureCollection output section, it is referring to a returnFeatureCollection setting which I cannot find any information about anywhere.

I hope someone has a clue of what to do.

The complete toolbox:

# -*- coding: utf-8 -*-
import arcpy
import os

class test_tool(object):
    def __init__(self):
        """Define the tool (tool name is the name of the class)."""
        self.label = "Test"
        self.description = "Test"
        self.canRunInBackground = False

    def getParameterInfo(self):
        """Define parameter definitions"""
        #Define parameter definitions
        out_features = arcpy.Parameter(
            displayName="Observationer",
            name="Observationer",
            datatype="DEFeatureClass",
            #datatype="GPFeatureRecordSetLayer",
            parameterType="Optional",
            direction="Derived")
        params = [out_features]

        return params

    def isLicensed(self):
        """Set whether tool is licensed to execute."""
        return True

    def updateParameters(self, parameters):
        """Modify the values and properties of parameters before internal
        validation is performed.  This method is called whenever a parameter
        has been changed."""
        return

    def updateMessages(self, parameters):
        """Modify the messages created by internal validation for each tool
        parameter.  This method is called after internal validation."""
        return

    def execute(self, parameters, messages):
        """The source code of the tool."""
        coordinates = [[-117.196717216, 34.046944853],
               [-117.186226483, 34.046498438],
               [-117.179530271, 34.038016569],
               [-117.187454122, 34.039132605],
               [-117.177744614, 34.056765964],
               [-117.156205131, 34.064466609],
               [-117.145491191, 34.068261129],
               [-117.170825195, 34.073618099],
               [-117.186784501, 34.068149525],
               [-117.158325598, 34.03489167]]

        # Create an in_memory feature class to initially contain the coordinate pairs
        feature_class = arcpy.CreateFeatureclass_management(
            "in_memory", "tempfc", "POINT")[0]

        # Open an insert cursor
        with arcpy.da.InsertCursor(feature_class, ["SHAPE@XY"]) as cursor:
            # Iterate through list of coordinates and add to cursor
            for (x, y) in coordinates:
                cursor.insertRow([(x, y)])
        renderer = '''{
            "renderer": {
                "type": "simple",
                "symbol": {
                    "type": "esriSFS",
                    "style": "esriSFSSolid",
                    "color": [
                        255,
                        0,
                        0,
                        255
                    ],
                    "outline": {
                        "type": "esriSLS",
                        "style": "esriSLSSolid",
                        "color": [
                            110,
                            110,
                            110,
                            255
                        ],
                        "width": 2
                    }
                },
                "label": "",
                "description": "",
                "rotationType": "geographic",
                "rotationExpression": ""
            }
        }'''

        # Create empty FeatureSet
        feature_set = arcpy.FeatureSet()

        # Load data into FeatureSet with query
        feature_set.load(feature_class, None, None, renderer, True)
        parameters[2].value = feature_set
        return

 

0 Kudos
1 Reply
Robert_van_Gilst
New Contributor III

Bump. No one. REALLY??

0 Kudos