Discussion:
[Community] shapely: unable to get numpy array from linestring geometry
Matthew Perry
2007-09-13 05:32:35 UTC
Permalink
Hi all,

Trying to load some linestring geometries into shapely arrays and I'm
getting incorrect results:

ds = ogr.Open("/home/perry/Desktop/line1/line1.shp")
lyr = ds.GetLayer(0)
feat = lyr.GetFeature(0)
geom = loads(feat.GetGeometryRef().ExportToWkb())
print type(geom)
print geom.wkt
line = asarray(geom)
print type(line)
print line[0]


Which gives me:

<class 'shapely.geometry.linestring.LineString'>

LINESTRING (-118.1344542359263414 36.1719818088280292,
-118.0363326316767854 36.3323268694309576, -118.2253962105966565
36.3514725483089194, -118.3043721359682365 36.6578034103562942,
-118.167959173962\
7710 36.8205416808189625, -118.0578715204144942 36.8755855075931009,
-118.0650511499937352 37.0024256301595926, -118.2253962105966565
37.1220861231468504, -118.5173678134855635 37.0861879752506738, -11\
8.5317270726440313 37.0742219259519459, -118.5412999120830051
36.9617410625439291, -118.6657468247897640 36.8109688413799816,
-118.8931017614655445 36.6841287188134899, -118.8931017614655445
36.4926719\
300338789, -118.9170338600630004 36.3131811905529958,
-118.7064313924054204 36.2174527961631867, -118.6992517628261936
36.1336904510721055, -118.7878005276367617 36.0236027975238287,
-119.0031894150138\
214 35.9518065017314754, -119.0031894150138214 35.9518065017314754,
-119.1156702784218453 35.9877046496276520)

<type 'numpy.ndarray'>

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/tmp/python-9523EYK.py", line 241, in <module>
print line[0]
IndexError: 0-d arrays can't be indexed


Any ideas why the linestring geometry is not properly converted to a
numpy array?
--
Matthew T. Perry
http://www.perrygeo.net

"You never change things by fighting the existing reality.
To change something, build a new model that makes
the existing model obsolete" - R. Buckminster Fuller
Sean Gillies
2007-09-13 14:42:11 UTC
Permalink
Post by Matthew Perry
Hi all,
Trying to load some linestring geometries into shapely arrays and I'm
ds = ogr.Open("/home/perry/Desktop/line1/line1.shp")
lyr = ds.GetLayer(0)
feat = lyr.GetFeature(0)
geom = loads(feat.GetGeometryRef().ExportToWkb())
print type(geom)
print geom.wkt
line = asarray(geom)
print type(line)
print line[0]
<class 'shapely.geometry.linestring.LineString'>
LINESTRING (-118.1344542359263414 36.1719818088280292,
-118.0363326316767854 36.3323268694309576, -118.2253962105966565
36.3514725483089194, -118.3043721359682365 36.6578034103562942,
-118.167959173962\
7710 36.8205416808189625, -118.0578715204144942 36.8755855075931009,
-118.0650511499937352 37.0024256301595926, -118.2253962105966565
37.1220861231468504, -118.5173678134855635 37.0861879752506738, -11\
8.5317270726440313 37.0742219259519459, -118.5412999120830051
36.9617410625439291, -118.6657468247897640 36.8109688413799816,
-118.8931017614655445 36.6841287188134899, -118.8931017614655445
36.4926719\
300338789, -118.9170338600630004 36.3131811905529958,
-118.7064313924054204 36.2174527961631867, -118.6992517628261936
36.1336904510721055, -118.7878005276367617 36.0236027975238287,
-119.0031894150138\
214 35.9518065017314754, -119.0031894150138214 35.9518065017314754,
-119.1156702784218453 35.9877046496276520)
<type 'numpy.ndarray'>
File "<stdin>", line 1, in <module>
File "/tmp/python-9523EYK.py", line 241, in <module>
print line[0]
IndexError: 0-d arrays can't be indexed
Any ideas why the linestring geometry is not properly converted to a
numpy array?
I just added the following test


http://trac.gispython.org/projects/PCL/browser/Shapely/trunk/tests/LineString.txt#L27

and it passes. Can you give me more information? Print out

geom.geom_type
geom.coords
geom.__array_interface__
line

before you print line[0]. Which of the alpha versions are you using?

Cheers,
Sean
Matthew Perry
2007-09-13 17:23:43 UTC
Permalink
Sean,

Thanks for helping me out with this. I've printed the info below and
attached my test shapefile....
Post by Sean Gillies
Post by Matthew Perry
Any ideas why the linestring geometry is not properly converted to a
numpy array?
Can you give me more information? Print out
geom.geom_type
LineString
Post by Sean Gillies
geom.coords
<shapely.geometry.base.CoordinateSequence object at 0x8afc14c>
Post by Sean Gillies
line # should be a numpy array
LINESTRING (-118.1344542359263414 36.1719818088280292,
-118.0363326316767854 36.3323268694309576, -118.2253962105966565
36.3514725483089194, -118.3043721359682365 36.6578034103562942,
-118.1679591739627\
710 36.8205416808189625, -118.0578715204144942 36.8755855075931009,
-118.0650511499937352 37.0024256301595926, -118.2253962105966565
37.1220861231468504, -118.5173678134855635 37.0861879752506738, -118.\
5317270726440313 37.0742219259519459, -118.5412999120830051
36.9617410625439291, -118.6657468247897640 36.8109688413799816,
-118.8931017614655445 36.6841287188134899, -118.8931017614655445
36.4926719300\
338789, -118.9170338600630004 36.3131811905529958,
-118.7064313924054204 36.2174527961631867, -118.6992517628261936
36.1336904510721055, -118.7878005276367617 36.0236027975238287,
-119.0031894150138214 \
35.9518065017314754, -119.0031894150138214 35.9518065017314754,
-118.9749086902324393 36.1107213805937803)
Post by Sean Gillies
geom.__array_interface__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/tmp/python-738I1s.py", line 272, in <module>
print geom.__array_interface__
File "build/bdist.linux-i686/egg/shapely/geometry/linestring.py",
line 164, in __array_interface__
File "build/bdist.linux-i686/egg/shapely/geometry/linestring.py",
line 144, in ctypes
TypeError: unsupported operand type(s) for *: 'int' and 'NoneType'
Post by Sean Gillies
before you print line[0]. Which of the alpha versions are you using?
I'm using svn, revision 874. I had the same issue with alpha2.
--
Matthew T. Perry
http://www.perrygeo.net

"You never change things by fighting the existing reality.
To change something, build a new model that makes
the existing model obsolete" - R. Buckminster Fuller
-------------- next part --------------
A non-text attachment was scrubbed...
Name: line1.zip
Type: application/zip
Size: 1923 bytes
Desc: not available
URL: <http://lists.gispython.org/pipermail/community/attachments/20070913/8c02cea9/attachment.zip>
Sean Gillies
2007-09-13 17:37:21 UTC
Permalink
Post by Matthew Perry
Sean,
Thanks for helping me out with this. I've printed the info below and
attached my test shapefile....
Post by Sean Gillies
Post by Matthew Perry
Any ideas why the linestring geometry is not properly converted to a
numpy array?
Can you give me more information? Print out
geom.geom_type
LineString
Post by Sean Gillies
geom.coords
<shapely.geometry.base.CoordinateSequence object at 0x8afc14c>
Post by Sean Gillies
line # should be a numpy array
LINESTRING (-118.1344542359263414 36.1719818088280292,
-118.0363326316767854 36.3323268694309576, -118.2253962105966565
36.3514725483089194, -118.3043721359682365 36.6578034103562942,
-118.1679591739627\
710 36.8205416808189625, -118.0578715204144942 36.8755855075931009,
-118.0650511499937352 37.0024256301595926, -118.2253962105966565
37.1220861231468504, -118.5173678134855635 37.0861879752506738, -118.\
5317270726440313 37.0742219259519459, -118.5412999120830051
36.9617410625439291, -118.6657468247897640 36.8109688413799816,
-118.8931017614655445 36.6841287188134899, -118.8931017614655445
36.4926719300\
338789, -118.9170338600630004 36.3131811905529958,
-118.7064313924054204 36.2174527961631867, -118.6992517628261936
36.1336904510721055, -118.7878005276367617 36.0236027975238287,
-119.0031894150138214 \
35.9518065017314754, -119.0031894150138214 35.9518065017314754,
-118.9749086902324393 36.1107213805937803)
Post by Sean Gillies
geom.__array_interface__
File "<stdin>", line 1, in <module>
File "/tmp/python-738I1s.py", line 272, in <module>
print geom.__array_interface__
File "build/bdist.linux-i686/egg/shapely/geometry/linestring.py",
line 164, in __array_interface__
File "build/bdist.linux-i686/egg/shapely/geometry/linestring.py",
line 144, in ctypes
TypeError: unsupported operand type(s) for *: 'int' and 'NoneType'
Post by Sean Gillies
before you print line[0]. Which of the alpha versions are you using?
I'm using svn, revision 874. I had the same issue with alpha2.
Matt,

I found and fixed a bug. Try updating to r875?

I'll be offline the rest of the day but will check in later tonight.

Cheers,
Sean
Matthew Perry
2007-09-14 03:13:24 UTC
Permalink
Sean,

r875 did the trick. Thanks.

-m
Post by Sean Gillies
Post by Matthew Perry
Sean,
Thanks for helping me out with this. I've printed the info below and
attached my test shapefile....
Post by Sean Gillies
Post by Matthew Perry
Any ideas why the linestring geometry is not properly converted to a
numpy array?
Can you give me more information? Print out
geom.geom_type
LineString
Post by Sean Gillies
geom.coords
<shapely.geometry.base.CoordinateSequence object at 0x8afc14c>
Post by Sean Gillies
line # should be a numpy array
LINESTRING (-118.1344542359263414 36.1719818088280292,
-118.0363326316767854 36.3323268694309576, -118.2253962105966565
36.3514725483089194, -118.3043721359682365 36.6578034103562942,
-118.1679591739627\
710 36.8205416808189625, -118.0578715204144942 36.8755855075931009,
-118.0650511499937352 37.0024256301595926, -118.2253962105966565
37.1220861231468504, -118.5173678134855635 37.0861879752506738, -118.\
5317270726440313 37.0742219259519459, -118.5412999120830051
36.9617410625439291, -118.6657468247897640 36.8109688413799816,
-118.8931017614655445 36.6841287188134899, -118.8931017614655445
36.4926719300\
338789, -118.9170338600630004 36.3131811905529958,
-118.7064313924054204 36.2174527961631867, -118.6992517628261936
36.1336904510721055, -118.7878005276367617 36.0236027975238287,
-119.0031894150138214 \
35.9518065017314754, -119.0031894150138214 35.9518065017314754,
-118.9749086902324393 36.1107213805937803)
Post by Sean Gillies
geom.__array_interface__
File "<stdin>", line 1, in <module>
File "/tmp/python-738I1s.py", line 272, in <module>
print geom.__array_interface__
File "build/bdist.linux-i686/egg/shapely/geometry/linestring.py",
line 164, in __array_interface__
File "build/bdist.linux-i686/egg/shapely/geometry/linestring.py",
line 144, in ctypes
TypeError: unsupported operand type(s) for *: 'int' and 'NoneType'
Post by Sean Gillies
before you print line[0]. Which of the alpha versions are you using?
I'm using svn, revision 874. I had the same issue with alpha2.
Matt,
I found and fixed a bug. Try updating to r875?
I'll be offline the rest of the day but will check in later tonight.
Cheers,
Sean
_______________________________________________
Community mailing list
Community at lists.gispython.org
http://lists.gispython.org/mailman/listinfo/community
--
Matthew T. Perry
http://www.perrygeo.net

"You never change things by fighting the existing reality.
To change something, build a new model that makes
the existing model obsolete" - R. Buckminster Fuller
sgillies
2007-09-14 06:23:08 UTC
Permalink
You're welcome.
Post by Matthew Perry
Sean,
r875 did the trick. Thanks.
-m
Post by Sean Gillies
Post by Matthew Perry
Sean,
Thanks for helping me out with this. I've printed the info below and
attached my test shapefile....
Post by Sean Gillies
Post by Matthew Perry
Any ideas why the linestring geometry is not properly converted to a
numpy array?
Can you give me more information? Print out
geom.geom_type
LineString
Post by Sean Gillies
geom.coords
<shapely.geometry.base.CoordinateSequence object at 0x8afc14c>
Post by Sean Gillies
line # should be a numpy array
LINESTRING (-118.1344542359263414 36.1719818088280292,
-118.0363326316767854 36.3323268694309576, -118.2253962105966565
36.3514725483089194, -118.3043721359682365 36.6578034103562942,
-118.1679591739627\
710 36.8205416808189625, -118.0578715204144942 36.8755855075931009,
-118.0650511499937352 37.0024256301595926, -118.2253962105966565
37.1220861231468504, -118.5173678134855635 37.0861879752506738, -118.\
5317270726440313 37.0742219259519459, -118.5412999120830051
36.9617410625439291, -118.6657468247897640 36.8109688413799816,
-118.8931017614655445 36.6841287188134899, -118.8931017614655445
36.4926719300\
338789, -118.9170338600630004 36.3131811905529958,
-118.7064313924054204 36.2174527961631867, -118.6992517628261936
36.1336904510721055, -118.7878005276367617 36.0236027975238287,
-119.0031894150138214 \
35.9518065017314754, -119.0031894150138214 35.9518065017314754,
-118.9749086902324393 36.1107213805937803)
Post by Sean Gillies
geom.__array_interface__
File "<stdin>", line 1, in <module>
File "/tmp/python-738I1s.py", line 272, in <module>
print geom.__array_interface__
File "build/bdist.linux-i686/egg/shapely/geometry/linestring.py",
line 164, in __array_interface__
File "build/bdist.linux-i686/egg/shapely/geometry/linestring.py",
line 144, in ctypes
TypeError: unsupported operand type(s) for *: 'int' and 'NoneType'
Post by Sean Gillies
before you print line[0]. Which of the alpha versions are you using?
I'm using svn, revision 874. I had the same issue with alpha2.
Matt,
I found and fixed a bug. Try updating to r875?
I'll be offline the rest of the day but will check in later tonight.
Cheers,
Sean
_______________________________________________
Community mailing list
Community at lists.gispython.org
http://lists.gispython.org/mailman/listinfo/community
--
Matthew T. Perry
http://www.perrygeo.net
"You never change things by fighting the existing reality.
To change something, build a new model that makes
the existing model obsolete" - R. Buckminster Fuller
_______________________________________________
Community mailing list
Community at lists.gispython.org
http://lists.gispython.org/mailman/listinfo/community
Loading...