#3 Problem determining if point is in a polygon

open
nobody
None
5
2009-11-19
2009-11-19
Tim Anderson
No

I'm trying to determine if a geographic coordinate is within an image which is defined by four geographic coordinates in decimal degrees with the Southern and Western Hemispheres being negative.

I tried a simple test to see if there was something going on with the decimal degrees and just used about as easy a test case as I could think of (see attachment for code fragment). When I tested p.within (polygon) or polygon.contains (p), both returned false.

I must be doing something wrong because I can't imagine that a square polygon with 2 units on a side somehow does not contain a point at (1, 1).

Discussion

  • Tim Anderson
    Tim Anderson
    2009-11-19

    Sample Java code

     
    Attachments
  • Tim Anderson
    Tim Anderson
    2009-11-19

    I entered my geographic coordinates into a test case for TestBuilder and both contains() and within() returned true for the respective Geometry's.

     
  • Tim Anderson
    Tim Anderson
    2009-11-20

    In my original code, I realized that I was using a LineString instead of a Polygon, so I changed it in my method to test if a Point was in a Polygon and got the same results.