How to fix error in reading shape file vertices?
109 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
% Loop through each shapefile and read it using readgeotable
for i = 1:length(shapefileList)
shapefileFullPath = fullfile(shapefilePath, shapefileList(i).name);
roiShapes{i} = readgeotable(shapefileFullPath);
end
parfor k = 1:numShapes
currentShapeTable = roiShapes{k};
if ~isempty(currentShapeTable) && any(strcmp('Shape', currentShapeTable.Properties.VariableNames))
currentShape = currentShapeTable(1,:);
if isa(currentShape.Shape, 'geopolyshape')
x = currentShape.Shape.X;
y = currentShape.Shape.Y;
% Ensure coordinates are not empty
if ~isempty(x) && ~isempty(y)
% If multiple polygons or holes are present, they are separated by NaN.
% For simplicity, assume a single polygon part by removing NaNs:
validInd = ~isnan(x) & ~isnan(y);
x = x(validInd);
y = y(validInd);
% Convert from world coordinates to image intrinsic coordinates
[col, row] = worldToIntrinsic(R, x, y);
% Create a mask for the polygon
mask = poly2mask(col, row, rows, cols);
end
end
This code is giving error as
Error using . (line 229)
Unrecognized method, property, or field 'X' for class 'geopolyshape'.
I am attaching the shape file as well.
I request to please suggest me how to fix this error.
0 Kommentare
Antworten (1)
Cris LaPierre
am 9 Dez. 2024 um 16:43
In the file you have shared, your shapefile has a single shape in it, and that shape does not contain an X property.
unzip('PLANT1.zip');
currentShapeTable = readgeotable("PLANT1.shp");
currentShape = currentShapeTable
currentShape.Shape
There is nothing to fix. The file does not contain the data you expected.
5 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!