how to extract the fields header in the shape file?

Is there a way to extract the fields headers in the shape file ? 13×1 struct array with fields: I need to read the headers Geometry,BoundingBox, ...
Geometry
BoundingBox
X
Y
ID_0
ISO
NAME_0
ID_1
NAME_1
HASC_1
CCN_1
CCA_1
TYPE_1
ENGTYPE_1
NL_NAME_1
VARNAME_1
DMSP_11sum
DMSP_12sum
DMSP_13sum
VIIRS_0412
VIIRS_0413
VIIRS_0414
VIIRS_Y15s
VIIRS_0415
FEB2015sum

2 Comments

What does "extract the fields headers in the shape file" actually mean?
Do you mean that you want to retrieve the values of the Geometry field of your structure? And do what with it? Put it into a new variable. If so, this will depends on what is in Geometry (scalar values? matrices of the same size? matrices of different size?)
No, what I mean is that the word "Geometry" and the words "BoundingBox" for example these I need to read them from the shape not writing them by hand because I have many shapes and each shape has different headers

Sign in to comment.

 Accepted Answer

A complete guess as it's really not clear what you're asking: If you want to get the list of fields of a structure, use fieldnames. To then use one of these names then use dynamic field name syntax:
%get list of fields
names = fieldnames(yourstructure);
%get value of 1st field
yourstructure.(names{1}) %() to access field whose name is in names{1}

6 Comments

Hi, sorry but I have another question if you can help me please .. I need each row as a matrix I mean each element in a cell but when I'm doing this for example:
s= shape(1)
size(s)
I got a matrix of 1x1 so all the info in one cell do you know how can I do this ? because I need to write them as a row in a csv file ...
I have attached the screen shots for more info..
Thank you so much .
The simplest way to write teh content of a structure array to a text file would be to convert that structure to a table then write that table to file. However, in your case some of the fields (X and Y) are matrices of different size. How would you write these into a csv file?
I don't need them actually the x and y is there a way to exclude them?
t = struct2table(s); %convert structure to table
t.X = []; %remove X column
t.Y = []; %remove Y column
writetable(t, 'somefile.csv');
You are great !!! Thank you so much for your help...

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!