I have a list (s) containing information on the probable locations of many animals in South America. For example, this is the type of stored information and what it looks like when plotted for the first individual.


> s[1]
class       : RasterLayer 
dimensions  : 418, 313, 130834  (nrow, ncol, ncell)
resolution  : 0.16666, 0.16666  (x, y)
extent      : -86.333, -34.16842, -55.91633, 13.74755  (xmin, xmax, ymin, ymax)
coord. ref. : NA 
data source : in memory
names       : layer 
values      : 0, 1  (min, max)
> plot(s[[1]])

enter image description here

Note: the green areas are all "likely" locations and the grey areas are "unlikely" locations.

I also have spatial data in geoTIFF format from NASA.

I would like to determine the centroid of the likely areas for each individual, and identify the value for the GeoTIFF spatial data that matches with the centroid (i.e., likely a different value for each individual).

UPDATED To determine the centroid, I've tried the following:

indi1<-s[[1]] #restrict list to 1st individual
colMeans(xyFromCell(indi1, which(indi1[]==1)))
        x         y 
-52.62926 -18.16871 

However, even though this just uses coordinates where the value was "likely" (1's), you can see that the centroid falls in an area that is "unlikely".

points(colMeans(xyFromCell(indi1, which(indi1[]==1)))[1],
       colMeans(xyFromCell(indi1, which(indi1[]==1)))[2],
plot(indi1, xlim=c(-55,-50), ylim=c(-20,-15))
points(colMeans(xyFromCell(indi1, which(indi1[]==1)))[1],
       colMeans(xyFromCell(indi1, which(indi1[]==1)))[2],

enter image description here

So I still need a solution for restricting the final centroid value to an area that is "likely". And, ultimately, associating this location with a value in the GeoTIFF.

Note: this question is related to another question I have here.

  • I don't use r, but you could achieve your goals with QGIS also. It's not clear if for 1) you want the mean value across all areas, or the mean value across each individual connected area. For 2), you can polygonize your raster and compute centriods of the polygons. – Jon Nov 16 '18 at 15:17
  • Thanks @Jon. Unfortunately, the first part of my analysis, to identify probable locations shown above is all done in r. I'd prefer to not switch platforms, as I am unsure how this could be done in QGIS. – tnt Nov 16 '18 at 15:24
  • Can you narrow this down to one question only (and open another question for your second part), and try and either give us some sample data or code to generate sample data. – Spacedman Nov 16 '18 at 16:57
  • @Spacedman I have split the question into two different questions (the second one is here: gis.stackexchange.com/questions/302963/…). Unfortunately, I don't have a way to provide sample data, the process to get the probable locations is very complex and not my code to share. The best I can do is provide the example above for the different fields and values. – tnt Nov 16 '18 at 17:15
  • 1
    You can't restrict the "final centroid" location - the centroid is where the centroid is. You could, however, if the centroid point is in a "0", take the nearest cell that is a "1" (green) and use the centre of that cell as a point proxy for whatever it is you want to calculate from it. – Spacedman Nov 16 '18 at 18:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.