Convert double array to structure array for use in shapewrite() fxn

조회 수: 46 (최근 30일)
andrew joros
andrew joros 2011년 4월 30일
Anyone know how I can convert a double array to a struct array for use in a shapewrite() function?
I have three arrays: data, lat, lon which are each 556x1355 and i am trying to put this into a .shp file so that it can be read into ARCGIS. Any help?
I have tried googling with no help :-/
UPDATE: Now I am getting this error using a method I found online:
[test2.Geometry] = deal('MultiPoint');
test2.id = datarawsnan;
test2.lon = lonn;
test2.lat = latt;
shapewrite(test2, 'test2');
THE ERROR IS:
??? Error using ==> makedbfspec at 116
Attribute field id of geographic data structure S contains at least one value that is not a scalar double.
Error in ==> shapewrite>parseInputs at 555
dbfspec = makedbfspec(S);
Error in ==> shapewrite at 77
[S, basename, dbfspec] = parseInputs(varargin{:});
Thanks
A

답변 (2개)

Walter Roberson
Walter Roberson 2011년 4월 30일
[test2(1:numel(datarawsnan)).Geometry] = deal('MultiPoint');
t = num2cell(datarawsnan);
[test2.id] = deal(t{:});
t = num2cell(lonn);
[test2.lon] = deal(t{:});
t = num2cell(latt);
[test2.lat] = deal(t{:});
shapewrite(test2, 'test2');
Alternately,
test2 = struct('Geometry', 'Multipoint', 'id', num2cell(datarawsnan), 'lon', num2cell(lonn), 'lat', num2cell(latt));
shapewrite(test2, 'test2');
Though possibly you would have to change the shapewrite call to be
shapewrite(test2(:), 'test2');
The first version of the code using the explicit assignments would create a structure vector, whereas the second version of the code, using struct(), would create a structure array the same shape as your arrays.
  댓글 수: 1
dd
dd 2012년 5월 10일
Hi Walter,
I tried your struct() code, and it indeed works, but only within Matlab.
When then checking the produced .dbf file, the 'Lon' and 'Lat' fields are not recorded, which means that the entire shapefile itself cannot be imported in ArcGIS.
When reading the produced shapefile in Matlab (using shaperead), however, it seems that some NaN values are produced in the 'Lon' and 'Lat' fields (in a second column), which is not the case for the other fields. These NaN entries might be at the source of the problem.
Have you any clue about how to properly write 'Lon' and 'Lat' fields?
Cheers

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


Liyin
Liyin 2011년 10월 24일
It works!Thanks!

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by