How to identify points that are located in a polygon when this polygon passes through the meridian?
2 次查看(过去 30 天)
显示 更早的评论
I have a polygon presented by a series of longitude and latitude degrees. The longitude of this polygon is presented by degrees of [0 360] and it passes through the meridian. Also, I have two points and I need to check whether these points are located in this polygon.
For example, the longitude and latitude of this polygon is
PGlon = [5 5 355 355 5]; PGlat = [30 40 40 30 30];
and the points are
Xlon = [0 10]; Xlat = [35 45];
The positions of the polygon and points are as this figure (the first point is located inside this polygon).
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/200168/image.png)
I know that the function "inpolygon" may help to solve this problem, and I do
in_flag = inpolygon(Xlat,Xlon,PGlat,PGlon);
But this function cannot recognize whether the polygon crosses the meridian, so both points are identified to be outside the polygon.
Is there any useful way to handle this problem? Thanks!
0 个评论
回答(1 个)
Are Mjaavatten
2019-1-5
编辑:Are Mjaavatten
2019-1-5
It seems that you are using the mapping toolbox, Then you can use ingeoquad:
ingeoquad([35,45],[0,10],[30 40], [355 5])
Your call to inpolygon checks if the points are inside a band spanning 350 degrees, which is not what you want. Use negative values for longitudes > 180:
inpolygon([35 45],[0 10],[30 40 40 30],[5 5 -5 -5])
2 个评论
Are Mjaavatten
2019-1-6
编辑:Are Mjaavatten
2019-1-6
Just create a polygon from the border points. inpolygon will work for any polygon, even if it is not convex. Example:
xb = [0 1 1 0.5 0];
yb = [0 0 1 0.5 1];
figure;
patch(xb,yb,[1,1,1]*0.9);
inside = inpolygon(x,y,xb,yb);
hold on
plot(x(inside),y(inside),'*r')
plot(x(~inside),y(~inside),'ok')
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!