How to resolve the error for creating mask from shape file?
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:workndvi_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 408×5604579 (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 is uploaded on following link;
https://drive.google.com/file/d/1aqMYMJDlMOXvamybP-i6eiuo5ehYzdkh/view?usp=sharing
I would appreciate any help.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:workndvi_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 408×5604579 (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 is uploaded on following link;
https://drive.google.com/file/d/1aqMYMJDlMOXvamybP-i6eiuo5ehYzdkh/view?usp=sharing
I would appreciate any help. 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:workndvi_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 408×5604579 (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 is uploaded on following link;
https://drive.google.com/file/d/1aqMYMJDlMOXvamybP-i6eiuo5ehYzdkh/view?usp=sharing
I would appreciate any help. how to resolve the error for creating mask from s MATLAB Answers — New Questions