Re: Finding a points inside polygon [message #32629] |
Thu, 24 October 2002 08:17  |
James Kuyper
Messages: 425 Registered: March 2000
|
Senior Member |
|
|
James Kuyper wrote:
>
> Gunho Sohn wrote:
>>
>> Dear All,
>>
>> I have a problem to determine whether a point (x,y) is inside the polygon.
>> Simply I've used IDLanROI::ContainsPoints method in my code. However, it
>> seems to make a serious problem. Please, check this problem together. I used
>> following polygons and point
>>
>> polygon vertices (vx,vy):
>> vx=[35.859278 55.591451 155.00000 155.00000]
>> vy=[0.00000000 0.00000000 19.279154 23.105984]
>>
>> point (x,y):
>> x=122.87897 y=13.049367
>>
>> When I simply coded this as follows, it printes as 0 which means this point
>> is located outside of polygon. But, it is not!
By the way, the range of values you were using made me wonder - by any
chance are those values geographic latitudes and longitudes? In that
case, you have to be very careful about how you define your polygon
edges. Each map projection constitutes a different definition of what it
means to be a "straight line". The most natural definition is that the
edges are great circle arcs. In that case, to see the boundaries of your
polygon properly, you need to use the gnomonic projection, because it's
the only one that maps all great circle arcs as straight lines. Try the
following:
IDL> map_set,21.0,92.0,/gnomic,/continents,/grid,/label,scale=2e8
IDL> oplot,vx,vy
That will give you the overview of the problem. To get down to the
details, use:
IDL> map_set,13.049367,122.87897,/gnomic,/hires,/grid,/label,scal e=2e7
IDL> oplot,vx,vy
IDL> plots,122.87897,13.049367, psym=2
So, if these are latitude-longitude values connected by great circle
arcs, the specified point is not merely outside the polygon, it's
hundreds of miles outside the polygon.
|
|
|
Re: Finding a points inside polygon [message #32630 is a reply to message #32629] |
Thu, 24 October 2002 07:47   |
James Kuyper
Messages: 425 Registered: March 2000
|
Senior Member |
|
|
Gunho Sohn wrote:
>
> Dear All,
>
> I have a problem to determine whether a point (x,y) is inside the polygon.
> Simply I've used IDLanROI::ContainsPoints method in my code. However, it
> seems to make a serious problem. Please, check this problem together. I used
> following polygons and point
>
> polygon vertices (vx,vy):
> vx=[35.859278 55.591451 155.00000 155.00000]
> vy=[0.00000000 0.00000000 19.279154 23.105984]
>
> point (x,y):
> x=122.87897 y=13.049367
>
> When I simply coded this as follows, it printes as 0 which means this point
> is located outside of polygon. But, it is not!
IDL> vx = [35.859278, 55.591451, 155.00000, 155.00000, 35.859278]
IDL> vy = [0.00000000, 0.00000000, 19.279154, 23.105984, 0.000000]
I added the extra point on the end, to close the polygon. ContainsPoint
doesn't need that closure, but the follow commands do:
IDL> plot,vx,vy
IDL> plots,[122.87897],[13.049367]
That's ambiguous - the point seems to be right on the edge.
IDL> plot,vx,vy,xrange=[122,123],yrange=[13,14]
IDL> plots,[122.87897],[13.049367],psym=1
That doesn't help; it's still ambiguous.
IDL> plot,vx,vy,xrange=[122.87,122.88],yrange=[13.04,13.05]
IDL> plots,[122.87897],[13.049367]
Finally! That looks to me like the point is slightly, but definitely,
outside of the polygon. ContainsPoint is apparantly correct.
|
|
|
Re: Finding a points inside polygon [message #32646 is a reply to message #32630] |
Thu, 24 October 2002 14:06  |
Pavel A. Romashkin
Messages: 531 Registered: November 2000
|
Senior Member |
|
|
I plotted the polygon and the point as you specify. It looks to me that
the point does lie outside the polygon, some 0.0001x and 0.001y to the
right and below the border, to be exact. Check the coordinates, make
sure the floating point precision does not play a joke on you.
David's INSIDE returns zero also.
Make sure your polygon is closed:
vx = [vx, [vx[0]]
vy = [vy, vy[0]]
IDL> print, inside(x, y, vx, vy)
0
So I suspect that there is nothing wrong with the ROI object in this case.
Good luck,
Pavel
Gunho Sohn wrote:
>
> polygon vertices (vx,vy):
> vx=[35.859278 55.591451 155.00000 155.00000]
> vy=[0.00000000 0.00000000 19.279154 23.105984]
>
> point (x,y):
> x=122.87897 y=13.049367
>
> When I simply coded this as follows, it printes as 0 which means this point
> is located outside of polygon. But, it is not!
> o_poly=obj_new('IDLanROI', vx,vy)
> print, o_poly->ContainsPoints(x,y)
>
> I compared this using fanning's inside.pro, as I expected 'inside.pro' said
> this point is in the polygon.
>
> Do I something wrong using IDLanROI object?
>
> I hope to hear anything from you soon.
>
> Many thanks,
>
> Gunho
|
|
|