필터 지우기
필터 지우기

How to define geographicGrid in matlab code?

조회 수: 6 (최근 30일)
Devendra
Devendra 2024년 3월 29일
댓글: Cris LaPierre 2024년 5월 27일
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

채택된 답변

Cris LaPierre
Cris LaPierre 2024년 3월 29일
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.
  댓글 수: 26
Aksh
Aksh 2024년 5월 27일
>> indices_caf
2481 2259
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 ds_hants_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)
mask = reshape(isinterior(polygon, lon(:), lat(:)), size(lon));
May I request you to please suggest me how to resolve this error.
I will be thankful to you.
Cris LaPierre
Cris LaPierre 2024년 5월 27일
Please ask a new question as this one is already answered. When doing so, please provide enough of the code for us to reporduce the error. It would be helpful to attach the necessary file(s) to your post using the paperclip icon. You may have to zip them first.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Identification에 대해 자세히 알아보기

제품


릴리스

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by