Extracting the values of pixel at certain points
10 views (last 30 days)
Show older comments
Mariam Salem
on 27 Nov 2017
Commented: Walter Roberson
on 30 Nov 2017
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
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
Accepted Answer
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
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".
More Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!