How can I maintain perfectly equivalent raster and SpatialPointsDataFrame extents when in R?

Each time I combine rasters, or raster and point data, the extents are very slightly different (like single-digit meters or less over an area of 10000+km2). I know this results from cropping/masking different resolution rasters.

At present, I am constantly using the functions projectRaster, crop, mask, spTransform, etc... to make things line up, but there must be a better approach.

  • 5
    Could you give an example of your problem? The extent of spatial points data frames is the extend of the points, the extent of a raster goes to the edges of the cells. I don't know what you mean by "Maintaining perfectly equivalent extents". They are what they is. – Spacedman Nov 21 '17 at 20:59
  • I'm dealing with rasters from multiple sources that are all clipped to the same polygon. But when the rasters have different resolutions, the edges of the resulting rasters are left with slightly different extents because the cells are of different sizes (resolutions). So, to keep a full cell along the edge, you end up with slightly different extents, which lead to error messages when using functions on >1 raster or raster + point data. – ecologist1234 Nov 22 '17 at 17:26
  • Yeah, this is really important - I use workflows like this all the time, and also have spex::buffer_extent so that an extent is "exactly whole-numbered" at some grain. I'm pretty au fait with keeping extents constant through workflows, but that takes a bit of practice - usually it involves creating a raster on a specific extent, or extending it and then carrying it through. Can you provide an actual example I'll try to explain more? – mdsumner Nov 29 '17 at 20:33

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.