How to make a logical mask using a shape file?
Show older comments
I am using following MATLAB code to create logical mask.
% Create a logical mask
[Z,R] = readgeoraster(img_file.name);
disp(R);
[lat,lon] = geographicGrid(R);
[Lon, Lat] = meshgrid(lon, lat);
logical_mask = reshape(isinterior(polygon, Lon(:), Lat(:)), size(Lon));
It is giving following erros
Incorrect number or types of inputs or outputs for function geographicGrid.
Error in ds_indices_caf (line 57)
[lat,lon] = geographicGrid(R);
I request to kindly suggest me how to do it correctly.
Dava
Answers (1)
Image Analyst
on 26 Mar 2024
0 votes
You have to define lat and lon as vectors before you use them in meshgrid to get the full matrices Lat and Lon as outputs.
8 Comments
OK, you edited the code to fix the missing definitions of lat and lon, but this is what we get
% Create a logical mask
[lat,lon] = geographicGrid(img_file.name);
[Lon, Lat] = meshgrid(lon, lat);
logical_mask = reshape(isinterior(polygon, Lon(:), Lat(:)), size(Lon));
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:
Devendra
on 27 Mar 2024
It looks like it probably requires the Mapping Toolbox, which I do not have. Does it?
help geographicGrid
Devendra
on 27 Mar 2024
Devendra
on 27 Mar 2024
Image Analyst
on 28 Mar 2024
I believe during the trial period you get free telephone help. Call them and work through it with an actual live person. I can't help you because I do not have that toolbox.
Categories
Find more on Mapping Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!