Jaakko Salli wrote:
> [EMAIL PROTECTED] wrote:
>>> Jaakko Salli wrote:
>>>> Brent Pedersen wrote:
>>>>> On Wed, Jun 25, 2008 at 8:52 AM, Jaakko Salli <[EMAIL PROTECTED]>
>>>>> wrote:
>>>>>> Hi all,
>>>>>>
>>>>>> I have encountered strange problem with Polygon.contains(Point). It
>>>>>> seems it stops functioning correctly after being called 21 times. At
>>>>>> that point, instead of checking if point is inside the polygon, it
>>>>>> just
>>>>>> check if it is inside polygon's bounding box.
>>>>>>
>>>>>> Here is code to reproduce the issue (I have tried it with Python 2.5.2
>>>>>> and Shapely SVN trunk):
>>>>>>
>>>>>> from shapely.geometry import Point, Polygon
>>>>>>
>>>>>> # Form a 'L' shaped polygon
>>>>>> points = [(0.0, 0.0),
>>>>>>          (1.0, 0.0),
>>>>>>          (1.0, 1.0),
>>>>>>          (2.0, 1.0),
>>>>>>          (2.0, 2.0),
>>>>>>          (0.0, 2.0),
>>>>>>          (0.0, 0.0)]
>>>>>>
>>>>>> poly = Polygon(points)
>>>>>>
>>>>>> # Create point that should be outside polygon, but
>>>>>> # inside its bounding box
>>>>>> pt_outside_but_inside_bbox = Point(1.5, 0.5)
>>>>>>
>>>>>> # Create point that should be outside polygon,
>>>>>> # even outside its bounding box
>>>>>> pt_outside_even_bbox = Point(2.5, 0.5)
>>>>>>
>>>>>> # At iteration number 22, poly.contains effectively becomes
>>>>>> # poly_bounding_box.contains
>>>>>> for i in range(1,100):
>>>>>>    res1 = poly.contains(pt_outside_but_inside_bbox)
>>>>>>    res2 = poly.contains(pt_outside_even_bbox)
>>>>>>    print '#%i: poly.contains(pt_outside_but_inside_bbox) = %s'%(i,
>>>>>> res1)
>>>>>>    print '     poly.contains(pt_outside_even_bbox) = %s'%(res2)
>>>>>>    if res1 != False:
>>>>>>        print "poly.contains failed at try #%i!"%(i)
>>>>>>        break
>>>>>>
>>>>>>
>>>>>> Thanks,
>>>>>>  Jaakko Salli
>>>>>>
>>>>>>
>>>>>> _______________________________________________
>>>>>> Community mailing list
>>>>>> [email protected]
>>>>>> http://lists.gispython.org/mailman/listinfo/community
>>>>>>
>>>>> thankfully, i dont see this with r1117. that scared me.
>>>>> even upped the range to 100K and no problems.
>>>>> fwiw, i'm using geos 3.0.0, not an rc...
>>>> I'm using the geos DLL provided with the Windows installer
>>>> (also using Windows XP SP2, if that matters).
>>> I have now built geos 3.0.0 DLL with msys+MingW32. Seems to have fixed
>>> the issue.
>>>
>>> Sorry for bothering :)
>>>
>>> Thanks,
>>>   Jaakko
>> Jaakko, would you be willing to put that DLL online so I can download and
>> compare it to the one I am distributing?
> Here you go:
> 
> http://personal.inet.fi/private/jmsalli/geos_dlls.zip
> 
> I didn't use any configure options, but did run 'strip -d' after make was
> done.
> 
> Jaakko

Jaakko,

I'm back in my office, trying to reproduce the problem, and have run
into something that disturbs me ...

Save the attached doctest file and run it like

  >>> import doctest
  >>> doctest.testfile('ops-repeat.txt')

On Linux (w/ Python 2.5, GEOS 3.0) the test passes. The test also passes
when I use your new DLLs. I can confirm that if I use the geos.dll I
have been distributing, the test fails on the 22nd interation. I have no
idea WTF is going on in that case :(

I'm not a Windows platform expert at all ... will your DLLs work on all
Win32 systems? I'm testing on Windows 2000 here.

Cheers,
Sean

    >>> from shapely.geometry import Point, Polygon

Form a 'L' shaped polygon

    >>> points = [(0.0, 0.0),
    ...           (1.0, 0.0),
    ...           (1.0, 1.0),
    ...           (2.0, 1.0),
    ...           (2.0, 2.0),
    ...           (0.0, 2.0),
    ...           (0.0, 0.0)]

    >>> poly = Polygon(points)

Create point that should be outside polygon, but
inside its bounding box

    >>> pt_outside_but_inside_bbox = Point(1.5, 0.5)

Create point that should be outside polygon,
even outside its bounding box

    >>> pt_outside_even_bbox = Point(2.5, 0.5)

At iteration number 22, poly.contains effectively becomes
poly_bounding_box.contains

    >>> for i in range(30):
    ...     res1 = poly.contains(pt_outside_but_inside_bbox)
    ...     if res1 != False:
    ...         print "poly.contains failed at try #%d!" % i
    ...         print "%s" % poly
    ...         print "%s" % pt_outside_but_inside_bbox
    ...         print "Containment: ", poly.contains(pt_outside_but_inside_bbox)
    ...         print "Intersection: ", 
poly.intersects(pt_outside_but_inside_bbox)
    ...         break
    
_______________________________________________
Community mailing list
[email protected]
http://lists.gispython.org/mailman/listinfo/community

Reply via email to