How to read the properties information of kml data

8 views (last 30 days)
I got geographical information using 'readgeotable',
but I want to bring properties information of actual kml data.
In more detail, I would like to bring each field within the kml data and the property information corresponding to the field.
Is there any way?

Answers (1)

Shivam
Shivam on 11 Sep 2024
Using readgeotable for the kml data, gives a nxm table where n corresponds to no. of 'Placemark' inside the kml document. In the below mentioned workaround, I have used a sample data with 2 Placemarks, plotted it using wmmarker function and and illustrated how to extract individual field values.
>> T = readgeotable('path/to/kmlfile.kml');
>> wmmarker(T); % Plot the source locations on a web map.
>> T
T =
2×3 table
Shape Name Description
_______________________ ____________ ______________________________
(37.4223°N, 122.0822°W) "Location 1" "This is the first location."
(37.4220°N, 122.0850°W) "Location 2" "This is the second location."
>> fieldNames = T.Properties.VariableNames; % Get the keys (field names) of the table
fieldNames =
1×3 cell array
{'Shape'} {'Name'} {'Description'}
Here's how you can extract column corresponding to 'Shape' fieldName and also extract value of first row:
% Extract the 'Shape' column
shapeColumn = T.Shape;
% Access the first row of the 'Shape' column
firstShape = T.Shape(1);
Also note that I am providing the sample data in a .txt file because this community platform does not support attaching .kml files directly. You can copy the data from the .txt file into a .kml file on your system to test the workaround.
I hope it helps.

Products


Release

R2024a

Community Treasure Hunt

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

Start Hunting!