How to define geographicGrid in matlab code?

91 views (last 30 days)
I am using following matlab code to extract data but it is giving some error.
img_file = 'c:\data\4MARCH24_BAND7_SUBSET.dat'
img = hypercube(img_file);
shapefile = 'c:\data\Achi Khurd.shp';
S = shaperead(shapefile);
%remove small triangles and squares
coord_lengths = arrayfun(@(s) numel(s.X), S);
not_useful_mask = coord_lengths < 10;
S(not_useful_mask) = [];
polygon = polyshape({S.X}, {S.Y});
% Create a logical mask
[Z,R] = readgeoraster(img_file);
[lat,lon] = geographicGrid(R);
[Lon, Lat] = meshgrid(lon, lat);
logical_mask = reshape(isinterior(polygon, Lon(:), Lat(:)), size(Lon));
% Use the logical mask to extract data
extracted_data = img(logical_mask);
disp(extracted_data);
It is giving following error
Incorrect number or types of inputs or outputs for function geographicGrid.
Error in Test (line 14)
[lat,lon] = geographicGrid(R);
I am attaching the data also in order to run the above mentioned matlab code.
I would be thankful for suggesting me to fix it.
Deva

Accepted Answer

Cris LaPierre
Cris LaPierre on 29 Mar 2024 at 16:14
Ultimately, the issue is because your input to geographicGrid is the wrong data type.
geographicGrid expects the input to be a GeographicCellsReference or GeographicPostingsReference object (see here). However, if you inspect the class of your variable R in the Workspace, you will see it is a MapCellsReference object.
Basically, your data file does not contain the data format you expect.
You can compare the difference between the two as well as see their corresponding object functions on their respective doc pages.
  23 Comments
Devendra
Devendra on 24 Apr 2024 at 12:40
Edited: Devendra on 24 Apr 2024 at 12:41
I have put across the question of customizing enviwrite code to larger MATLAB community but so far nobody has responded in last two days. Actually I want to customize enviwrite matlab code for reading my map_info and produce ENVI header file containing map_info and projection_info. Please suggest me whom should I approach to get it coustomized for my purpose. I would appreciate your kind suggestions and would be highly obliged to you.
Devendra
Cris LaPierre
Cris LaPierre on 24 Apr 2024 at 13:05
Sorry. It can take a while, especially if the topic is niche. I'm afraid this is not an area where I consider myself an expert. I do not know who to direct you to, and I am unfamiliar with the topics you are asking about.

Sign in to comment.

More Answers (0)

Products


Release

R2024a

Community Treasure Hunt

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

Start Hunting!