[#191] pyshapelib update to swig 1.3.29 and unicode support

Date:
2006-10-06 16:05
Priority:
3
State:
Open
Submitted by:
Didrik Pinte (dpinte)
Assigned to:
Didrik Pinte (dpinte)
Category:
none
Version:
none
Summary:
pyshapelib update to swig 1.3.29 and unicode support

Detailed description
Here is the buggy patch.

Here are the two problems :

[1] this new version does not seem to be happy with unicode objects in place of str objects. When calling shapefile.ShapeFile(filename) from Thuban, the library complains about the type of the argument :

--------------------------------------------------------------------------
An unhandled exception occurred:
in method 'new_ShapeFile', argument 1 of type 'char *'
(please report to http://thuban.intevation.org/bugtracker.html)

Traceback (most recent call last):
File "/home/did/projets/python/thuban/current/thuban/Thuban/UI/mainwindow.py", line 297, in invoke_command
command.Execute(self.Context())
File "/home/did/projets/python/thuban/current/thuban/test/../Thuban/UI/command.py", line 121, in Execute
apply(self.function, (context,) + self.args + args, kw)
File "/home/did/projets/python/thuban/current/thuban/Thuban/UI/mainwindow.py", line 1072, in call_method
apply(getattr(context.mainwindow, methodname), args)
File "/home/did/projets/python/thuban/current/thuban/Thuban/UI/mainwindow.py", line 573, in AddLayer
store = self.application.Session().OpenShapefile(filename)
File "/home/did/projets/python/thuban/current/thuban/test/../Thuban/Model/session.py", line 296, in OpenShapefile
store = ShapefileStore(self, filename)
File "/home/did/projets/python/thuban/current/thuban/test/../Thuban/Model/data.py", line 204, in __init__
self._open_shapefile()
File "/home/did/projets/python/thuban/current/thuban/test/../Thuban/Model/data.py", line 207, in _open_shapefile
self.shapefile = shapelib.ShapeFile(self.FileName())
File "/home/did/projets/python/thuban/current/thuban/Thuban/../Lib/shapelib.py", line 73, in __init__
this = _shapelib.new_ShapeFile(*args)
TypeError: in method 'new_ShapeFile', argument 1 of type 'char *'
--------------------------------------------------------------------------

I've investigated the problem and found a workaround. In the Lib/shapelib.py, changing the args tuple at line 73 so that it contains only str objects and no more unicode ones solve the problem ... That's a bit strange. I've reported the problem on the swig-user mailing list but have received no answer at the moment.

[2] The second problem is really strange :

When calling the original libraries/pyshapelib/pytest.py, everything works fine BUT if you do the following, you get an error :

Original code :
--------------------------------------------------------------------
make_shapefile("testfile")
read_shapefile("testfile")
--------------------------------------------------------------------

Modified code causing the bug :
--------------------------------------------------------------------
make_shapefile("testfile")
import os
os.path.exists("testfile.shp")
read_shapefile("testfile")
--------------------------------------------------------------------
Output :

([10.0, 10.0, 0.0, 0.0], [20.0, 20.0, 0.0, 0.0])
[[(10.0, 10.0), (10.0, 20.0), (20.0, 20.0), (10.0, 10.0)]]
([0.0, 0.0, 0.0, 0.0], [40.0, 40.0, 0.0, 0.0])
[[(0.0, 0.0), (0.0, 40.0), (40.0, 40.0), (40.0, 0.0), (0.0, 0.0)], [(10.0, 10.0), (20.0, 10.0), (20.0, 20.0), (10.0, 20.0), (10.0, 10.0)]]
Traceback (most recent call last):
File "pytest.py", line 88, in ?
os.path.exists("testfile.shp")
File "/usr/lib/python2.4/posixpath.py", line 171, in exists
st = os.stat(path)
TypeError: shapefile already closed

It is like if the handle was closed but still kept some kind of reference on the previously opened shapefile.
Message  ↓
Date: 2007-11-30 23:56
Sender: Bernhard Reiter

Hmm, this is a patch, I think we should close the report
as Bram has already done other code.

Date: 2007-03-14 00:01
Sender: Bram de Greve

*sigh* /me should proofread my comments before submitting
... Ignore "says Unicode support should be OK." =)

Date: 2007-03-13 23:56
Sender: Bram de Greve

says Unicode support should be OK. I'm doing it step by
step. SWIG-less shapelib is already committed to the
branch, dbflib is following ;) Unicode support is not tested
yet though!

Date: 2007-03-13 23:16
Sender: Didrik Pinte

Great, i've just tested the new branch of Bram with success. I guess we can forget SWIG for pyshapelib (except for the dbflib part). We still need to test thoroughly the change but it seems to be a great improvement (thanks Bram ;-) ).

Date: 2007-03-13 22:55
Sender: Bernhard Reiter

Okay, so do we wait until Bram has done a major overhaul?
And assign this issue to him. :)

Attachments:
Size Name Date By Download
318 KiBpyshapelib.patch2006-10-06 16:05Didrik Pintepyshapelib.patch
Field Old Value Date By
assigned_tonone2007-11-30 23:56Bernhard Reiter
File Added34: pyshapelib.patch2006-10-06 16:05Didrik Pinte