Convert double array to structure array for use in shapewrite() fxn
16 次查看(过去 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
0 个评论
回答(2 个)
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
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
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!