How to fix error in reading shape file vertices?

% 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 = 1x13 table
Shape OID_ Name FolderPath SymbolID AltMode Base Clamped Extruded Snippet PopupInfo Shape_Leng Shape_Area ____________ ____ ________ ____________ ________ _______ ____ _______ ________ _______ _________ __________ __________ geopolyshape 0 "PLANT1" "PLANT1.kmz" 0 0 0 -1 0 "" "" 0.0009767 5.5739e-08
currentShape.Shape
ans =
geopolyshape with properties: NumRegions: 1 NumHoles: 0 Geometry: "polygon" CoordinateSystemType: "geographic" GeographicCRS: [1x1 geocrs]
There is nothing to fix. The file does not contain the data you expected.

5 Comments

Thanks a lot for your suggestion. Please suggest me whether this shape file can be used by modifying the above mentioned code. If so, please suggest me the modification of this code to use plant1 shape file.
unzip('Builtup.zip');
currentShapeTable = readgeotable("Builtup.shp");
currentShape = currentShapeTable
currentShape = 1x2 table
Shape ID ____________ __ geopolyshape 1
lat = currentShape.Shape.InternalData.VertexCoordinate1;
long = currentShape.Shape.InternalData.VertexCoordinate2;
plot(long, lat)
geoplot(currentShape.Shape)
Thank you somuch for your suggestions. May I request you to please extract latitude and longitude of shape file PLANT1.zip also?
I tried to extract the latitude and longitude from the PLANT1.shp using following statements
lat = currentShape.Shape.InternalData.VertexCoordinate1;
long = currentShape.Shape.InternalData.VertexCoordinate2;
However, it gives following error
Unable to resolve the name 'currentShape.Shape.InternalData.VertexCoordinate1'.
Please suggest me how to extract the latitude and longitude of shape file in question.
There is no position data in your shapefile.

Sign in to comment.

Products

Release

R2024b

Asked:

on 9 Dec 2024

Commented:

on 12 Dec 2024

Community Treasure Hunt

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

Start Hunting!