Unable to POST coordinates to Events API

Hi all,

When I add coordinates as part of the json body to /api/30/events these are not stored against the event.

Version 2.30
Event Program created with Feature Type = Polygon (and can add a polygon through the UI)

Please let me know if I’m missing something.

Thanks

Documentation states (for tracked entity):

{
    "trackedEntity": "tracked-entity-id",
    "orgUnit": "org-unit-id",
    "coordinates": "[1, 1]",
    "attributes": [ {
        "attribute": "attribute-id",
        "value": "attribute-value"
    } ]
}

When I post (for event)

{
  "program": "Qa8SsbbNAET",
  "orgUnit": "Ln87Wf0A7hK",
  "eventDate": "2019-04-20",
  "status": "COMPLETED",
  "completedDate": "2019-04-20",
  "storedBy": "API_User",
  "coordinates": "[ [ [ 14.937399688077036, -25.141721827352683 ], [ 14.930269477859209, -25.271253979643209 ], [ 15.088322471021044, -25.271253979643209 ], [ 15.089510839390682, -25.270065611273569 ], [ 14.937399688077036, -25.141721827352683 ] ] ]",
  "dataValues": [
    { "dataElement": "UtoThjUTY4J", "value": "id0001" }
  ]
}

the transaction is successful (import successful) but the event does not contain the geometry.

2 Likes

Why are your coordinates an array?

2 Likes

@pierredane

It looks like your list of coordinates have spaces between the left square bracket and the longitude, as well as between the comma and the minus sign for the latitude.

That is not allowed - I have reported this on JIRA in another context (DHIS2-5969). The problem here is twofold: Firstly, some documentation indicates that such spaces are OK or even expected, and secondly certain things like injecting “incorrect” coordinates fail with no usable error message (or even worse, as in your case, the import seems successful but nothing is actually stored).

I suspect the problem here might be related to some low-level PostGIS formatting requirement - the API does not fully verify that incoming coordinates fits the PostGIS requirements exactly, but just “sends it on” and the actual db injection into the geometry field fails.

Regards
Calle

2 Likes

It is a polygon rather than a point

2 Likes

Hi Calle,
Thanks - I was hoping this was the issue but alas - without the spaces the coordinates are still not stored.

{
  "program": "Qa8SsbbNAET",
  "orgUnit": "Ln87Wf0A7hK",
  "eventDate": "2019-04-20",
  "status": "COMPLETED",
  "completedDate": "2019-04-20",
  "storedBy": "API_User",
  "coordinates": "[[[14.937399688077036,-25.141721827352683],[14.930269477859209,-25.271253979643209],[15.088322471021044,-25.271253979643209],[15.089510839390682,-25.270065611273569],[14.937399688077036,-25.141721827352683]]]",
  "dataValues": [
    { "dataElement": "UtoThjUTY4J", "value": "id0001" }
  ]
}
2 Likes

@pierredane

Mmm, so while it’s not those obvious space characters, it still looks like there’s a low-level postgis issue since the api call returns success but nothing is actually stored.

You stated that “Event Program created with Feature Type = Polygon (and can add a polygon through the UI)”. Have you tried to extract a UI-added polygon via the API and then compared it with what you are trying to POST?

If you are unable to post exactly the same as what you extract, then it’s got to be a bug somewhere…

Regards
Calle

1 Like