ArcGIS REST API find nearest example

1642
1
02-08-2018 05:50 AM
TylerWaring
Occasional Contributor II

Greetings, I'm trying to build a find nearest tool that uses the REST API to perform a Find Nearest analysis. Right now I'm working in the service directory form to get some simple results. From there I'll integrate into an http call from a Java application. 

I'm walking through the documentation to build out a simplified example and entering the information into the html form (accepting most of the defaults) as such: 

analysisLayer: 

{
   "layerDefinition": {
      "geometryType": "esriGeometryPoint",
      "fields": [{
         "name": "OBJECTID",
         "type": "esriFieldTypeOID",
         "alias": "OBJECTID"
      }]
   },
   "featureSet": {
      "geometryType": "esriGeometryPoint",
      "spatialReference": {
         "wkid": 4326
      },
      "features": [{
         "geometry": {
               "x": -78.78227,
               "y": 35.78691
         },
         "attributes": {
            "OBJECTID": 1
         }
      }]
   }
}

nearLayer: 

  {
      "layerDefinition": {
            "geometryType": "esriGeometryPoint",
            "fields": [
            {
                  "name": "OBJECTID",
                  "type": "esriFieldTypeOID",
                  "alias": "OBJECTID"
            }
            ]
      },
      "featureSet": {
            "geometryType": "esriGeometryPoint",
            "spatialReference": {
                  "wkid": 4326
            },
      "features": [
      {
            "geometry": {
                  "x": -78.78845,
                  "y": 35.79748
      },
            "attributes": {
                  "OBJECTID": 1
      }
   },
   {
         "geometry": {      
                 "x": -78.79154,
                  "y": 35.78691
         },
         "attributes": {
               "OBJECTID": 2
         }
   },
   {
         "geometry": {
               "x": -78.78604,
               "y": 35.78272
         },
         "attributes": {
               "OBJECTID": 3
         }
   },
   {
         "geometry": {
               "x": -78.77162,
               "y": 35.79192
         },
         "attributes": {
               "OBJECTID": 4
         }
   },
   {
         "geometry": {
               "x": -78.77541,
               "y": 35.78774
         },
         "attributes": {
               "OBJECTID": 5
         }
   }
]
}
}

measurementType: 

   

   StraightLine

MaxCount: 

   100

searchCutoff: 

   

   5000

searchCutoffUnits:

   

   Meters

timeOfDay: 

   null

timeZoneForTimeOfDay: 

   GeoLocal

I'm getting cryptic errors upon clicking the Submit Job (POST) button: 

  • esriJobMessageTypeError: {"messageCode": "AO_100030", "message": "FindNearest failed."}
  • esriJobMessageTypeError: Failed to execute (FindNearest).
  • esriJobMessageTypeError: Failed.

I'm assuming that there are some details that are expected from my analysisLayer and nearLayer JSON objects. However, I am unable to determine why the process failed from the error message. Does anyone recognize any issue with my JSON objects or is there a way that I can access a more detailed error message? 

Thanks, Tyler 

0 Kudos
1 Reply
TylerWaring
Occasional Contributor II

Update: to troubleshoot this issue and factor out as many variables as possible, I decided to run a simpler GPServer tool - CreateBuffers. I used the featureCollection example referenced in the tool's documentation (Feature input—ArcGIS REST API: Spatial Analysis Service | ArcGIS for Developers ) for simplicity sake. Strangely, I ended up getting the same errors: 

  • esriJobMessageTypeError: {"messageCode": "AO_100012", "message": "CreateBuffers failed."}
  • esriJobMessageTypeError: Failed to execute (CreateBuffers).
  • esriJobMessageTypeError: Failed.

I'm thinking that there must something other than the GPTask failing since the two required variables (inputLayer and distances) for CreateBuffers are either taken from the documentation (inputLayer) or are dirt simple (distances i.e. [4.0]). Is there something I should be checking for on the server?  

Following the Create Buffer documentation I created a request that looks like this in Chrome's HTTP Trace add-on: 

context:

dissolveType: None

distances: [4.0]

endType: Round

env:outSR:

env:processSR:

f: html

field:

inputLayer: {

      "layerDefinition": {

            "geometryType": "esriGeometryPoint",

            "fields": [

                  {

                        "name": "Id",

                        "type": "esriFieldTypeOID",

                        "alias": "Id"

                  },

                  {

                        "name": "Name",

                        "type": "esriFieldTypeString",

                        "alias": "Name"

                  }

            ]

      },

      "featureSet": {

            "geometryType": "esriGeometryPoint",

            "spatialReference": {

                  "wkid": 4326

            },

            "features": [

                  {

                        "geometry": {

                              "x": -104.44,

                              "y": 34.83

                        },

                        "attributes": {

                              "Id": 43,

                              "Name": "Feature 1"

                        }

                  },

                  {

                        "geometry": {

                              "x": -100.65,

                              "y": 33.69

                        },

                        "attributes": {

                              "Id": 67,

                              "Name": "Feature 2"

                        }

                  }

            ]

      },

      "filter": "Name = 'Feature 1'"

}

outputName:

returnM: false

returnZ: false

ringType: Disks

sideType: Full

units: Meters

0 Kudos