Extracting the values of pixel at certain points

10 views (last 30 days)
I have a large raster layer that has aridity values assigned to each pixel. I also have latitude and longitude data of some locations in USA. I would like to know the pixel value according to my latitude and longitude locations . I first clipped the raster to my area of interest (USA) in Arcmap the I converted my clipped raster in to a .tif file then I did the following, where i convert these pixels into lat and lon but I am having problems finishing the code. I'm not sure what to do. Or is there a different approach. Any suggestions?
I = imread('ai_yr1.tif');
info = geotiffinfo('ai_yr1.tif');
height = info.Height; % Integer indicating the height of the image in pixels
width = info.Width; % Integer indicating the width of the image in pixels
[rows,cols] = meshgrid(1:height,1:width);
[ADlat,ADlon] = pix2latlon(info.RefMatrix, rows, cols);
Thank you for the help!!
  4 Comments
Walter Roberson
Walter Roberson on 28 Nov 2017
You might be able to zip it and attach that. If the result would still be over 5 Mb then you might have to provide a link to something like Google Drive or DropBox
Mariam Salem
Mariam Salem on 29 Nov 2017
Edited: Walter Roberson on 29 Nov 2017
I have put some latitude and longitude locations as an example (you could use a couple of them if you wish) and AI_clip1 is the tif file

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 29 Nov 2017
I = imread('AI_clip1.tif');
info = geotiffinfo('AI_clip1.tif');
Latlon = xlsread('Latlon.xlsx');
height = info.Height; % Integer indicating the height of the image in pixels
width = info.Width; % Integer indicating the width of the image in pixels
[rows,cols] = meshgrid(1:height,1:width);
[ADlat,ADlon] = pix2latlon(info.RefMatrix, rows, cols);
Idub = double(I);
mask = I == (intmin('int32')+1);
Idub(mask) = nan;
pixelvalues = interp2(ADlat, ADlon, Idub.', Latlon(:,1), Latlon(:,2));
Note: a number of the results at the end are nan, because those are outside of the clipped map.
... What is this data? When I
surf(Idub, 'edgecolor', 'none'); colormap(parula(256))
then it looks similar to heights, but when I compare against the list of highest points in the USA, it appears to be missing most of the Rocky Mountains in Colorado. The maximum point in the data appears to be somewhat near to Mount St. Helens; the data just might correspond to its height in inches taking into account the bulge of the Earth ? But what happened to the Rockies or the other high continental peaks?
  2 Comments
Mariam Salem
Mariam Salem on 30 Nov 2017
The raster file shows the aridity from it you can extract the values of the aridity index.
I have another question, for one point it seems to be outside the limits I would guess it's because of the raster file itself. I checked the point on google maps it is with the USA boundaries, which means there's a shift. How do I over come this? Do I run for this point alone and shift it back? I wouldn't know how to do that....or do I change the latitude and longitude?
The point is: lat= 36.8975 , lon= -121.8347
If you plot it in matlab with the USA boundaries it still lies outside...I don't understand why is that.
Do you have any ideas?
Walter Roberson
Walter Roberson on 30 Nov 2017
The map resolution is 0.00833333376795053 degree, which I figure for that location is approximately 710 metres. The point you indicate is approximately 285 metres east of a spot marked with no data, so it is closer to the "no data" point than to the data point to the east of it.
You could change
Idub(mask) = nan;
to
Idub(mask) = 0;
to have it use 0 for the points marked "no data".

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!