How to fix error in reading shape file vertices?
Show older comments
% 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.
Answers (1)
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 Comments
Aksh Kumar
on 10 Dec 2024
Edited: Aksh Kumar
on 10 Dec 2024
Walter Roberson
on 10 Dec 2024
Edited: Walter Roberson
on 10 Dec 2024
unzip('Builtup.zip');
currentShapeTable = readgeotable("Builtup.shp");
currentShape = currentShapeTable
lat = currentShape.Shape.InternalData.VertexCoordinate1;
long = currentShape.Shape.InternalData.VertexCoordinate2;
plot(long, lat)
geoplot(currentShape.Shape)
Aksh Kumar
on 10 Dec 2024
Aksh Kumar
on 12 Dec 2024
Cris LaPierre
on 12 Dec 2024
There is no position data in your shapefile.
Categories
Find more on Data Import and Export in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
