필터 지우기
필터 지우기

Create line Shapefile with attributetable

조회 수: 6 (최근 30일)
Jojor
Jojor 2023년 6월 22일
답변: Aiswarya 2023년 8월 8일
I'm working with dune morphologies and want to create a shapefile with lines to view in arcmap. The basis from which all the variables have been calculated is a 1576 x 101 raster with the coordinates xr and yr. I was able to create a shapefile but I want to add smoothed and crestO to the attribute table. The structure of the array I'm using is the following:
>> MC.CL
ans =
struct with fields:
Connectivity: 8
ImageSize: [1576 101]
NumObjects: 337
PixelIdxList: {1×337 cell}
smoothed: {1×337 cell}
crestO: {1×337 cell}
I used the PixelIdxList field (structure see below) to get the absolute position of the pixels involved
>> MC.CL.PixelIdxList
ans =
1×337 cell array
Columns 1 through 6
{16×1 double} {49×1 double} {24×1 double} {28×1 double} {15×1 double} {9×1 double}
and used this snippet to get the actual coordinates and to create a shapefile
% get coordinates %
for i=1:MC.CL.NumObjects
crest.xline{i}=xr(MC.CL.PixelIdxList{i});
crest.yline{i}=yr(MC.CL.PixelIdxList{i});
end
%shapefile%
crest = struct('Geometry', 'Line', 'NumFeatures', MC.CL.NumObjects, 'Lat', crest.yline, 'Lon', crest.xline);
shapewrite(crest, crest_name);
With
crest =
1×337 struct array with fields:
Geometry
NumFeatures
Lat
Lon
How do I add 'smoothed' and 'crestO' to the attribute table? The function documentation wasn't helpful with that, at least not to a beginner.

답변 (1개)

Aiswarya
Aiswarya 2023년 8월 8일
It is my understanding that you want to add two additional attributes (smoothed and crestO) to the struct array crest. The structure was created with an initial set of fields, but more fields need to be added.
This can be done by creating two new fields and assigning them to the respective cell arrays obtained from MC.CL using the deal function:
[crest(:).smoothed] = deal(MC.CL.smoothed{:});
[crest(:).crestO] = deal(MC.CL.crestO{:});
This will assign each element of the cell to the respective element of the structure array, i.e., crest(1).smoothed will have the first element of MC.CL.smoothed and so on.
I hope this helps.
Regards
Aiswarya

카테고리

Help CenterFile Exchange에서 NaNs에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by