[thuban-Patches][191] pyshapelib update to swig 1.3.29 and unicode support

thuban-patches@wald.intevation.org thuban-patches at wald.intevation.org
Fri Oct 6 18:05:23 CEST 2006


Patches item #191, was opened at 2006-10-06 18:05
You can respond by visiting: 
http://wald.intevation.org/tracker/?func=detail&atid=107&aid=191&group_id=6
Or by replying to this e-mail entering your response between the following markers: 
#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+
(enter your response here)
#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+

Status: Open
Priority: 3
Submitted By: Didrik Pinte (dpinte)
Assigned to: Nobody (None)
Summary: pyshapelib update to swig 1.3.29 and unicode support 
Version: None
Category: None


Initial Comment:
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.


----------------------------------------------------------------------

You can respond by visiting: 
http://wald.intevation.org/tracker/?func=detail&atid=107&aid=191&group_id=6




More information about the Thuban-devel mailing list

This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)