REST Radius Spatial Query

1561
5
Jump to solution
12-17-2019 04:40 AM
ScottWilson2
New Contributor II

Hi, i have created some code which does the following:

1) user clicks on the map (red pin)

2) a circle is created, based on the point in step 1, and queries the feature layer for items within the radius (50 meters (?))

3) results are displayed on map (blue pins)

var x = e.mapPoint.x;
var y = e.mapPoint.y;
var spatial = new SpatialReference({ wkid: 102100, latestWkid: 3857 });
var point = new Point(x, y, spatial);
 

qGeom = new Circle(point,{ 
  "radius": 50,
  "spatialReference":point.spatialReference 
}); 
 
 
// use the circle for the query geometry 
qParcels.geometry = qGeom; 
qParcels.outFields = ["UFRM_BLPU_POINT_ADDRESS"]; 
qParcels.returnGeometry = true;
parcels = queryTask.execute(qParcels, showResults);‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Ok, so all of the above works perfectly client side using the jsapi 3.29.

I now want to take the above functionality and replicate it in the Query Builder.  I've used Chrome developer tools to try and mimic the request, but i don't have the full picture.

Here is what i have so far.  I'm getting an error when setting the Geometry to 'esriGeometryPolygon' 'geometry' parameter is invalid (I assume esriGeometryPolygon is what i should be using as that's what i located in dev tools).  I'm also not sure how i set the circle.

Can someone help me with the combination of settings?

thanks

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Scott,

   OK I did some testing and is seems that a MapServer does not work using distance and a point but a FeatureServer does. So on to your second post. The geometry for the polygon should Not be encoded. and you need to click the Query (POST) instead of the Query (GET) since the query string is so long.

View solution in original post

5 Replies
ScottWilson2
New Contributor II

Looking at the header for the JSAPI query, parsed request looks like this, so geometry is expecting rings (which i presume is my circle):

f: json
where: 
returnGeometry: true
spatialRel: esriSpatialRelIntersects
geometry: {"rings":[[[-475303.63745402906,7507176.940403111],[-475304.29482658487,7507189.483818703],[-475306.259741941,7507201.88980601],[-475309.51067207364,7507214.022442436],[-475314.011999112,7507225.7488002805],[-475319.71440557495,7507236.940403111],[-475326.5554147041,7507247.474633386],[-475334.4600749718,7507257.236075874],[-475343.341781266,7507266.117782169],[-475353.103223754,7507274.022442436],[-475363.63745402906,7507280.863451566],[-475374.82905685995,7507286.565858029],[-475386.5554147041,7507291.067185067],[-475398.6880511309,7507294.318115199],[-475411.09403843695,7507296.283030556],[-475423.63745402906,7507296.940403111],[-475436.18086962117,7507296.283030556],[-475448.5868569272,7507294.318115199],[-475460.71949335403,7507291.067185067],[-475472.44585119816,7507286.565858029],[-475483.63745402906,7507280.863451566],[-475494.17168430414,7507274.022442436],[-475503.93312679214,7507266.117782169],[-475512.81483308633,7507257.236075874],[-475520.71949335403,7507247.474633386],[-475527.56050248316,7507236.940403111],[-475533.26290894614,7507225.7488002805],[-475537.7642359845,7507214.022442436],[-475541.0151661171,7507201.88980601],[-475542.98008147324,7507189.483818703],[-475543.63745402906,7507176.940403111],[-475542.98008147324,7507164.396987519],[-475541.0151661171,7507151.991000213],[-475537.7642359845,7507139.858363787],[-475533.26290894614,7507128.132005942],[-475527.56050248316,7507116.940403111],[-475520.71949335403,7507106.406172836],[-475512.81483308633,7507096.644730348],[-475503.93312679214,7507087.763024054],[-475494.17168430414,7507079.858363787],[-475483.63745402906,7507073.017354657],[-475472.44585119816,7507067.314948194],[-475460.71949335403,7507062.813621156],[-475448.5868569272,7507059.562691024],[-475436.18086962117,7507057.597775667],[-475423.63745402906,7507056.940403111],[-475411.09403843695,7507057.597775667],[-475398.6880511309,7507059.562691024],[-475386.5554147041,7507062.813621156],[-475374.82905685995,7507067.314948194],[-475363.63745402906,7507073.017354657],[-475353.103223754,7507079.858363787],[-475343.341781266,7507087.763024054],[-475334.4600749718,7507096.644730348],[-475326.5554147041,7507106.406172836],[-475319.71440557495,7507116.940403111],[-475314.011999112,7507128.132005942],[-475309.51067207364,7507139.858363787],[-475306.259741941,7507151.991000213],[-475304.29482658487,7507164.396987519],[-475303.63745402906,7507176.940403111],[-475303.63745402906,7507176.940403111]]],"spatialReference":{"wkid":102100,"latestWkid":3857}}
geometryType: esriGeometryPolygon
inSR: 102100
outFields: UFRM_BLPU_POINT_ADDRESS
outSR: 102100‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

URL Encoded

f=json&where=&returnGeometry=true&spatialRel=esriSpatialRelIntersects&geometry=%7B%22rings%22%3A%5B%5B%5B-475303.63745402906%2C7507176.940403111%5D%2C%5B-475304.29482658487%2C7507189.483818703%5D%2C%5B-475306.259741941%2C7507201.88980601%5D%2C%5B-475309.51067207364%2C7507214.022442436%5D%2C%5B-475314.011999112%2C7507225.7488002805%5D%2C%5B-475319.71440557495%2C7507236.940403111%5D%2C%5B-475326.5554147041%2C7507247.474633386%5D%2C%5B-475334.4600749718%2C7507257.236075874%5D%2C%5B-475343.341781266%2C7507266.117782169%5D%2C%5B-475353.103223754%2C7507274.022442436%5D%2C%5B-475363.63745402906%2C7507280.863451566%5D%2C%5B-475374.82905685995%2C7507286.565858029%5D%2C%5B-475386.5554147041%2C7507291.067185067%5D%2C%5B-475398.6880511309%2C7507294.318115199%5D%2C%5B-475411.09403843695%2C7507296.283030556%5D%2C%5B-475423.63745402906%2C7507296.940403111%5D%2C%5B-475436.18086962117%2C7507296.283030556%5D%2C%5B-475448.5868569272%2C7507294.318115199%5D%2C%5B-475460.71949335403%2C7507291.067185067%5D%2C%5B-475472.44585119816%2C7507286.565858029%5D%2C%5B-475483.63745402906%2C7507280.863451566%5D%2C%5B-475494.17168430414%2C7507274.022442436%5D%2C%5B-475503.93312679214%2C7507266.117782169%5D%2C%5B-475512.81483308633%2C7507257.236075874%5D%2C%5B-475520.71949335403%2C7507247.474633386%5D%2C%5B-475527.56050248316%2C7507236.940403111%5D%2C%5B-475533.26290894614%2C7507225.7488002805%5D%2C%5B-475537.7642359845%2C7507214.022442436%5D%2C%5B-475541.0151661171%2C7507201.88980601%5D%2C%5B-475542.98008147324%2C7507189.483818703%5D%2C%5B-475543.63745402906%2C7507176.940403111%5D%2C%5B-475542.98008147324%2C7507164.396987519%5D%2C%5B-475541.0151661171%2C7507151.991000213%5D%2C%5B-475537.7642359845%2C7507139.858363787%5D%2C%5B-475533.26290894614%2C7507128.132005942%5D%2C%5B-475527.56050248316%2C7507116.940403111%5D%2C%5B-475520.71949335403%2C7507106.406172836%5D%2C%5B-475512.81483308633%2C7507096.644730348%5D%2C%5B-475503.93312679214%2C7507087.763024054%5D%2C%5B-475494.17168430414%2C7507079.858363787%5D%2C%5B-475483.63745402906%2C7507073.017354657%5D%2C%5B-475472.44585119816%2C7507067.314948194%5D%2C%5B-475460.71949335403%2C7507062.813621156%5D%2C%5B-475448.5868569272%2C7507059.562691024%5D%2C%5B-475436.18086962117%2C7507057.597775667%5D%2C%5B-475423.63745402906%2C7507056.940403111%5D%2C%5B-475411.09403843695%2C7507057.597775667%5D%2C%5B-475398.6880511309%2C7507059.562691024%5D%2C%5B-475386.5554147041%2C7507062.813621156%5D%2C%5B-475374.82905685995%2C7507067.314948194%5D%2C%5B-475363.63745402906%2C7507073.017354657%5D%2C%5B-475353.103223754%2C7507079.858363787%5D%2C%5B-475343.341781266%2C7507087.763024054%5D%2C%5B-475334.4600749718%2C7507096.644730348%5D%2C%5B-475326.5554147041%2C7507106.406172836%5D%2C%5B-475319.71440557495%2C7507116.940403111%5D%2C%5B-475314.011999112%2C7507128.132005942%5D%2C%5B-475309.51067207364%2C7507139.858363787%5D%2C%5B-475306.259741941%2C7507151.991000213%5D%2C%5B-475304.29482658487%2C7507164.396987519%5D%2C%5B-475303.63745402906%2C7507176.940403111%5D%2C%5B-475303.63745402906%2C7507176.940403111%5D%5D%5D%2C%22spatialReference%22%3A%7B%22wkid%22%3A102100%2C%22latestWkid%22%3A3857%7D%7D&geometryType=esriGeometryPolygon&inSR=102100&outFields=UFRM_BLPU_POINT_ADDRESS&outSR=102100‍‍‍

I have tried taking the URL encoded string and pasting it into the url from my query builder, but this results in a 404.  I have also tried copying just the encoded geometry but that also results in a 404.

Why is the query builder going to a 404 page when i input geometry rings?

Based on a user clicking the map, how do I take the x/y coordinates and create a circle that generates the rings above?

thanks

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Scott,

   In your first post on the query page you have the input Geometry as a coordinate pair (a point) yet you have the geometry type as polygon. Change that to point and your firt post should work.

0 Kudos
ScottWilson2
New Contributor II

Hi Robert, i have tried changing Geometry Type to point and I get No records found.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Scott,

   OK I did some testing and is seems that a MapServer does not work using distance and a point but a FeatureServer does. So on to your second post. The geometry for the polygon should Not be encoded. and you need to click the Query (POST) instead of the Query (GET) since the query string is so long.

ScottWilson2
New Contributor II

Hi Robert, thank you for checking this for me.

Ok, so I have managed to get it working.

1) I am using the FeatureServer instead of the MapServer

2) I am using the POST button rather than GET

3) I've entered raw geometry, no encodeding

4) The Geometry type set to Polygon

The input geometry is now returning the 3 properties contained within the boundary

I've included a print screen of the full request:

0 Kudos