<?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 Re: Survey123 Spatial Analysis/Overlapping polygons in ArcGIS Survey123 Questions</title>
    <link>https://community.esri.com/t5/arcgis-survey123-questions/survey123-spatial-analysis-overlapping-polygons/m-p/1001013#M31056</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;There is no existing function to do this, however, Survey123 does support the custom JS function.&lt;/P&gt;&lt;P&gt;Here are some good resources:&lt;/P&gt;&lt;P&gt;&amp;nbsp;Blog:&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://community.esri.com/t5/arcgis-survey123-blog/extending-survey123-smart-forms-with-custom-js-functions/ba-p/898782" target="_blank" rel="noopener"&gt;https://community.esri.com/t5/arcgis-survey123-blog/extending-survey123-smart-forms-with-custom-js-f...&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Doc:&amp;nbsp;&lt;A href="https://doc.arcgis.com/en/survey123/desktop/create-surveys/pulldatajavascript.htm" target="_blank" rel="noopener nofollow noopener noreferrer"&gt;https://doc.arcgis.com/en/survey123/desktop/create-surveys/pulldatajavascript.htm&lt;/A&gt;&amp;nbsp;(Please pay attention to the known limitations at the end of this doc)&lt;/P&gt;&lt;P&gt;I have also attached a sample XLSform (Please change the feature layer url in the pulldata function) and a Javascript code (Please take the code and save it as .js file, then put the js. file into the scripts folder as described in the documentation).&lt;/P&gt;&lt;P&gt;The following code can do simple overlap detection and returns the count of the existing polygons that are overlapping.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function overlapDetection(geometry, token, featurelayer_url) {
    // If there is no geometry input, output null
    if (!geometry) {
        return "Wait for input geometry.";
    }

    // If the survey is submitted in the webapp, convert the geometry to object
    if (typeof(geometry) != "object") {      
        var geoArray = geometry.split(';');
        geoArray.forEach(ArraytoAA);
        var geoObject = {"rings": [geoArray]};
    } else {
        var geoObject = geometry;
    }

    var geoString = JSON.stringify(geoObject);

    // Change the parameters in the query URL to work with different geometryType, spatialRel, etc.
    // Ref: https://developers.arcgis.com/rest/services-reference/query-feature-service-layer-.htm
    var url = featurelayer_url+"/query?where=1%3D1&amp;amp;geometry="+geoString+"&amp;amp;geometryType=esriGeometryPolygon&amp;amp;spatialRel=esriSpatialRelOverlaps&amp;amp;units=esriSRUnit_Meter&amp;amp;returnCountOnly=true&amp;amp;f=json";

    if (token) {
        url =  url+"&amp;amp;token="+token;
    }

    var xhttp = new XMLHttpRequest();
    xhttp.open("GET", url, false);
    xhttp.send();

    if (xhttp.status!==200) {
        return (xhttp.status);
    } else {
        var responseJSON=JSON.parse(xhttp.responseText)
        if (responseJSON.error) {
            return JSON.stringify(responseJSON.error);
        } else {
            return JSON.stringify(responseJSON.count);
        }
    }
}

function ArraytoAA(item,index,array) {
    var coord = item.split(' ').map(Number)
    array[index] = coord;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Thanks,&lt;/P&gt;&lt;P&gt;Ruth&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 10 Dec 2020 15:40:00 GMT</pubDate>
    <dc:creator>Ruth_JiatengXu</dc:creator>
    <dc:date>2020-12-10T15:40:00Z</dc:date>
    <item>
      <title>Survey123 Spatial Analysis/Overlapping polygons</title>
      <link>https://community.esri.com/t5/arcgis-survey123-questions/survey123-spatial-analysis-overlapping-polygons/m-p/839216#M20421</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Would anybody know whether there is way within &lt;STRONG&gt;Survey123&lt;/STRONG&gt; to check whether a new polygon being collected via a &lt;STRONG&gt;geoshape&lt;/STRONG&gt; question overlaps an existing polygon/record collected in previous surveys? So, some kind of constraint for &lt;STRONG&gt;spatial functionality&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;Many thanks for any suggestions.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Nov 2020 10:15:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-survey123-questions/survey123-spatial-analysis-overlapping-polygons/m-p/839216#M20421</guid>
      <dc:creator>CherylWheeler2</dc:creator>
      <dc:date>2020-11-10T10:15:59Z</dc:date>
    </item>
    <item>
      <title>Re: Survey123 Spatial Analysis/Overlapping polygons</title>
      <link>https://community.esri.com/t5/arcgis-survey123-questions/survey123-spatial-analysis-overlapping-polygons/m-p/1001013#M31056</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;There is no existing function to do this, however, Survey123 does support the custom JS function.&lt;/P&gt;&lt;P&gt;Here are some good resources:&lt;/P&gt;&lt;P&gt;&amp;nbsp;Blog:&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://community.esri.com/t5/arcgis-survey123-blog/extending-survey123-smart-forms-with-custom-js-functions/ba-p/898782" target="_blank" rel="noopener"&gt;https://community.esri.com/t5/arcgis-survey123-blog/extending-survey123-smart-forms-with-custom-js-f...&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Doc:&amp;nbsp;&lt;A href="https://doc.arcgis.com/en/survey123/desktop/create-surveys/pulldatajavascript.htm" target="_blank" rel="noopener nofollow noopener noreferrer"&gt;https://doc.arcgis.com/en/survey123/desktop/create-surveys/pulldatajavascript.htm&lt;/A&gt;&amp;nbsp;(Please pay attention to the known limitations at the end of this doc)&lt;/P&gt;&lt;P&gt;I have also attached a sample XLSform (Please change the feature layer url in the pulldata function) and a Javascript code (Please take the code and save it as .js file, then put the js. file into the scripts folder as described in the documentation).&lt;/P&gt;&lt;P&gt;The following code can do simple overlap detection and returns the count of the existing polygons that are overlapping.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function overlapDetection(geometry, token, featurelayer_url) {
    // If there is no geometry input, output null
    if (!geometry) {
        return "Wait for input geometry.";
    }

    // If the survey is submitted in the webapp, convert the geometry to object
    if (typeof(geometry) != "object") {      
        var geoArray = geometry.split(';');
        geoArray.forEach(ArraytoAA);
        var geoObject = {"rings": [geoArray]};
    } else {
        var geoObject = geometry;
    }

    var geoString = JSON.stringify(geoObject);

    // Change the parameters in the query URL to work with different geometryType, spatialRel, etc.
    // Ref: https://developers.arcgis.com/rest/services-reference/query-feature-service-layer-.htm
    var url = featurelayer_url+"/query?where=1%3D1&amp;amp;geometry="+geoString+"&amp;amp;geometryType=esriGeometryPolygon&amp;amp;spatialRel=esriSpatialRelOverlaps&amp;amp;units=esriSRUnit_Meter&amp;amp;returnCountOnly=true&amp;amp;f=json";

    if (token) {
        url =  url+"&amp;amp;token="+token;
    }

    var xhttp = new XMLHttpRequest();
    xhttp.open("GET", url, false);
    xhttp.send();

    if (xhttp.status!==200) {
        return (xhttp.status);
    } else {
        var responseJSON=JSON.parse(xhttp.responseText)
        if (responseJSON.error) {
            return JSON.stringify(responseJSON.error);
        } else {
            return JSON.stringify(responseJSON.count);
        }
    }
}

function ArraytoAA(item,index,array) {
    var coord = item.split(' ').map(Number)
    array[index] = coord;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Thanks,&lt;/P&gt;&lt;P&gt;Ruth&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Dec 2020 15:40:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-survey123-questions/survey123-spatial-analysis-overlapping-polygons/m-p/1001013#M31056</guid>
      <dc:creator>Ruth_JiatengXu</dc:creator>
      <dc:date>2020-12-10T15:40:00Z</dc:date>
    </item>
    <item>
      <title>Re: Survey123 Spatial Analysis/Overlapping polygons</title>
      <link>https://community.esri.com/t5/arcgis-survey123-questions/survey123-spatial-analysis-overlapping-polygons/m-p/1001685#M31104</link>
      <description>&lt;P&gt;Thank you very much &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/216203"&gt;@Ruth_JiatengXu&lt;/a&gt;&amp;nbsp;Ruth for your reply. I will experiment with your ideas. I really appreciate your response.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Nov 2020 10:12:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-survey123-questions/survey123-spatial-analysis-overlapping-polygons/m-p/1001685#M31104</guid>
      <dc:creator>CherylWheeler2</dc:creator>
      <dc:date>2020-11-16T10:12:45Z</dc:date>
    </item>
    <item>
      <title>Re: Survey123 Spatial Analysis/Overlapping polygons</title>
      <link>https://community.esri.com/t5/arcgis-survey123-questions/survey123-spatial-analysis-overlapping-polygons/m-p/1005742#M31345</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/221268"&gt;@CherylWheeler2&lt;/a&gt;,&amp;nbsp;&lt;/P&gt;&lt;P&gt;On top of what Ruth suggests another workflow would be to use the Search() appearance which we currently have support for in our 3.12 beta builds.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The Search() appearance lets your query existing Feature Services to see if there is a spatial overlap.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please check out our &lt;A href="https://earlyadopter.esri.com/project/article/item.html?cap=e69ef91f45744b98882c651f7b518eb7&amp;amp;arttypeid={5a8e51ed-4a87-43fe-a67d-2b7829af130f}&amp;amp;artid={F91C2CD4-2A42-4CA3-AC7D-755A5C34F811}" target="_self"&gt;Early Adopter Community&lt;/A&gt; for more information on using the Search() appearance in your survey.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Zach&lt;/P&gt;</description>
      <pubDate>Tue, 01 Dec 2020 02:30:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-survey123-questions/survey123-spatial-analysis-overlapping-polygons/m-p/1005742#M31345</guid>
      <dc:creator>ZacharySutherby</dc:creator>
      <dc:date>2020-12-01T02:30:16Z</dc:date>
    </item>
    <item>
      <title>Re: Survey123 Spatial Analysis/Overlapping polygons</title>
      <link>https://community.esri.com/t5/arcgis-survey123-questions/survey123-spatial-analysis-overlapping-polygons/m-p/1008005#M31515</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/216203"&gt;@Ruth_JiatengXu&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;Your response above was incredibly helpful and I have managed to implement the JavaScript function above into my survey, however it is only able to detect an overlap when I am drawing polygons with straight edges e.g. squares, rectangles, triangles.&lt;/P&gt;&lt;P&gt;When I draw polygons by free-hand or that are circle (any polygon with a curved edges), it returns the error:&lt;/P&gt;&lt;P&gt;@javascript error:ReferenceError: xmlhttp is not defined in overlapDetection.js:overlapDetection&lt;/P&gt;&lt;P&gt;Which is returned at the line of code:&lt;/P&gt;&lt;P&gt;if (xhttp.status!==200) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return (xmlhttp.status);&lt;/P&gt;&lt;P&gt;When I changed xmlhttp.status to xhttp.status, I got a 404 error: “page not found” so I believe it’s a problem with the query URL.&lt;/P&gt;&lt;P&gt;Do you know why this might be and is there a work around?&lt;/P&gt;&lt;P&gt;Many thanks,&lt;/P&gt;&lt;P&gt;Izzy&lt;/P&gt;</description>
      <pubDate>Wed, 09 Dec 2020 11:23:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-survey123-questions/survey123-spatial-analysis-overlapping-polygons/m-p/1008005#M31515</guid>
      <dc:creator>IzzyMcLees</dc:creator>
      <dc:date>2020-12-09T11:23:46Z</dc:date>
    </item>
  </channel>
</rss>

