Ok I got it: converting the array to a list and then zipping will do the trick.
------------------------------------------------------
from shapely.geometry import MultiPoint
import numpy

parr = numpy.zeros((6,6))
parr[0,0] = 1
parr[0,2] = 1
parr[3,3] = 1
print 'parr=',parr
points = numpy.where(parr>0)
print 'points=',points
plist = numpy.vstack(points).tolist()
print 'plist=',plist
points_good = zip(plist[0],plist[1])
print 'points_good=',points_good
mp = MultiPoint(points_good)
print 'list=',list((p.x,p.y) for p in mp.geoms)
------------------------------------------------------
parr= [[ 1.  0.  1.  0.  0.  0.]
 [ 0.  0.  0.  0.  0.  0.]
 [ 0.  0.  0.  0.  0.  0.]
 [ 0.  0.  0.  1.  0.  0.]
 [ 0.  0.  0.  0.  0.  0.]
 [ 0.  0.  0.  0.  0.  0.]]
points= (array([0, 0, 3]), array([0, 2, 3]))
plist= [[0, 0, 3], [0, 2, 3]]
points_good= [(0, 0), (0, 2), (3, 3)]
list= [(0.0, 0.0), (0.0, 2.0), (3.0, 3.0)]
-------------------------------------------------------

I was working directly with array because I have to create a lot of
objects and I was hoping to speed things up a bit: as always premature
optimization is the root of all evil :)

Anyway if someone still happen to know why it is not working with
arrays or how to quickly convert binary images in shape objects I'd
love to hear it!

Thanks and regards

Mario

On Sun, Aug 17, 2008 at 1:57 PM, Mario Ceresa
<[EMAIL PROTECTED]> wrote:
> Hello again,
> Apparently I found that using dtype=float instead of numpy.float32
> better the whole thing:
> -------------------------------------------------------
> [[ 1.  0.  1.  0.  0.  0.]
>  [ 0.  0.  0.  0.  0.  0.]
>  [ 0.  0.  0.  0.  0.  0.]
>  [ 0.  0.  0.  1.  0.  0.]
>  [ 0.  0.  0.  0.  0.  0.]
>  [ 0.  0.  0.  0.  0.  0.]]
> (array([0, 0, 3]), array([0, 2, 3]))
> [[ 0.  0.]
>  [ 0.  2.]
>  [ 3.  3.]]
> [(0.0, 0.0), (3.0, 0.0), (2.0, 3.0)]
> ---------------------------------------------------------
> so probably the last error was a casting problem (float32->float64).
> Still I'd love to obtain [(0.0, 0.0), (0.0, 2.0), (3.0, 3.0)] as
> coordinates in the multpoint...
> It looks likes it is reading vertically column-by-column. Maybe
> numpy.transpose() was a bad idea?
>
> *perplexed*
>
> Mario
>
> PS: BTW I use numpy 1.1.1
>
> On Sun, Aug 17, 2008 at 1:17 PM, Mario Ceresa
> <[EMAIL PROTECTED]> wrote:
>> Hi all,
>> first thanks you all for shapely: I've just started using it and it's
>> a wonderful product!
>> But there is a things that leaves me puzzled: whenever i run the following 
>> code
>>
>> -------------------
>> from shapely.geometry import MultiPoint
>> import numpy
>>
>> parr = numpy.zeros((6,6))
>> parr[0,0] = 1
>> parr[0,2] = 1
>> parr[3,3] = 1
>> print parr
>> points = numpy.where(parr>0)
>> print points
>> points_trans = 
>> numpy.asarray(numpy.transpose(numpy.vstack(points)),dtype=numpy.float32)
>> print points_trans
>> mp = MultiPoint(points_trans)
>> print list((p.x,p.y) for p in mp.geoms)
>> ---------------------
>>
>> I'm expecting that values in points_trans and mp.geoms should be equals.
>> But this is actually the output I get:
>>
>> parr = [[ 1.  0.  1.  0.  0.  0.]
>>  [ 0.  0.  0.  0.  0.  0.]
>>  [ 0.  0.  0.  0.  0.  0.]
>>  [ 0.  0.  0.  1.  0.  0.]
>>  [ 0.  0.  0.  0.  0.  0.]
>>  [ 0.  0.  0.  0.  0.  0.]]
>>
>> points = (array([0, 0, 3]), array([0, 2, 3]))
>>
>> points_trans = [[ 0.  0.] [ 0.  2.] [ 3.  3.]]
>>
>> list = [(0.0, 5.325712092559326e-315), (32.000007629394531,
>> 1.6304166312761136e-322), (9.2814421247954897e-317,
>> 1.9762625833649862e-323)]
>>
>> This happen on fed core 9 -  x64 - python 2.5 -  Shapely 1.06, geos 3.0
>> and on RHEL5 x64 - python 2.4 - Shapely 1.06 - geos 3.0.
>> On this platform the last line is:
>>
>> list = [(0.0, 5.325712092559326e-315), (32.000007629394531,
>> 1.6304166312761136e-322), (2.4278924170566564e-315,
>> 2.4180091278772481e-315)]
>>
>> Basically I just want to take a binary image and create a shape object
>> which represent the image . Is there something that I got wrong? or a
>> simpler way to do it?
>>
>> Thanks and regards
>>
>> Mario Ceresa
_______________________________________________
Community mailing list
[email protected]
http://lists.gispython.org/mailman/listinfo/community

Reply via email to