zhikrullah / pyshp

Automatically exported from code.google.com/p/pyshp
MIT License
0 stars 0 forks source link

Editor Fails Writing POINTZ Shapefile #27

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create a POINTZ shapefile using a `Writer()`
2. Attempt to append to the shapefile using an `Editor()`, specifying the 
filename in Editor constructor
3. Write fails with the following exception:

{{{
Traceback (most recent call last):
  File "/Users/driggs2/workspace/batutils/batutils/transect/tkgui_pro.py", line 270, in go
    transect.main()
  File "/Users/driggs2/workspace/batutils/batutils/transect/app.py", line 281, in main
    self._finalize()
  File "/Users/driggs2/workspace/batutils/batutils/transect/app_pro.py", line 90, in _finalize
    self.w.save(self.outfile)
  File "/Users/driggs2/workspace/batutils/batutils/transect/shapefile.py", line 862, in save
    self.saveShp(target)
  File "/Users/driggs2/workspace/batutils/batutils/transect/shapefile.py", line 829, in saveShp
    self.__shapefileHeader(self.shp, headerType='shp')
  File "/Users/driggs2/workspace/batutils/batutils/transect/shapefile.py", line 596, in __shapefileHeader
    raise ShapefileException("Failed to write shapefile elevation and measure values. Floats required.")
ShapefileException: Failed to write shapefile elevation and measure values. 
Floats required.
}}}

What is the expected output? What do you see instead?

What version of the product are you using? On what operating system?
  pyshp 1.1.4
  Python 2.6.6 (Apple)
  Mac OS X 10.6.8

Please provide any additional information below.

Writing the shapefile as POINT rather than POINTZ works correctly.

The above exception itself is due to the Editor's Writer trying to write an "m" 
value of None. For some reason, `Editor.point()` has a different method 
signature than `Writer.point()`, and the former assigns a default value of None 
for "m" and "z", while the latter assigns default value of 0. Changing the 
method signature of `Editor.point()` to use default values m=0, z=0 appears to 
solve the above exception, but still fails later with:

{{{
Traceback (most recent call last):
  File "/Users/driggs2/workspace/batutils/batutils/transect/tkgui_pro.py", line 270, in go
    transect.main()
  File "/Users/driggs2/workspace/batutils/batutils/transect/app.py", line 281, in main
    self._finalize()
  File "/Users/driggs2/workspace/batutils/batutils/transect/app_pro.py", line 93, in _finalize
    self.w.save(self.outfile)
  File "/Users/driggs2/workspace/batutils/batutils/transect/shapefile.py", line 862, in save
    self.saveShp(target)
  File "/Users/driggs2/workspace/batutils/batutils/transect/shapefile.py", line 830, in saveShp
    self.__shpRecords()
  File "/Users/driggs2/workspace/batutils/batutils/transect/shapefile.py", line 699, in __shpRecords
    f.write(pack("<1d", s.points[0][2]))
IndexError: array index out of range
}}}

Again, I solved my own immediate problem by using POINT type rather than 
POINTZ, but it looks like pyshp may have some more bugs related to editing 
POINTZ types.

Original issue reported on code.google.com by david.ri...@myotisoft.com on 25 Feb 2012 at 8:54

GoogleCodeExporter commented 8 years ago
After refreshing my local copy from a pristine SVN checkout, I see that this 
editor bug applies even to POINT types. The bug is that `Editor.point()` 
defaults "z" and "m" values to None, which causes the following exception:

{{{
Traceback (most recent call last):
  File "testcase.py", line 38, in <module>
    test()
  File "testcase.py", line 25, in test
    e.save(FNAME2)
  File "/Users/driggs2/tmp/pyshp/shapefile.py", line 862, in save
    self.saveShp(target)
  File "/Users/driggs2/tmp/pyshp/shapefile.py", line 829, in saveShp
    self.__shapefileHeader(self.shp, headerType='shp')
  File "/Users/driggs2/tmp/pyshp/shapefile.py", line 596, in __shapefileHeader
    raise ShapefileException("Failed to write shapefile elevation and measure values. Floats required.")
shapefile.ShapefileException: Failed to write shapefile elevation and measure 
values. Floats required.
}}}

The signature of `Editor.point()` should be changed to:

`def point(self, x=None, y=None, z=0, m=0, shape=None, part=None, point=None, 
addr=None)`

Original comment by david.ri...@myotisoft.com on 25 Feb 2012 at 10:44

GoogleCodeExporter commented 8 years ago

Original comment by jlawh...@gmail.com on 28 Feb 2012 at 5:23