How to read shape file in matlab?

46 vues (au cours des 30 derniers jours)
Devendra
Devendra le 26 Mar 2024
Modifié(e) : Devendra le 10 Avr 2024 à 5:32
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 commentaires
Ram Prasanth
Ram Prasanth le 27 Mar 2024
Thank you @Voss for the clarification
Dyuman Joshi
Dyuman Joshi le 31 Mar 2024 à 7:51
Any updates, @Devendra? Did you check @Voss's answer?

Connectez-vous pour commenter.

Réponses (1)

Voss
Voss le 26 Mar 2024
Modifié(e) : Voss le 26 Mar 2024
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

Catégories

En savoir plus sur Large Files and Big Data dans Help Center et File Exchange

Produits


Version

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by