modifying vertices of geopolyshape

17 次查看(过去 30 天)
Murat Panayirci
Murat Panayirci 2022-11-8
移动Walter Roberson 2025-8-16,4:32
Hi,
I can modify an existing polyshape plot as follows:
Vertices = [0 0 2 2; 2 0 0 2]';
NewVertices = [0 0 2 2; 2 0 0 3]';
pgon = polyshape(Vertices);
p = plot(pgon,'FaceColor','red','FaceAlpha',0.1);
p.Shape.Vertices = NewVertices;
however I can't do the same thing with geopolyshape, since I could not find any properties of it which stores the lat,lon coords. Essentially, I want to enable moving a geopolyshape incrementally with user commands. I would be glad if you anybody could advise.
Thank you,
Murat

回答(2 个)

Geetla Sindhu
Geetla Sindhu 2022-11-11
Hello Murat,
I understand that you are trying to use geopolyshape with geographic coordinates.
You can try the following workaround to solve the issue:
  • A geopolyshape object represents a polygon or multipolygon in geographic coordinates. Use the geopolyshape function.
shape = geopolyshape(lat,lon)
This function creates a polygon with vertices at the specified latitude and longitude coordinates.
  • Then geoplot is used to plot the point, line, or polygon shape objects in shape on a geographic axes.
pg = geoplot(shape)
Now pg is a polygon object with different properties and they be accessed using dot notation.
For example:
shape = geopolyshape([1 10 1 1],[1 1 10 1] );
pg = geoplot(shape);
pg.FaceColor = "r";
Hope this resolves your issue.
You can also refer to Geographic polygon appearance and behavior - MATLAB (mathworks.com) for further information regarding polygon properties.
Thank you.
  1 个评论
Murat Panayirci
Murat Panayirci 2022-11-11
移动:Walter Roberson 2025-8-16,4:32
Hi Geetla,
my problem is that the object pg you created with geoplot does not have a "Vertices" field (as in the regular polyshape plot) which I can modify. see below
shape = geopolyshape([1 10 1 1],[1 1 10 1] );
pg = geoplot(shape);
>> pg.ShapeData
ans =
geopolyshape with properties:
NumRegions: 1
NumHoles: 0
Geometry: "polygon"
CoordinateSystemType: "geographic"
GeographicCRS: []
>> pgon = polyshape([0 0 2 2],[2 0 0 2]);
>> p = plot(pgon,'FaceColor','red','FaceAlpha',0.1);
>> p.Shape
ans =
polyshape with properties:
Vertices: [4×2 double]
NumRegions: 1
NumHoles: 0
as you can see pg.ShapeData or any other field that I checked does not enable me to easily update the geoplot by updating the coords of vertices. Whereas for polyshape, I can do that as I have mentioned in my original post.
So my question is: how can I modify the geoplot of a geopolyshape, without replotting it?
thanks,
Murat

请先登录,再进行评论。


Kelly Kearney
Kelly Kearney 2025-8-16,0:11
编辑:Kelly Kearney 2025-8-16,0:11
Old question, but I was working through this same problem when needing to reproject a mappolyshape. It appears that the vertex coordinates are hidden in the undocumented object properties InternalData.VertexCoordinateData1 and InternalData.VertexCoordinateData2. They appear to be modifiable*.
shape = geopolyshape([1 10 1 1],[1 1 10 1]);
geoplot(shape);
hold on
shape.InternalData.VertexCoordinate2 = [1 1 5 1];
geoplot(shape, 'r')
*usual disclaimer that undocumented stuff is liable to change and thus break code. I tested this to R2023a and the Answers site used 2024b to render this.

标签

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by