<?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: Geoshape Centroid in ArcGIS Survey123 Questions</title>
    <link>https://community.esri.com/t5/arcgis-survey123-questions/geoshape-centroid/m-p/1399874#M55690</link>
    <description>&lt;P&gt;Hello,&lt;BR /&gt;&lt;BR /&gt;I was curious if anyone happened to figure out how to get the lat/long of the centroid from a geoshape that is created in Survey123?&amp;nbsp; This is something that would be quite helpful.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Fri, 22 Mar 2024 22:36:44 GMT</pubDate>
    <dc:creator>JacobPearse</dc:creator>
    <dc:date>2024-03-22T22:36:44Z</dc:date>
    <item>
      <title>Geoshape Centroid</title>
      <link>https://community.esri.com/t5/arcgis-survey123-questions/geoshape-centroid/m-p/1158287#M41654</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am looking to return the lat and long of a &lt;STRONG&gt;geoshape centroid&amp;nbsp;&lt;/STRONG&gt;from my survey form. Essentially I want to pass the centroid lat and long to what3words for reverse geocoding. Then the what3words result would populate a&amp;nbsp; note on the survey. I have seen&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/rest/analysis/api-reference/find-centroids.htm" target="_blank"&gt;https://developers.arcgis.com/rest/analysis/api-reference/find-centroids.htm&amp;nbsp;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;but am not really sure how to implement it. Would somebody be able to point me in the right direction, or able to share some sample Javascript to accomplish this please?&lt;/P&gt;&lt;P&gt;Many thanks&lt;/P&gt;</description>
      <pubDate>Mon, 28 Mar 2022 09:23:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-survey123-questions/geoshape-centroid/m-p/1158287#M41654</guid>
      <dc:creator>CherylWheeler11</dc:creator>
      <dc:date>2022-03-28T09:23:46Z</dc:date>
    </item>
    <item>
      <title>Re: Geoshape Centroid</title>
      <link>https://community.esri.com/t5/arcgis-survey123-questions/geoshape-centroid/m-p/1226075#M45637</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I was wondering if anyone has found a possible workaround for that? I am trying to find a way to generate the centroid coordinates of a geoshape created in Survey123 field app. Any ideas including the pulldata("@javascript"&amp;nbsp;custom query would be super useful.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Oct 2022 09:16:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-survey123-questions/geoshape-centroid/m-p/1226075#M45637</guid>
      <dc:creator>DimiKPT</dc:creator>
      <dc:date>2022-10-27T09:16:12Z</dc:date>
    </item>
    <item>
      <title>Re: Geoshape Centroid</title>
      <link>https://community.esri.com/t5/arcgis-survey123-questions/geoshape-centroid/m-p/1399874#M55690</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;&lt;BR /&gt;I was curious if anyone happened to figure out how to get the lat/long of the centroid from a geoshape that is created in Survey123?&amp;nbsp; This is something that would be quite helpful.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 22 Mar 2024 22:36:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-survey123-questions/geoshape-centroid/m-p/1399874#M55690</guid>
      <dc:creator>JacobPearse</dc:creator>
      <dc:date>2024-03-22T22:36:44Z</dc:date>
    </item>
    <item>
      <title>Re: Geoshape Centroid</title>
      <link>https://community.esri.com/t5/arcgis-survey123-questions/geoshape-centroid/m-p/1596203#M61702</link>
      <description>&lt;P&gt;Hello, I figured something out with a javascript. If this solution is an answer somewhere else, let me know.&lt;/P&gt;&lt;P&gt;In Survey123, it's not directly possible to calculate the centroid of a polygon drawn using a GeoShape question. However, there is a way to get an approximate centroid by using a custom JavaScript approach. Here's the solution I implemented:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;1. Using a Custom JavaScript File:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;- A JavaScript file is used to extract the coordinates of the polygon (in GeoJSON format) and calculate the centroid by averaging the X (longitude) and Y (latitude) coordinates of the points that make up the polygon.&lt;/P&gt;&lt;P&gt;The centroid.js file contains two separate functions:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;getCentroidX: to calculate the X (longitude) coordinate of the centroid.&lt;/LI&gt;&lt;LI&gt;getCentroidY: to calculate the Y (latitude) coordinate of the centroid.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Here’s the JavaScript code used to calculate the centroid:&lt;/P&gt;&lt;P&gt;// Function to extract coordinates from a GeoJSON geometry&lt;BR /&gt;function extractCoordinates(geometry) {&lt;BR /&gt;if (geometry &amp;amp;&amp;amp; geometry.rings &amp;amp;&amp;amp; geometry.rings.length &amp;gt; 0) {&lt;BR /&gt;return geometry.rings[0].map(function(point) {&lt;BR /&gt;return [point[0], point[1]]; // Extracting only longitude (X) and latitude (Y)&lt;BR /&gt;});&lt;BR /&gt;}&lt;BR /&gt;return [];&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;// Function to calculate the Centroid X (longitude)&lt;BR /&gt;function getCentroidX(geometry) {&lt;BR /&gt;let coordinates = extractCoordinates(geometry);&lt;BR /&gt;let sumX = coordinates.reduce(function(sum, coord) { return sum + coord[0]; }, 0);&lt;BR /&gt;return sumX / coordinates.length; // Average of the X coordinates&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;// Function to calculate the Centroid Y (latitude)&lt;BR /&gt;function getCentroidY(geometry) {&lt;BR /&gt;let coordinates = extractCoordinates(geometry);&lt;BR /&gt;let sumY = coordinates.reduce(function(sum, coord) { return sum + coord[1]; }, 0);&lt;BR /&gt;return sumY / coordinates.length; // Average of the Y coordinates&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;2. Configuring the Form in Survey123:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;-&amp;nbsp;&amp;nbsp; GeoShape: Allows the user to draw a polygon.&lt;/P&gt;&lt;P&gt;- poly_wkt: Stores the geometry as a WKT string (use string(${polygon}) to convert the GeoShape into a string).&lt;/P&gt;&lt;P&gt;-&amp;nbsp; centroid_x and centroid_y: These fields calculate the X and Y coordinates of the centroid using pulldata() to call the JavaScript file. The pulldata() function is used as follows:&lt;/P&gt;&lt;UL&gt;&lt;UL&gt;&lt;LI&gt;number(pulldata("@javascript", "centroid.js", "getCentroidX", ${polygon}))&lt;/LI&gt;&lt;LI&gt;number(pulldata("@javascript", "centroid.js", "getCentroidY", ${polygon}))&lt;/LI&gt;&lt;/UL&gt;&lt;/UL&gt;&lt;P&gt;&lt;STRONG&gt;3. Creating a GeoPoint in a Repeat:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;-To store the centroid geometry in a spatial layer, I used a GeoPoint inside a repeat.&lt;/P&gt;&lt;P&gt;-I used concat(${centroid_y}, ' ', ${centroid_x}) to combine the centroid coordinates and create a GeoPoint geometry in the form.&lt;/P&gt;&lt;P&gt;-This allows storing the centroid as a GeoPoint in the map layer with the calculated coordinates.&lt;/P&gt;&lt;P&gt;-Don't forget to add&amp;nbsp;calculationMode=always in&amp;nbsp;bind::esri:parameters&lt;/P&gt;&lt;P&gt;Here’s a quick look at the table&amp;nbsp;structure in Excel:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Mar 2025 16:51:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-survey123-questions/geoshape-centroid/m-p/1596203#M61702</guid>
      <dc:creator>estelleseremes</dc:creator>
      <dc:date>2025-03-17T16:51:15Z</dc:date>
    </item>
    <item>
      <title>Re: Geoshape Centroid</title>
      <link>https://community.esri.com/t5/arcgis-survey123-questions/geoshape-centroid/m-p/1643603#M63864</link>
      <description>&lt;P&gt;Exactly what I was looking for given that there is no pulldata(@geoshape) alowing that operation !&lt;BR /&gt;Thank you a lot&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/791120"&gt;@estelleseremes&lt;/a&gt;&amp;nbsp;for sharing.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Aug 2025 08:37:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-survey123-questions/geoshape-centroid/m-p/1643603#M63864</guid>
      <dc:creator>Chris_976</dc:creator>
      <dc:date>2025-08-20T08:37:52Z</dc:date>
    </item>
    <item>
      <title>Re: Geoshape Centroid</title>
      <link>https://community.esri.com/t5/arcgis-survey123-questions/geoshape-centroid/m-p/1648416#M64065</link>
      <description>&lt;P&gt;I tried using the proposed script, and it always returned "empty" coordinates.&lt;BR /&gt;I realized that the wkt call wasn't understood within the script, so I needed to add a parsing step to convert the JSON string that Survey123 sends to a JavaScript object within your script.&lt;/P&gt;&lt;P&gt;// Function to extract coordinates from a GeoJSON geometry&lt;BR /&gt;function extractCoordinates(geometry) {&lt;BR /&gt;// AQUI É O PONTO CRÍTICO: CONVERTER A STRING PARA UM OBJETO JSON&lt;BR /&gt;let geojson = JSON.parse(geometry);&lt;/P&gt;&lt;P&gt;if (geojson &amp;amp;&amp;amp; geojson.rings &amp;amp;&amp;amp; geojson.rings.length &amp;gt; 0) {&lt;BR /&gt;return geojson.rings[0].map(function(point) {&lt;BR /&gt;return [point[0], point[1]]; // Extracting only longitude (X) and latitude (Y)&lt;BR /&gt;});&lt;BR /&gt;}&lt;BR /&gt;return [];&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;// Function to calculate the Centroid X (longitude)&lt;BR /&gt;function getCentroidX(geometry) {&lt;BR /&gt;let coordinates = extractCoordinates(geometry);&lt;BR /&gt;if (coordinates.length === 0) {&lt;BR /&gt;return NaN; // Retorne NaN ou 0 para evitar divisão por zero&lt;BR /&gt;}&lt;BR /&gt;let sumX = coordinates.reduce(function(sum, coord) {&lt;BR /&gt;return sum + coord[0];&lt;BR /&gt;}, 0);&lt;BR /&gt;return sumX / coordinates.length; // Average of the X coordinates&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;// Function to calculate the Centroid Y (latitude)&lt;BR /&gt;function getCentroidY(geometry) {&lt;BR /&gt;let coordinates = extractCoordinates(geometry);&lt;BR /&gt;if (coordinates.length === 0) {&lt;BR /&gt;return NaN; // Retorne NaN ou 0 para evitar divisão por zero&lt;BR /&gt;}&lt;BR /&gt;let sumY = coordinates.reduce(function(sum, coord) {&lt;BR /&gt;return sum + coord[1];&lt;BR /&gt;}, 0);&lt;BR /&gt;return sumY / coordinates.length; // Average of the Y coordinates&lt;BR /&gt;}&lt;/P&gt;</description>
      <pubDate>Sat, 06 Sep 2025 22:25:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-survey123-questions/geoshape-centroid/m-p/1648416#M64065</guid>
      <dc:creator>RicardoCantarelli</dc:creator>
      <dc:date>2025-09-06T22:25:08Z</dc:date>
    </item>
  </channel>
</rss>

