How to read shape file in matlab?

41 次查看(过去 30 天)
Devendra
Devendra 2024-3-26
编辑: Devendra 2024-4-10,5:32
此 个问题 已被 Dyuman Joshi 标记
I am using following matlab code to read shape file. I am attaching the shape file also as zip file. Please suggest me how to fix it? I would be highly obliged for kind help. Dave
  6 个评论
Dyuman Joshi
Dyuman Joshi 2024-3-31,7:51
Any updates, @Devendra? Did you check @Voss's answer?

请先登录,再进行评论。

回答(1 个)

Voss
Voss 2024-3-26
编辑:Voss 2024-3-26
You are attempting to read a file in the current directory:
S = shaperead(shapefile.name);
That is, you are not taking into account the location of that file.
You should specify an absolute or relative path to the file, e.g.:
file_name = fullfile(shapefile.folder,shapefile.name);
S = shaperead(file_name);
d = uigetdir(pwd, 'Select a folder');
assert(~isnumeric(d),'No folder selected')
shapefiles = dir(fullfile(d, '*.shp'));
for n = 1:length(shapefiles)
shapefile = shapefiles(n);
file_name = fullfile(shapefile.folder,shapefile.name);
disp(file_name);
S = shaperead(file_name);
polygon = polyshape([S.X], [S.Y]);
% Create a logical mask
logical_mask = inpolygon(lon, lat, polygon.Vertices(:, 1), polygon.Vertices(:, 2));
% ...
end

类别

Help CenterFile Exchange 中查找有关 Large Files and Big Data 的更多信息

产品


版本

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by