0

I have the following data frame (long, lat, value) (all coordinates are within Colombia):

Spoints:
        x           y           z
    1   -75.67083   7.57916667  7.328901e-19
    2   -74.59583   2.34583333  4.470517e-28
    3   -73.67083   5.82083333  2.796526e-11
    4   -75.31250   8.68750000  2.867735e-20
    5   -73.88750   10.47083333 4.460837e-14
    6   -73.22083   -1.56250000 3.127243e-35
    7   -72.12083   -1.47083333 1.361218e-37
    8   -74.54583   9.60416667  1.108581e-37

I would like to create a raster and plot it on Colombia's map.

  • 1
    Well, if this is all of your data the problem is that it is not gridded and, as is, cannot be represented as a raster. Raster data is systematical spaced data, representing an array, over an entire extent. Whereas your data is non-aligned point data. You could interpolate using something like kriging it but, given its spatial distribution and n, you would likely not get good results. What is your goal here? You could display the points as variable color and size to represent the data. – Jeffrey Evans Apr 4 '16 at 22:21
2

You are providing spurious information and omitting important information. I do not care that you are plotting over the "wrld_simpl" data but would like to know what the resulting object classes are and if there are any attributes in the SpatialPixelsDataFrame and resulting raster objects. I would ask, why are you projecting to the same projection? The spTransform is completely unnecessary and possible causing you issues.

Please clarify your post to distill it to the actual issue. To assign values, the raster function should just grab the first attribute in the @data slot. However you can specify which column you want by specifying the column name. Here is a quick worked example.

library(sp)
library(raster)

data(meuse.grid) 
coordinates(meuse.grid) <- ~x+y 
gridded(meuse.grid) <- TRUE

class(meuse.grid)
str(meuse.grid@data)

r <- raster(meuse.grid, "dist") 
class(r)
plot(r)
  • Thank you for your help. I am just a begginer on GIS using R and I used another example that I found here. I already have employed the example you provided, however it still does not work. Is there an issue if all the raster cells are not defined in the data frame? – mountainlake Apr 4 '16 at 22:05
  • What happens when you try to plot the SpatialPixelsDataFrame object, before you coerce it to a raster class object? You can use spplot, in my example spplot(meuse.grid, "dist") If nothing plots or you just plot an array of points, then there is an issue that we can start with. – Jeffrey Evans Apr 4 '16 at 22:10
  • spplot(Spoints, "z") worked! Do you know why I can't rasterize it? – mountainlake Apr 4 '16 at 22:15

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.