How do I extract the multiband data using shape file?

조회 수: 4 (최근 30일)
gauri
gauri 2024년 5월 9일
편집: gauri 2024년 5월 13일
I am using my matlab code to extract the multiband data from envi format using shape file. Code is working without any error but it is not extracting multiband data. I am attaching the code and providing the link for data file and shape file and request you to please have a look on it and suggest me how to extract the multiband data. data link is as follows;
  댓글 수: 3
gauri
gauri 2024년 5월 9일
The link mentioned above also have shape file along with data file.
gauri
gauri 2024년 5월 9일
이동: Cris LaPierre 2024년 5월 10일
the extracted data should have
number of sample = 1315
number of lines = 1153
number of bands = 7

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

답변 (1개)

Jacob Mathew
Jacob Mathew 2024년 5월 10일
After going through the query and downloading the data and the code, I was able to run the code without any error. However, there are few discrepancies that I noticed which may be the reason why you are not getting the output that you expected.
Non unique data across some bands
You have tried to plot multiple bands simultaneously using the code:
mapshow(rescale(Z(:,:,[3 2 1])),R)
Plotting only one band at a time and comparing them side by side shows that there isn’t much variation between them:
Further investigation shows that there are only 3 unique bands:
  • Band 1 (corresponding to index 1)
  • Band 2, 3 4 and 5 (corresponding to index 2, 3, 4 & 5)
  • Ban 6 and 7 (corresponding to index 6 & 7)
Possibly incorrect logical mask
The 5490x5490 matrix logical mask has a rank of 3 and the sum of all its elements is 5. This shows that that mask matrix is overwhelmingly empty.
Fixing these two discrepancies might yield better result.
  댓글 수: 1
gauri
gauri 2024년 5월 10일
편집: gauri 2024년 5월 13일
I have modified the code as follows;
% Get image info:
DataFile='C:\working_bpt\bands\Bagpat_7Bands.dat'
[Z,R] = readgeoraster(DataFile);
disp(size(Z));
p = R.ProjectedCRS;
[x,y] = worldGrid(R);
[lon,lat] = projinv(p,x,y);
ShapeFile='C:\working_bpt\bands\BAGHPAT.shp'
S = shaperead(ShapeFile);
info = shapeinfo(ShapeFile);
crs = info.CoordinateReferenceSystem;
[S(1).lon,S(1).lat] = projinv(crs,S(1).X,S(1).Y);
% Remove trailing nan from shapefile
rx = S(1).lon(1:end-1);
ry = S(1).lat(1:end-1);
logical_mask = inpolygon(S(1).lon,S(1).lat,rx,ry);
% Use the logical mask to extract data
extracted_data = Z(logical_mask);
disp(extracted_data);
it is giving following informations
DataFile =
'C:\working_bpt\bands\Bagpat_7Bands.dat'
5490 5490 7
ShapeFile =
'C:\working_bpt\bands\BAGHPAT.shp'
1 9
>>
I request you to kindly look on it and suggest me how to get seven band data using shape file.

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

카테고리

Help CenterFile Exchange에서 Import, Export, and Conversion에 대해 자세히 알아보기

제품


릴리스

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by