Add centroid function for geospapes

Is there anyway to calculate the centroid of a geoshape the way we can calculate areas?

You can call area(${geoshape}) and it will return the area in meters. See for more.

1 Like

Thank you but I was asking if there was anything to calculate the centroid of a geoshape analagous to the way we cancalulate areas: e.g. something like centroid(${geoshape})

So sorry, @MartinFroglife. I misread the question! There's no built-in way to calculate centroid.

It sounds like it'd be helpful for us to add. Can you tell me more about how the centroid is used in your work? Also, any reason that it needs to be calculated on device rather than downstream in the analysis?

No worries. I'll preface my remarks to say that we could do this downstream or we could even get the user to enter this data with sufficient accuracy.

We are collecting data on ponds. The geoshapes are outlines of ponds and it would be nice to use the centroid as a location coordinate. The workflow (this is a new project so I am currently developing things) use the QRealtime QGIS plugin which takes the ODK data and imports it all into QGIS for display and query the data against any of the fields. If I can get all this to work it would be a very simple workflow with no code needing to be written but provide a very powerful tool.

As it happens I am having a bit of trouble with geoshapes and and QRealtime so doing things this way might be infeasable any way, and I will end up having to do more processing downstream and write some code somewhere, which I am not afraid of, but why reinvent stuff if I dont have to?. I just seem to be so close to something that is really simple yet meets our needs.

For what its worth, I would have thought centroid() would have been a pretty useful function in many circumstances, but if there is no demand for it from others I can see there may be many more important develeopments.


1 Like

If you can import successfully with qrealtime, or alternatively have an updated CSV of submissions land somewhere with the polygon WKT, you can create a layer from one of these, and then add a virtual field to the qrealtime layer or a separate layer linked to the CSV layer that will calculate the centroid and update with new or changed entries.

I have done similar to take geotrace and geoshape WKT or other shape data and calculate their centroids in ODK geopoint format to use as map select points in other forms.

The QGIS virtual field expression would look something like centroid($geometry). You can also create a new point layer as centroids of a selected layer in one click in QGIS, but this is a one time action and won't update, so only useful after all data are collected.

(Sorry if this is a bit unclear, I'm writing from mobile!)

Yeah the first in particular seems like a good workflow. But it is all so very close, but not quite all the way there, to being a zero work workflow. You can't blame me for checking!

And centroids do seem like a good idea to me, every bit as much as area:-)

This seems like a useful feature, so I've made this topic into a feature request. No idea when we'll be able to squeeze in this feature this in. Pull requests to JavaRosa and Enketo are welcome.