Input geometry point spatial query

209
1
Jump to solution
03-26-2024 02:15 PM
Labels (1)
JamesCrandall
MVP Frequent Contributor

When attempting to use point geometry as inputGeometry to query our Parcels REST service, it doesn't fail but it does return all parcels when I'm expecting only 1 parcel to be in the result.  Also, successfully doing a similar spatial query using polygon geometry so not sure why we're seeing a different result using point feature as the inputGeometry.

Using the "geometry" values in the example below as the input directly in the REST query interface returns the correct result.

Example input payload to the request:

 

 

{
  "f": "json",
  "geometryType": "esriGeometryPoint",
  "geometry": {
    "x": 952887.1388473287,
    "y": 830228.6453575715,
    "spatialReference": {
      "wkid": 2881
    }
  },
  "spatialRel": "esriSpatialRelIntersects",
  "distance": 0,
  "units": "esriSRUnit_Foot",
  "inSR": 2881,
  "where": "1=1",
  "outFields": "PARNO",
  "returnGeometry": "false",
  "returnCountOnly": "true",
  "featureEncoding": "esriDefault",
  "token": "validtoken"
}

 

 

 

This is being run via Python 3.x using the requests library (again, successfully with other geometry types).  In this code sample below the "geom" variable is as described in the "geometry" attribute above.

 

 

queryURL_parcels = 'https://{}/ourdevserver/rest/services/LandOwnershipAndInterests/NormalizedParcels/FeatureServer/0/query'.format(portalUrlBase)
    params = {'f': 'json',
              'geometryType': 'esriGeometryPoint',
              'geometry': geom,
              'spatialRel': 'esriSpatialRelIntersects',
              'distance': 0.0,
              'units': 'esriSRUnit_Foot',
              'inSR': 2881,
              'where': '1=1',
              'outFields': 'PARNO',
              'returnGeometry': 'false',
              'returnCountOnly': 'true',
              'token': tok}

    print(json.dumps(params))
    r = requests.post(queryURL_parcels, data = params, verify=False)
    response = json.loads(r.content)
    print(response)

 

 

 

Since the returnCountOnly param is true then we get back all 4million parcels in the layer, expecting only 1 feature in the count/result.

Hopefully someone can spot what I'm missing because I've attempted all combinations of geometry formats.

 

0 Kudos
1 Solution

Accepted Solutions
JamesCrandall
MVP Frequent Contributor

The input geometry attribute is expecting a string of coordinate pairs.  I was simply passing in the geom object of the result from another query/response of the point layer: 

'geometry': geom

 

Simply putting this into a string solves the issue:

'geometry': '{},{}'.format(geom['x'],geom['y'])

View solution in original post

0 Kudos
1 Reply
JamesCrandall
MVP Frequent Contributor

The input geometry attribute is expecting a string of coordinate pairs.  I was simply passing in the geom object of the result from another query/response of the point layer: 

'geometry': geom

 

Simply putting this into a string solves the issue:

'geometry': '{},{}'.format(geom['x'],geom['y'])
0 Kudos