How to export contour plot as shape file?

Hi, I want to export result of plotting as shapefile. Before, I use several syntaxes, like shapewrite, but it does not work. Thank you.
[X,Y,Z] = peaks;
figure
A=contour(X,Y,Z,20);
shapewrite(A,'contour.shp')

 Respuesta aceptada

KSSV
KSSV el 19 de Abr. de 2018
Editada: KSSV el 19 de Abr. de 2018
[X,Y,Z] = peaks;
figure
A=contour(X,Y,Z,20);
% shapewrite(A,'contour.shp')
x = A(1,:) ;
y = A(2,:) ;
Data = struct([]) ;  % initilaize structure
for i = 1:length(x)
    Data(i).Geometry = 'Point' ;
    Data(i).X=x(i)  ;  % x value 
    Data(i).Y =y(i) ;  % y value
    Data(i).Name = randseq(1) ;   % some random attribute/ name
end
shapewrite(Data, 'myfile.shp')

5 comentarios

Thank you for your answer. Is there is another way to do it? I cant use ranseq syntax..
To use 'randseq', the following product must be licensed, installed, and
enabled:
Bioinformatics Toolbox
KSSV
KSSV el 19 de Abr. de 2018
Oh..... randseq is optional..it is not compulsory...you can skip that line completely.
Amra Rajuli
Amra Rajuli el 19 de Abr. de 2018
Thank you. I have exported it to GIS, it works. However, it has no properties, so we cannot set contour color difference in GIS. Also, the result a bit different. I attach the figure.
In your attached figure you are asking where a set of extra scattered points come from. It may come from the contour matrix A itself. For each new contour line extra information is stored. The code provided by KSSV is interpreting this information as coordinates. Following example (based on KSSV solution) solves that problem:
x_cont = A(1,:);
y_cont = A(2,:);
count_parts=1;
idx=1;
while idx<length(y_cont) % extracts each single contour
part(count_parts,:)=[idx+1 idx+y_cont(idx)];
idx=idx+y_cont(idx)+1;
count_parts=count_parts+1;
end
count_parts=count_parts-1;
Data = struct([]) ; % initilaize structure
for i = 1:count_parts
Data(i).Geometry = 'Line' ;
Data(i).X=x_cont(part(i,1):part(i,2)) ; % x value
Data(i).Y =y_cont(part(i,1):part(i,2)) ; % y value
Data(i).Z =x_cont(part(i,1)-1) ; % store the contour value
end
shapewrite(Data, 'myfile.shp')
Ozgur Kirca
Ozgur Kirca el 6 de Dic. de 2023
Great script, worked very nicely! Thank you @Max Friedrich!!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Etiquetas

Preguntada:

el 19 de Abr. de 2018

Comentada:

el 6 de Dic. de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by