필터 지우기
필터 지우기

Info

This question is locked. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

How to read shape file in matlab?

조회 수: 30 (최근 30일)
Devendra
Devendra 2024년 3월 26일
Locked: Rena Berman 2024년 6월 5일
I am using following matlab code to read shape file. I am attaching the shape file also as zip file.
% pickup the shape files
d = uigetdir(pwd, 'Select a folder');
shapefiles = dir(fullfile(d, '*.shp'));
for n = 1:length(shapefiles)
\ shapefile = shapefiles(n);
disp(shapefile.name);
S = shaperead(shapefile.name);
\ polygon = polyshape([S.X], [S.Y]);
% Create a logical mask
logical_mask = inpolygon(lon, lat, polygon.Vertices(:, 1), polygon.Vertices(:, 2));
end
This is giving the following errors;
>> test\r\nAchi Khurd.shp
Error using openShapeFiles>checkSHP (line 82)
Unable to open file 'Achi Khurd.shp'. Check the path and filename or file permissions.
Error in openShapeFiles (line 19)
[basename, ext] = checkSHP(basename,shapeExtensionProvided);
Error in shaperead (line 212)
= openShapeFiles(filename,'shaperead');
Error
in test (line 9)
S = shaperead(shapefile.name);
>>
Please suggest me how to fix it? I would be highly obliged for kind help.
Dave
  댓글 수: 8
Rena Berman
Rena Berman 2024년 6월 5일

(Answers Dev) Restored edit

Rena Berman
Rena Berman 2024년 6월 5일

(Answers Dev) Restored edit

답변 (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

This question is locked.

카테고리

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