Clear Filters
Clear Filters

How to resolve the error for creating mask from shape file?

67 views (last 30 days)
Aksh
Aksh on 27 May 2024 at 13:05
Commented: KSSV on 28 May 2024 at 3:12
I am using following MATLAB code to create mask using shape file
S = shaperead(shapefile.name);
% Shapefile projections
info = shapeinfo(shapefile.name);
crs = info.CoordinateReferenceSystem;
[S(1).lon,S(1).lat] = projinv(crs,S(1).X,S(1).Y);
%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(1).lon}, {S(1).lat});
[Z,R] = readgeoraster('C:\work\ndvi_2022_23.dat');
p = R.ProjectedCRS;
[x,y] = worldGrid(R);
[lon,lat] = projinv(p,x,y);
% Create a logical mask
logical_mask = reshape(isinterior(polygon, lon(:), lat(:)), size(lon));
However, it is giving following error;
Ale.shp
Warning: Polyshape has duplicate vertices, intersections, or other inconsistencies that may produce inaccurate or
unexpected results. Input data has been modified to create a well-defined polyshape.
> In polyshape/checkAndSimplify (line 526)
In polyshape (line 175)
In indices_caf (line 45)
Requested 408x5604579 (17.0GB) array exceeds maximum array size preference (15.8GB). This might cause MATLAB to
become unresponsive.
Error in polyshape/isinterior>check_inpolygon (line 65)
x = x(ones(Nv,1),:);
Error in polyshape/isinterior (line 50)
[in, on] = check_inpolygon(X, Y, xv, yv, tol);
Error in indices_caf (line 53)
logical_mask = reshape(isinterior(polygon, lon(:), lat(:)), size(lon));
shape file is attached as zip file while data file ndvi.dat is uploaded in the following link;
I would appreciate any help.
  1 Comment
KSSV
KSSV on 28 May 2024 at 3:12
Error using readgeoraster
Unable to read 'ndvi.dat'. Format may not be supported, file may be corrupt, or a supporting file may have been specified.
Error in Junk (line 13)
[Z,R] = readgeoraster('ndvi.dat');

Sign in to comment.

Answers (0)

Products


Release

R2024a

Community Treasure Hunt

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

Start Hunting!