How to fix error in reading shape file vertices?

109 vues (au cours des 30 derniers jours)
Aksh Kumar
Aksh Kumar le 9 Déc 2024 à 10:55
Commenté : Cris LaPierre le 12 Déc 2024 à 14:18
% 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.

Réponses (1)

Cris LaPierre
Cris LaPierre le 9 Déc 2024 à 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 = 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 commentaires
Aksh Kumar
Aksh Kumar le 12 Déc 2024 à 1:38
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.
Cris LaPierre
Cris LaPierre le 12 Déc 2024 à 14:18
There is no position data in your shapefile.

Connectez-vous pour commenter.

Produits


Version

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by