Convert double array to structure array for use in shapewrite() fxn
14 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (2)
Walter Roberson
el 30 de Abr. de 2011
[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 comentario
dd
el 10 de Mayo de 2012
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
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!