Extract coordinates from a geopolyshape
97 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Sergey Kostrukov
el 12 de Oct. de 2022
Comentada: Aymane ahajjam
el 30 de Ag. de 2024
Given a geographic shape object of type geopolyshape:
us_states = readgeotable("usastatehi.shp")
montana = us_states.Shape(us_states.Name == "Montana")
class(montana)
ans =
'geopolyshape'
How could I extract a list of Lat/Lon coordinates of the given shape object (mo_lat, mo_lon)?
% montana
mo_lat = ??? % list of latitudes of Montana polygon edges
mo_lon = ??? % list of longitudes of Montana polygon edges
I know it's possible when loading data using shaperead function instead:
us_states = shaperead("usastatehi.shp")
montana = us_states(26); % 26 is Montana
mo_lat = montana.Y; % list of latitudes of Montana edges
mo_lon = montana.X; % list of longitudes of Montana edges
But I'm curious if it's possible to extract data from existing geopolyshape?
0 comentarios
Respuesta aceptada
Jacob Halbrooks
el 8 de Nov. de 2022
You can access latitude-longitude coordinates from a geopolyshape using the geotable2table function. We recognize that there is a need to make coordinate data access easier, but in the meantime you can use this approach as a workaround. For example, assuming your table contains geopolyshape data:
GT = readgeotable("myfile.shp");
T = geotable2table(GT,["Lat","Lon"]);
You can also extract the data into NaN-delimited arrays using polyjoin:
[lat,lon] = polyjoin(T.Lat,T.Lon);
2 comentarios
Más respuestas (2)
KSSV
el 12 de Oct. de 2022
Editada: KSSV
el 12 de Oct. de 2022
The present version is much easier. Note that the class of us_states is a table. You can extract the column using:
us_states = readgeotable("usastatehi.shp") ;
class(us_states)
us_states.(1) % first column
us_states.LabelLat % third column
us_states.(4) % 4th column
7 comentarios
Chad Greene
el 2 de Nov. de 2022
This is so frustrating. I don't understand why these new functions have been designed to prevent users from accessing the data we're trying to analyze.
Chad Greene
el 8 de Nov. de 2022
@Sergey Kostrukov I think I found a working solution. The m_shaperead function in M_Map can handle PolygonZ and PolyLineZ data.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!