# ODK code only sometime converts to accurate polygons on maps, but not always?

**URL:** <https://forum.getodk.org/t/odk-code-only-sometime-converts-to-accurate-polygons-on-maps-but-not-always/35346>\
**Category:** Support\
**Created:** [October 11, 2021, 12:06pm UTC](https://forum.getodk.org/t/odk-code-only-sometime-converts-to-accurate-polygons-on-maps-but-not-always/35346 "2021-10-11T12:06:37Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![davidbaines](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/davidbaines/32/7585_2.png) [@davidbaines](https://forum.getodk.org/u/davidbaines)\
**Post date:** [October 11, 2021, 12:06pm UTC](https://forum.getodk.org/t/odk-code-only-sometime-converts-to-accurate-polygons-on-maps-but-not-always/35346/1 "2021-10-11T12:06:38Z")

</div>

Hello ODK Forum,  
Attached is some data recently collected through ODK forms and stored on ONA. We collected data from 56 sites in Mali, including recording their perimeters with GPS. The “Map” functionality of ONA shows the location of these sites, except for 14 of the sites – where the location is unclear.

Please see the excel attachment called: ODK\_Forum\_Mali\_Data\_GPS\_Question  
Please see the worksheet called: “group\_survey\_group\_gps\_geopoint”.  
In Column L called “\_parent\_index” (highlighted in yellow) please filter on: 10, 16, 27, 26, 29, 33, 36, 37, 40, 42, 44, 46, 50 and 55.  
These are the 14 sites for which the mapping has not worked.  
You can see that their corresponding longitude, latitude and altitude (etc.) coordinates appear to have got a bit mixed up.

Please see the worksheet called: “Details\_Confirmed”.  
Here I have listed the details of the different tablets involved in collecting the data.

Would you be able to advise on:

- Why did 14/56 sites not record the GPS perimeter successfully?

The following is the response which I received from ONA to this question:

“Hello David,  
the two function that are not working well are one for latitude and longitude if(${index}=0,${latstr},substring-after(${latstr}, ';')) and selected-at(${geoshape},${index}\*3+1)  
I am not sure why it is working fine to most records and it fails in some records by pulling wrong data from geoshape polygon points.  
I recommend you ask the question on ODK Forum and attach the form by highlighting the two functions since sometimes it pulls altitude in stead of latitude.  
We are not very sure why this happens but what we can confirm from our end is that the data from data collectors are coming in in the correct format.  
A workaround for now is exporting data from Ona and identify those sites that have incorrect data and clean it manually in Excel.  
Regards,”

I have highlighted the two formula in red in the worksheet called “ref\_survey” in cells S73 and S74.

Thank you in advance for your interest, time and support.  
Very best wishes,  
David Baines  
[ODK\_Forum\_Mali\_Data\_GPS\_Question.xlsx](https://forum.getodk.org/uploads/short-url/AiicWaIa8zA0YUNlcIR2MTwu9ME.xlsx) (269.2 KB)

---

<div class="post-metadata">

**Author:** ![mathieubossaert](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/mathieubossaert/32/6131_2.png) [@mathieubossaert](https://forum.getodk.org/u/mathieubossaert)\
**Post date:** [October 13, 2021, 11:38am UTC](https://forum.getodk.org/t/odk-code-only-sometime-converts-to-accurate-polygons-on-maps-but-not-always/35346/2 "2021-10-13T11:38:31Z")

</div>

OK this is not a solution, but an explanation. Looking at the geometry definition, I observed that the "not working" ones do have a space character following the semicolon.

_[edit] removed the link to an old error wich may be confusing [/edit]_

---

<div class="post-metadata">

**Author:** ![davidbaines](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/davidbaines/32/7585_2.png) [@davidbaines](https://forum.getodk.org/u/davidbaines)\
**Post date:** [October 14, 2021, 1:02pm UTC](https://forum.getodk.org/t/odk-code-only-sometime-converts-to-accurate-polygons-on-maps-but-not-always/35346/3 "2021-10-14T13:02:25Z")

</div>

Hello Mathieu,  
Thank you for your message (and link). Indeed you are correct, the "not working" ones do display a space character after the semicolon. Although this does sometimes correspond to shorter length strings, it is not exclusive i.e. there are some longer length strings that also are "not working" and also display a space character after the semicolon.  
Either way, is there code which we could include into the ODK form which will always 'remove' space characters after a semicolon?  
Thank you and very best wishes,  
David

---

<div class="post-metadata">

**Author:** ![mathieubossaert](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/mathieubossaert/32/6131_2.png) [@mathieubossaert](https://forum.getodk.org/u/mathieubossaert)\
**Post date:** [October 14, 2021, 1:08pm UTC](https://forum.getodk.org/t/odk-code-only-sometime-converts-to-accurate-polygons-on-maps-but-not-always/35346/4 "2021-10-14T13:08:56Z")

</div>

> [@davidbaines](#):
>
> Although this does sometimes correspond to shorter length strings, it is not exclusive

yes you are right 😉

---

<div class="post-metadata">

**Author:** ![mathieubossaert](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/mathieubossaert/32/6131_2.png) [@mathieubossaert](https://forum.getodk.org/u/mathieubossaert)\
**Post date:** [October 14, 2021, 4:05pm UTC](https://forum.getodk.org/t/odk-code-only-sometime-converts-to-accurate-polygons-on-maps-but-not-always/35346/5 "2021-10-14T16:05:05Z")

</div>

I just post a new version of the sample geoshp2wkt xlsform here :

> [@ODK geoshape/geotrace/geopoint to WKT](https://forum.getodk.org/t/odk-geoshape-geotrace-geopoint-to-wkt/21062/17):
>
> Thanks to @Xiphware explanations here : I had a test to handle cases when geo strings contains '; ' as separator instead of the only semicolon. This problem occurs sometimes and @davidbaines faced it here : In such cases, point can be considered as a space-separated list of values with one more space and one more column index. [geoshape2wkt.xls](https://forum.getodk.org/uploads/short-url/3PIuAQdMai2wt1aqGqQWSzyaX8O.xls) (8 KB)

You should just have to adapt it it in your form. Please let me know if it is ok for you.

I tried it with both ";" and "; " separated geoshapes and it works fine 😉

---

<div class="post-metadata">

**Author:** ![davidbaines](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/davidbaines/32/7585_2.png) [@davidbaines](https://forum.getodk.org/u/davidbaines)\
**Post date:** [October 18, 2021, 9:38am UTC](https://forum.getodk.org/t/odk-code-only-sometime-converts-to-accurate-polygons-on-maps-but-not-always/35346/6 "2021-10-18T09:38:12Z")

</div>

Good Morning Mathieu,  
Thank you so much. I will update our ODK forms accordingly. We will test and let you know how they work. Thank you again.

---

<div class="post-metadata">

**Author:** ![davidbaines](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/davidbaines/32/7585_2.png) [@davidbaines](https://forum.getodk.org/u/davidbaines)\
**Post date:** [November 2, 2021, 1:04pm UTC](https://forum.getodk.org/t/odk-code-only-sometime-converts-to-accurate-polygons-on-maps-but-not-always/35346/7 "2021-11-02T13:04:44Z")

</div>

[Mali\_Land\_Use\_Survey\_Sept21\_prepared\_GPS\_v4.xlsx](https://forum.getodk.org/uploads/short-url/4NCffGXjh4MgRGeJM8Mfo5501F5.xlsx) (424.1 KB)

Hello Mathieu,  
I trust you are well.  
Our Programme Manager recently clarified to me that the column which he uses to upload data from the Excel onto Google Maps/QGIS is on worksheet "Data\_v2" and its column "BB" titled "group\_survey/group\_gps/polygon/wkt". I had previously thought it was column "AW" titled "group\_survey/group\_gps/geoshape" which he was using.  
May I check with you, that the new code you recently shared with us will also provide 'clean' data in Column "BB", allowing him to automate the uploading of that data? (My previous understanding was that your code was removing the space which sometimes occurs after the semi-colon in column "AW").  
The data in column "BB" was mixed up, and I needed to clean it manually in worksheet "group\_gps\_geopoint\_v2" before copying it across into worksheet "Data\_v2" column "BB".  
Thank you Mathieu,

---

<div class="post-metadata">

**Author:** ![mathieubossaert](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/mathieubossaert/32/6131_2.png) [@mathieubossaert](https://forum.getodk.org/u/mathieubossaert)\
**Post date:** [November 2, 2021, 1:20pm UTC](https://forum.getodk.org/t/odk-code-only-sometime-converts-to-accurate-polygons-on-maps-but-not-always/35346/8 "2021-11-02T13:20:57Z")

</div>

Hi David,

the values in the BB column are the calculated fields of the form, so yes, if you apply the changes I made in the showcase's form in the _geopoints_ and _polygon_ section of your survey, calculated values would be ok... I tested it by replacing the "geo" question by a text input in the showcase form. If you try it with each wrong geoshape from the AW column, you should get a well formatted wkt.
