AnsweredAssumed Answered

Geoprocessing service using python list function.

Question asked by scott.bradley-eagle-co-nz-esridist on Jan 10, 2012
Latest reply on Jan 26, 2012 by scott.bradley-eagle-co-nz-esridist
Hi, I have hit the wall on this one. Basically I'm looking for an answer on whether it is possible or not.

I have the following script which I have published to AGS as a Geoprocessing Service.

import sys, arcpy, string, re
fc = arcpy.GetParameterAsText(0)

arcpy.AddMessage( str(fc))

try:
    fList = arcpy.ListFields (fc)
    Result = str(len(fList))
    for field in fList:
        Result += " " + field.name
    arcpy.SetParameter(1, Result)
except:
    sys.exit("Fail! " + Result)

I have broken it down to its simplest form so all it does is take a feature set as input and outputs a string of field names using the Python function 'ListFields'

The issue is that at ArcGIS for Desktop it returns results fine ie. all fields are returned in the string. But when I test it at the REST end point using a JSON geometry it only returns the fields OBJECTID and SHAPE.

Any ideas where I maybe going wrong? Or is it simply a case of horses for courses and the ListFields function can not access the fields from geometries stored in a JSON.

Any help for be appreciated.

Here is my test geometry.

{
  "displayFieldName" : "Name",
  "fieldAliases" : {
    "Name" : "Name",
    "Type" : "Type",
    "Status" : "Status"
  },
  "geometryType" : "esriGeometryPoint",
  "spatialReference" : {
    "wkid" : 2193
  },
  "fields" : [
    {
      "name" : "Name",
      "type" : "esriFieldTypeString",
      "alias" : "Name",
      "length" : 50
    },
    {
      "name" : "Type",
      "type" : "esriFieldTypeString",
      "alias" : "Type",
      "length" : 50
    },
    {
      "name" : "Status",
      "type" : "esriFieldTypeString",
      "alias" : "Status",
      "length" : 50
    }
  ],
  "features" : [
    {
      "attributes" : {
        "Name" : "Scott",
        "Type" : null,
        "Status" : null
      },
      "geometry" : {
        "x" : 1800864.6298000002,
        "y" : 5814755.6933000004
      }
    }
  ]
}

Outcomes