Problem reading PolygonZ shapefiles

271 views
Skip to first unread message

jxb5000

unread,
Apr 17, 2012, 7:35:39 AM4/17/12
to Geospatial Python
Hello-
I am trying to use pyshp 1.1.4 Python library to read 3-D polygon
shapefiles (XYZ for each vertex).

This form of shapefile is described in "PolygonZ" section, p. 18, ESRI
Shapefile Technical Description, July 1998.

Everything is fine with 2-D shapefiles:
>>> shapes = shapefile.Reader("areas2d.shp").shapes()
(no errors here)

But with 3-D shapefile, this happens:
>>> shapes = shapefile.Reader("areas3d.shp").shapes()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/cygdrive/z/temp/pyshp-1.1.4/shapefile.py", line 310, in
shapes
shapes.append(self.__shape())
File "/cygdrive/z/temp/pyshp-1.1.4/shapefile.py", line 252, in
__shape
(mmin, mmax) = unpack("<2d", f.read(16))
File "/usr/lib/python2.5/struct.py", line 87, in unpack
return o.unpack(s)
struct.error: unpack requires a string argument of length 16

Environment details: Windows XP SP3, Python 2.5, 2-D and 3-D
shapefiles produced with GlobalMapper 12.

Thank you.

michail xyntarakis

unread,
Apr 17, 2012, 10:19:49 AM4/17/12
to geospati...@googlegroups.com
Hi,

I too have found the pyshp library to be buggy.

It seems that the problem is on the following line. When you read a 2D polygon you need 2 values of eight bytes each. When you read a 3D polygon you may need 3 values.

> (mmin, mmax) = unpack("<2d", f.read(16))

If I have time I will take a closer look at the issue. By the way, how do you know that I have used the library?

Michail

Joel Lawhead

unread,
Apr 17, 2012, 11:23:04 AM4/17/12
to Geospatial Python
Thanks for the feedback. I'll look into it. If you can send me a
sample shapefile that will help. The 3D features (and the measure
features) still have some bugs as they these types of shapefile are
not as common as 2D.

Thanks,
Joel

Joel Lawhead

unread,
Apr 17, 2012, 11:23:23 AM4/17/12
to Geospatial Python
Can you send me a sample shapefile?

- Joel

Joel Lawhead

unread,
Apr 17, 2012, 11:36:52 AM4/17/12
to Geospatial Python
This problem must have something to do with reading polygon
shapefiles. I just tried the z values on a 3D bathymetry point
shapefile from the University of Hawaii and it worked. I'll keep
looking for a sample but if you all could send me one that would
really help.

- Joel

On Apr 17, 6:35 am, jxb5000 <jxb5...@gmail.com> wrote:

jxb

unread,
Apr 17, 2012, 1:27:11 PM4/17/12
to Geospatial Python
Joel- Yes, I can send a PolygonZ shapefile. Thank you for looking
into this. I am not sure how to send an attachment though. Let me
look into that....

Thanks,
John

On Apr 17, 11:36 am, Joel Lawhead <jlawh...@geospatialpython.com>
wrote:
> > Thank you.- Hide quoted text -
>
> - Show quoted text -

jxb

unread,
Apr 17, 2012, 2:18:03 PM4/17/12
to Geospatial Python, jxb
Ah, I see how to send attachment. First time on Google Groups,
sorry... I will send PolygonZ shapefile later today.
> > - Show quoted text -- Hide quoted text -

Joel Lawhead

unread,
Apr 17, 2012, 2:23:22 PM4/17/12
to Geospatial Python, jxb
Thanks!

--
Joel Lawhead, PMP
NVision Solutions Inc.
Phone: 228-242-0014
Fax: 228-242-0013
Cell: 228-342-1891
Email: jlaw...@nvs-inc.com
Web: http://www.nvs-inc.com

Reply all
Reply to author
Forward
0 new messages