<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Extracting an intersecting polygon from S123 Json response in ArcGIS Survey123 Questions</title>
    <link>https://community.esri.com/t5/arcgis-survey123-questions/extracting-an-intersecting-polygon-from-s123-json/m-p/1211960#M44810</link>
    <description>&lt;P&gt;Greetings,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd like to use a Survey123 form to extract a polygon from a hosted feature layer that intersects with the location of the submitted survey. A scenario would be " Given a total number of 5 districts when a surveyor opens the survey in any of them (with a geo-point question capturing his location), the geometry of this district gets drawn in a following geo-shape question".&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I'm not a JS expert, but I edited the JS samples of the Survey123 connect templates and came up with the below code, but I can't get it to work. The JS function returns endless object (${element[1]} ${element[0]})&lt;/P&gt;&lt;P&gt;I understand that I'm not specific, but can anyone point out what is incorrect in the below code?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;// Query a feature layer and returns the feature that intersects the location&lt;/P&gt;&lt;P&gt;function featureByLocation(layerURL, location, token) {&lt;/P&gt;&lt;P&gt;// Output value. Initially set to an empty string (XLSForm null)&lt;/P&gt;&lt;P&gt;let outValue = "";&lt;/P&gt;&lt;P&gt;let outRing = [];&lt;/P&gt;&lt;P&gt;// Check to make sure both layerURL and location are provided&lt;/P&gt;&lt;P&gt;if (layerURL == null || layerURL === "" || location == null || location === "") {&lt;/P&gt;&lt;P&gt;// The function can't go forward; exit with the empty value&lt;/P&gt;&lt;P&gt;return location;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;// The coordinates will come in as `&amp;lt;lat&amp;gt; &amp;lt;lon&amp;gt; &amp;lt;alt&amp;gt; &amp;lt;acc&amp;gt;`.&lt;/P&gt;&lt;P&gt;// We need &amp;lt;lon&amp;gt;,&amp;lt;lat&amp;gt; for the query&lt;/P&gt;&lt;P&gt;// Note that I'm using the relatively new ` ` string that lets me place variables ${var}&lt;/P&gt;&lt;P&gt;let coordsArray = location.split(" ");&lt;/P&gt;&lt;P&gt;let coords = `${coordsArray[1]},${coordsArray[0]}`;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;// Set up query parameters&lt;/P&gt;&lt;P&gt;let f = "f=json";&lt;/P&gt;&lt;P&gt;let returnGeometry = "returnGeometry=true";&lt;/P&gt;&lt;P&gt;let geometry = `geometry=${coords}`;&lt;/P&gt;&lt;P&gt;let geometryType = "geometryType=esriGeometryPoint";&lt;/P&gt;&lt;P&gt;let inSR = "inSR=4326";&lt;/P&gt;&lt;P&gt;let spatialRel = "spatialRel=esriSpatialRelIntersects";&lt;/P&gt;&lt;P&gt;let outFields = "outFields=*";&lt;/P&gt;&lt;P&gt;let returnCount = "returnCount=1";&lt;/P&gt;&lt;P&gt;let parameters = [f,returnGeometry, geometry,geometryType,inSR,spatialRel,outFields,,returnCount].join("&amp;amp;");&lt;/P&gt;&lt;P&gt;if (token) {&lt;/P&gt;&lt;P&gt;parameters = parameters + `&amp;amp;token=${token}`;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;let url = `${layerURL}/query?${parameters}`;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;// Create the request object&lt;/P&gt;&lt;P&gt;let xhr = new XMLHttpRequest();&lt;/P&gt;&lt;P&gt;// Make the request. Note the 3rd parameter, which makes this a synchronous request&lt;/P&gt;&lt;P&gt;xhr.open("GET", url, false);&lt;/P&gt;&lt;P&gt;xhr.send();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;// Process the result&lt;/P&gt;&lt;P&gt;if (xhr.readyState === xhr.DONE) {&lt;/P&gt;&lt;P&gt;if (xhr.status !== 200) {&lt;/P&gt;&lt;P&gt;// The http request did not succeed&lt;/P&gt;&lt;P&gt;return "bad request: " + url&lt;/P&gt;&lt;P&gt;} else {&lt;/P&gt;&lt;P&gt;// Parse the response into an object&lt;/P&gt;&lt;P&gt;let response = JSON.parse(xhr.responseText);&lt;/P&gt;&lt;P&gt;if (response.error) {&lt;/P&gt;&lt;P&gt;// There was a problem with the query&lt;/P&gt;&lt;P&gt;} else {&lt;/P&gt;&lt;P&gt;if (response.features[0]) {&lt;/P&gt;&lt;P&gt;let ring = response["features"][0]["geometry"]["rings"][0];&lt;/P&gt;&lt;P&gt;ring.forEach(element =&amp;gt; outRing.push('${element[1]} ${element[0]}'));&lt;/P&gt;&lt;P&gt;outValue = outRing.join(";");&lt;/P&gt;&lt;P&gt;} else {&lt;/P&gt;&lt;P&gt;// No features found&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;return outValue;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;</description>
    <pubDate>Tue, 13 Sep 2022 12:53:54 GMT</pubDate>
    <dc:creator>AhmedShehata3</dc:creator>
    <dc:date>2022-09-13T12:53:54Z</dc:date>
    <item>
      <title>Extracting an intersecting polygon from S123 Json response</title>
      <link>https://community.esri.com/t5/arcgis-survey123-questions/extracting-an-intersecting-polygon-from-s123-json/m-p/1211960#M44810</link>
      <description>&lt;P&gt;Greetings,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd like to use a Survey123 form to extract a polygon from a hosted feature layer that intersects with the location of the submitted survey. A scenario would be " Given a total number of 5 districts when a surveyor opens the survey in any of them (with a geo-point question capturing his location), the geometry of this district gets drawn in a following geo-shape question".&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I'm not a JS expert, but I edited the JS samples of the Survey123 connect templates and came up with the below code, but I can't get it to work. The JS function returns endless object (${element[1]} ${element[0]})&lt;/P&gt;&lt;P&gt;I understand that I'm not specific, but can anyone point out what is incorrect in the below code?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;// Query a feature layer and returns the feature that intersects the location&lt;/P&gt;&lt;P&gt;function featureByLocation(layerURL, location, token) {&lt;/P&gt;&lt;P&gt;// Output value. Initially set to an empty string (XLSForm null)&lt;/P&gt;&lt;P&gt;let outValue = "";&lt;/P&gt;&lt;P&gt;let outRing = [];&lt;/P&gt;&lt;P&gt;// Check to make sure both layerURL and location are provided&lt;/P&gt;&lt;P&gt;if (layerURL == null || layerURL === "" || location == null || location === "") {&lt;/P&gt;&lt;P&gt;// The function can't go forward; exit with the empty value&lt;/P&gt;&lt;P&gt;return location;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;// The coordinates will come in as `&amp;lt;lat&amp;gt; &amp;lt;lon&amp;gt; &amp;lt;alt&amp;gt; &amp;lt;acc&amp;gt;`.&lt;/P&gt;&lt;P&gt;// We need &amp;lt;lon&amp;gt;,&amp;lt;lat&amp;gt; for the query&lt;/P&gt;&lt;P&gt;// Note that I'm using the relatively new ` ` string that lets me place variables ${var}&lt;/P&gt;&lt;P&gt;let coordsArray = location.split(" ");&lt;/P&gt;&lt;P&gt;let coords = `${coordsArray[1]},${coordsArray[0]}`;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;// Set up query parameters&lt;/P&gt;&lt;P&gt;let f = "f=json";&lt;/P&gt;&lt;P&gt;let returnGeometry = "returnGeometry=true";&lt;/P&gt;&lt;P&gt;let geometry = `geometry=${coords}`;&lt;/P&gt;&lt;P&gt;let geometryType = "geometryType=esriGeometryPoint";&lt;/P&gt;&lt;P&gt;let inSR = "inSR=4326";&lt;/P&gt;&lt;P&gt;let spatialRel = "spatialRel=esriSpatialRelIntersects";&lt;/P&gt;&lt;P&gt;let outFields = "outFields=*";&lt;/P&gt;&lt;P&gt;let returnCount = "returnCount=1";&lt;/P&gt;&lt;P&gt;let parameters = [f,returnGeometry, geometry,geometryType,inSR,spatialRel,outFields,,returnCount].join("&amp;amp;");&lt;/P&gt;&lt;P&gt;if (token) {&lt;/P&gt;&lt;P&gt;parameters = parameters + `&amp;amp;token=${token}`;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;let url = `${layerURL}/query?${parameters}`;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;// Create the request object&lt;/P&gt;&lt;P&gt;let xhr = new XMLHttpRequest();&lt;/P&gt;&lt;P&gt;// Make the request. Note the 3rd parameter, which makes this a synchronous request&lt;/P&gt;&lt;P&gt;xhr.open("GET", url, false);&lt;/P&gt;&lt;P&gt;xhr.send();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;// Process the result&lt;/P&gt;&lt;P&gt;if (xhr.readyState === xhr.DONE) {&lt;/P&gt;&lt;P&gt;if (xhr.status !== 200) {&lt;/P&gt;&lt;P&gt;// The http request did not succeed&lt;/P&gt;&lt;P&gt;return "bad request: " + url&lt;/P&gt;&lt;P&gt;} else {&lt;/P&gt;&lt;P&gt;// Parse the response into an object&lt;/P&gt;&lt;P&gt;let response = JSON.parse(xhr.responseText);&lt;/P&gt;&lt;P&gt;if (response.error) {&lt;/P&gt;&lt;P&gt;// There was a problem with the query&lt;/P&gt;&lt;P&gt;} else {&lt;/P&gt;&lt;P&gt;if (response.features[0]) {&lt;/P&gt;&lt;P&gt;let ring = response["features"][0]["geometry"]["rings"][0];&lt;/P&gt;&lt;P&gt;ring.forEach(element =&amp;gt; outRing.push('${element[1]} ${element[0]}'));&lt;/P&gt;&lt;P&gt;outValue = outRing.join(";");&lt;/P&gt;&lt;P&gt;} else {&lt;/P&gt;&lt;P&gt;// No features found&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;return outValue;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2022 12:53:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-survey123-questions/extracting-an-intersecting-polygon-from-s123-json/m-p/1211960#M44810</guid>
      <dc:creator>AhmedShehata3</dc:creator>
      <dc:date>2022-09-13T12:53:54Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting an intersecting polygon from S123 Json response</title>
      <link>https://community.esri.com/t5/arcgis-survey123-questions/extracting-an-intersecting-polygon-from-s123-json/m-p/1226522#M45675</link>
      <description>&lt;P&gt;Hi Ahmed&lt;/P&gt;&lt;P&gt;do you find a solution ?&lt;/P&gt;&lt;P&gt;Thinks&amp;nbsp;&lt;/P&gt;&lt;P&gt;Julien&lt;/P&gt;</description>
      <pubDate>Fri, 28 Oct 2022 09:05:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-survey123-questions/extracting-an-intersecting-polygon-from-s123-json/m-p/1226522#M45675</guid>
      <dc:creator>chargeetudeti</dc:creator>
      <dc:date>2022-10-28T09:05:26Z</dc:date>
    </item>
  </channel>
</rss>

