Extract coordinates from a geopolyshape

조회 수: 40 (최근 30일)
Sergey Kostrukov
Sergey Kostrukov 2022년 10월 12일
댓글: Sergey Kostrukov 2022년 11월 11일
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?

채택된 답변

Jacob Halbrooks
Jacob Halbrooks 2022년 11월 8일
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);
  댓글 수: 1
Sergey Kostrukov
Sergey Kostrukov 2022년 11월 11일
Thanks, loooks like this is a workaround. The optimal solution for now is to use shaperead I think.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

KSSV
KSSV 2022년 10월 12일
편집: KSSV 2022년 10월 12일
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)
ans = 'table'
us_states.(1) % first column
ans =
16×1 geopolyshape array with properties: NumRegions: [16×1 double] NumHoles: [16×1 double] Geometry: "polygon" CoordinateSystemType: "geographic" GeographicCRS: [1×1 geocrs]
us_states.LabelLat % third column
ans = 51×1
32.2827 64.6097 34.3451 34.8350 36.8223 39.0295 41.5106 39.1071 28.3914 32.5803
us_states.(4) % 4th column
ans = 51×1
-86.9206 -152.4593 -112.0705 -91.8861 -119.6633 -105.5440 -72.7627 -75.4942 -82.8483 -83.0864
  댓글 수: 7
Sergey Kostrukov
Sergey Kostrukov 2022년 11월 1일
They are definitely there since geoplot can plot them, but they seems internal only and not exposed to user code.
This has to be a feature request.
Chad Greene
Chad Greene 2022년 11월 2일
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
Chad Greene 2022년 11월 8일
@Sergey Kostrukov I think I found a working solution. The m_shaperead function in M_Map can handle PolygonZ and PolyLineZ data.
  댓글 수: 1
Sergey Kostrukov
Sergey Kostrukov 2022년 11월 11일
I didn't know about existence of M_Map and it looks amazing! Thank you very much.

댓글을 달려면 로그인하십시오.

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by