1

Maybe a rather simple question, but I could not find an answer. I am trying to extract long, lat, value from a .tiff file of a map of Africa with long/lat and soil acidity as the values.

Here is some information:

class : RasterLayer dimensions : 9578, 8990, 86106220 (nrow, ncol, ncell) resolution : 1000, 1000 (x, y) extent : -4108621, 4881379, -5076086, 4501914 (xmin, xmax, ymin, ymax) coord. ref. : +proj=laea +lat_0=5 +lon_0=20 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0 data source : C:\Users\M17GPPALT.tif names : M17GPPALT values : 0, 65535 (min, max) 

I want to extract simple long, lat, ph value for each point as an array.

1 Answer 1

2

Use rasterToPoints - for example:

> r = raster(matrix(1:12,3,4)) > rasterToPoints(r) x y layer [1,] 0.125 0.8333333 1 [2,] 0.375 0.8333333 4 [3,] 0.625 0.8333333 7 [4,] 0.875 0.8333333 10 [5,] 0.125 0.5000000 2 [6,] 0.375 0.5000000 5 [7,] 0.625 0.5000000 8 [8,] 0.875 0.5000000 11 [9,] 0.125 0.1666667 3 [10,] 0.375 0.1666667 6 [11,] 0.625 0.1666667 9 [12,] 0.875 0.1666667 12 

you'll end up with 86 million rows, although cells with NA aren't returned.

2
  • Thank you very much! As a follow up - to only extract a part of the map (e.g. a polygon), I have created a polygon using polyTara <- SpatialPolygons(...). How would I apply this before extract tthe points? Commented Aug 4, 2018 at 18:02
  • You can use raster::extract() to retrieve the raster values from any Spatial* object. For example, extract(your_raster, your_polgon) will return a dataframe of the pixel values. From here it is simple to create summary statistics (like those you would get from ArcGIS’s Zonal Statistics as Table). Commented Aug 4, 2018 at 20:01

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.