2

I have a dataset which represents a global grid with latitude and longitude and the length of each pixel along the x and y axis. These are simply lat/long CRS.

Like this

head(latlong)
   x      y     x.leng  y.leng   value 
80.221 50.854  72334 16027.8       0.1
80.000 50.214  32132  2404.4       0.2
79.779 50.214  72334 16027.8       0.6
79.664 50.854  77632 23841.8       0.5
79.572 51.548  80556 29873.3       0.3
79.491 52.270  82574 34953.4       0.2

Where x and y are the center of the cell and leng is the total length of the cell in the two directions. Because I have to do area-based calculations like extracting the values of cells in a raster that overlap with polygons, I cannot convert to a regular-sized raster and I don't want to interpolate values. So the functions rasterize and rasterXYZ don't work for me.

I know rast objects can have irregular-sized cells when they are projected but I am not sure how to set this up from the above data frame.

Should I consider creating a multi-polygon simple feature? What are my options?

Herman Toothrot
  • 1,463
  • 3
  • 23
  • 53
  • Just for clarification: x, y is the bottom left (south-west) corner of your "cell" in degrees, and x.leng, y.leng horizontal/vertical distances from the corner after a given cartesian projection? In that case, yes, you might handle the irregular "raster" cells as a set of polygons and stick to vector operations (e.g. overlapping and summing value-weighted fragment areas). Unless performance is an issue, in which case you might want to rasterize your irregular cells, and perhaps also the polygons, however with a precision tradewoff. Have you tried over at https://gis.stackexchange.com/ ? – I_O Mar 17 '23 at 23:08
  • @I_O sorry I should have said, x and y are the center of the cell, but I don't think it matters as the corners can be calculate using length. Haven't tried gis.SE because I usually have more luck here. You are right, probably having almost 30k polygons might make things very slow. – Herman Toothrot Mar 18 '23 at 08:50
  • 1
    in short you can't, you have to treat this as point data and interpolate from it - in general though, you absolutely can, the data might be regular in a different projection, or if they are not you can read it trhough the gdal warper (with indeed rast() and project() in some cases but terra won't indicate that to you) - if you want to share the data set I'll figure it out and explain,there are many situations so I can't just answer what will work here without trying – mdsumner Mar 28 '23 at 08:23

0 Answers0