[Thuban-commits] r2795 - in branches/WIP-pyshapelib-Unicode/thuban: . Thuban/UI libraries/pyshapelib libraries/shapelib

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Dec 12 21:35:23 CET 2007


Author: bramz
Date: 2007-12-12 21:35:20 +0100 (Wed, 12 Dec 2007)
New Revision: 2795

Added:
   branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/dbflibmodule.c
   branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/pyshapelib_common.h
   branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/shapelibmodule.c
Removed:
   branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/dbflib.i
   branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/dbflib.py
   branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/dbflib_wrap.c
   branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/shapelib.i
   branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/shapelib.py
   branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/shapelib_wrap.c
Modified:
   branches/WIP-pyshapelib-Unicode/thuban/ChangeLog
   branches/WIP-pyshapelib-Unicode/thuban/Thuban/UI/baserenderer.py
   branches/WIP-pyshapelib-Unicode/thuban/Thuban/UI/controls.py
   branches/WIP-pyshapelib-Unicode/thuban/Thuban/UI/labeldialog.py
   branches/WIP-pyshapelib-Unicode/thuban/Thuban/UI/tableview.py
   branches/WIP-pyshapelib-Unicode/thuban/Thuban/UI/view.py
   branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/ChangeLog
   branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/pyshapelib_api.h
   branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/pytest.py
   branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/setup.py
   branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/shptreemodule.c
   branches/WIP-pyshapelib-Unicode/thuban/libraries/shapelib/dbfopen.c
   branches/WIP-pyshapelib-Unicode/thuban/libraries/shapelib/shapefil.h
   branches/WIP-pyshapelib-Unicode/thuban/libraries/shapelib/shpopen.c
   branches/WIP-pyshapelib-Unicode/thuban/setup.py
Log:
ported rev (2734:2755] from WIP-pyshapelib-bramz branch

Modified: branches/WIP-pyshapelib-Unicode/thuban/ChangeLog
===================================================================
--- branches/WIP-pyshapelib-Unicode/thuban/ChangeLog	2007-12-12 20:23:04 UTC (rev 2794)
+++ branches/WIP-pyshapelib-Unicode/thuban/ChangeLog	2007-12-12 20:35:20 UTC (rev 2795)
@@ -320,6 +320,20 @@
 	* MANIFEST.in: Added toplevel ChangeLog to distribution.
 	Made sure that files under packaging are actually packaged.
 
+2007-04-12 Didrik Pinte <dpinte at itae.be>
+
+	* Removed workaround for file encoding in the Thuban code
+
+2007-03-14 Bram de Greve <bram.degreve at intec.ugent.be>
+
+	* setup.py : updated in order to use the new dbflib C module in place
+	of the old SWIG one
+
+2007-03-12 Didrik Pinte <dpinte at itae.be>
+
+	* setup.py : updated in order to use the new pyshapelib C module in place
+	of the old SWIG one
+
 2007-02-26 Bernhard Reiter <bernhard at intevation.de>
 
 	* MANIFEST.in: Added *.xmi to Doc so that ThubanModel.xmi is included.

Modified: branches/WIP-pyshapelib-Unicode/thuban/Thuban/UI/baserenderer.py
===================================================================
--- branches/WIP-pyshapelib-Unicode/thuban/Thuban/UI/baserenderer.py	2007-12-12 20:23:04 UTC (rev 2794)
+++ branches/WIP-pyshapelib-Unicode/thuban/Thuban/UI/baserenderer.py	2007-12-12 20:35:20 UTC (rev 2795)
@@ -583,7 +583,7 @@
                 x, y = forward(x, y)
             x = int(round(x * scale + offx))
             y = int(round(-y * scale + offy))
-            width, height = self.dc.GetTextExtent(text.decode('iso-8859-1'))
+            width, height = self.dc.GetTextExtent(text)
             if label.halign == ALIGN_LEFT:
                 # nothing to be done
                 pass
@@ -598,4 +598,4 @@
                 y = y - height
             elif label.valign == ALIGN_CENTER:
                 y = y - height/2
-            self.dc.DrawText(text.decode('iso-8859-1'), x, y)
+            self.dc.DrawText(text, x, y)

Modified: branches/WIP-pyshapelib-Unicode/thuban/Thuban/UI/controls.py
===================================================================
--- branches/WIP-pyshapelib-Unicode/thuban/Thuban/UI/controls.py	2007-12-12 20:23:04 UTC (rev 2794)
+++ branches/WIP-pyshapelib-Unicode/thuban/Thuban/UI/controls.py	2007-12-12 20:35:20 UTC (rev 2795)
@@ -51,7 +51,7 @@
                 name = names[i]
                 value = record[name]
                 self.InsertStringItem(i, name)
-                self.SetStringItem(i, 1, str(value).decode('iso-8859-1'))
+                self.SetStringItem(i, 1, unicode(value))
                 values[i] = value
 
         self.values = values

Modified: branches/WIP-pyshapelib-Unicode/thuban/Thuban/UI/labeldialog.py
===================================================================
--- branches/WIP-pyshapelib-Unicode/thuban/Thuban/UI/labeldialog.py	2007-12-12 20:23:04 UTC (rev 2794)
+++ branches/WIP-pyshapelib-Unicode/thuban/Thuban/UI/labeldialog.py	2007-12-12 20:35:20 UTC (rev 2795)
@@ -53,7 +53,7 @@
     def OnOK(self, event):
         result = self.list.GetValue()
         if result is not None:
-            self.end_dialog(wx.ID_OK, str(result))
+            self.end_dialog(wx.ID_OK, result)
         else:
             self.end_dialog(wx.ID_CANCEL, None)
 

Modified: branches/WIP-pyshapelib-Unicode/thuban/Thuban/UI/tableview.py
===================================================================
--- branches/WIP-pyshapelib-Unicode/thuban/Thuban/UI/tableview.py	2007-12-12 20:23:04 UTC (rev 2794)
+++ branches/WIP-pyshapelib-Unicode/thuban/Thuban/UI/tableview.py	2007-12-12 20:35:20 UTC (rev 2795)
@@ -77,10 +77,7 @@
             record = dict()
             for (key, val) in self.table.ReadRowAsDict(row, \
                               row_is_ordinal = 1).items():
-                if isinstance(val, str):
-                    record[key] = val.decode('iso-8859-1')
-                else:
-                    record[key] = val
+                record[key] = val
         return record[self.columns[col][0]]
 
     def SetValue(self, row, col, value):

Modified: branches/WIP-pyshapelib-Unicode/thuban/Thuban/UI/view.py
===================================================================
--- branches/WIP-pyshapelib-Unicode/thuban/Thuban/UI/view.py	2007-12-12 20:23:04 UTC (rev 2794)
+++ branches/WIP-pyshapelib-Unicode/thuban/Thuban/UI/view.py	2007-12-12 20:35:20 UTC (rev 2795)
@@ -433,7 +433,7 @@
         dc = wx.ClientDC(self)
         font = wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL)
         dc.SetFont(font)
-        return dc.GetTextExtent(text.decode('iso-8859-1'))
+        return dc.GetTextExtent(text)
 
     def LabelShapeAt(self, x, y, text=None):
         """Add or remove a label at window position x, y.

Modified: branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/ChangeLog
===================================================================
--- branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/ChangeLog	2007-12-12 20:23:04 UTC (rev 2794)
+++ branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/ChangeLog	2007-12-12 20:35:20 UTC (rev 2795)
@@ -3,6 +3,133 @@
 	* shptreemodule.c: Fix copyright notice.  It should have been
 	LGPL.
 
+2007-04-12	Bram de Greve <bram.degreve at intec.ugent.be>
+
+	* dbflibmodule.c: Expanded Unicode support to field names (formely it was
+	only available for string values in the records.  Renamed the write_field 
+	function to write_attribute to be symmetric with the read_attribute 
+	function that already existed.
+
+2007-04-11	Bram de Greve <bram.degreve at intec.ugent.be>
+
+	* dbflibmodule.c, pyshapelib_common.h, setup.py: attempt to add support for
+	Unicode and Language Driver ID (LDID) support in dbflib.  Before the strings
+	are send to the underlying shapelib, they are encoded using the code page
+	specified by the database's LDID if present.  To know this LDID requires 
+	some unofficial modifications to maptools' shapelib.  Backwards 
+	compatibility is ensured by detecting if this field is present and setting 
+	HAVE_LANGUAGE_DRIVER accordingly in setup.py.  In absence of the LDID, 
+	dbflib assumes a Windows ANSI codepage (cp1252).  
+	New or modified functions/attributes of the DBFFile class:
+	- read_record(...), DBFFile.read_attribute(...): modified, now return 
+	  Unicode strings.
+	- write_record(...) and write_field(...): modified, now accept both regular
+	  and Unicode strings but both are encoded.
+	- language_driver (read-only): new, the numerical value of the LDID 
+	  (exists only if HAVE_LANGUAGE_DRIVER == 1)
+	New or modified functions/constants of the dbflib module:
+	- language_driver_codec(...): added, translates a numerical LDID into the 
+	  string name of the Python codec used to encode/decode the strings. 
+	  (exists only if HAVE_LANGUAGE_DRIVER == 1)
+	- language_driver_name(...): added, translates a numerical LDID into a string
+	  representing the corresponding constant. 
+	  (exists only if HAVE_LANGUAGE_DRIVER == 1)
+	- LDID_NOT_SET, LDID_DOS_USA, ...: constants representing language drivers.
+	  (existsonly if HAVE_LANGUAGE_DRIVER == 1)
+
+2007-03-29	Bram de Greve <bram.degreve at intec.ugent.be>
+
+	* shapelibmodule.c, dbflibmodule.c, pyshapelib_common.h: added support for
+	Win32 wide character file API.  Unicode filenames are now fully supported
+	on the windows platform: for example exotic filenames like the greek letter
+	pi (u"\u03c0").  This is mostly mimicked from Python's fileobject.c, and
+	needed some severe changes in the C++ shapelib library to support the wide
+	filename API.  All XOpen and XCreate functions now have XOpenW and XCreateW
+	counterparts plus some common code has been split to XOpenEx and XCreateEx.
+	I hope these modifications might one day end up in an official shapelib
+	release.  Meanwhile, compatibility is guaranteed as the specific Unicode
+	code paths are not compiled if the modifications are not found.
+
+2007-03-22	Bram de Greve <bram.degreve at intec.ugent.be>
+
+	* shapelibmodule.c, dbflibmodule.c: in __init__ of ShapeFile and DBFFile,
+	throw proper IOError if opening of file failed.
+	
+	* dbflibmodule.c: commit function was incorrectly pointing to 
+	dbflib_read_record
+
+2007-03-21	Bram de Greve <bram.degreve at intec.ugent.be>
+
+	* shptreemodule.c: restoring something that shouldn't have been committed.
+
+2007-03-15	Bram de Greve <bram.degreve at intec.ugent.be>
+
+	* shapelib.c: When creating measured shapes (XYM), treat M value
+	value as optional (defaults to zero).  Similar for
+	3D shapes (XYZM), threat both the Z and M value as options 
+	(both default to zero).  When M values are to be given,
+	None is accepted as "no-data" value, and is stored as zero
+	(ESRI shapefile specs define any M value smaller than 1e-38
+	as no-data). Added an unpack_vertex() function to lift some
+	of the load of shpobject_init. Fixed a missing break and
+	PyMem_Free in build_vertex_list(), shapefile_init() and
+	shapelib_create().
+
+	* dbflibmodule.c: Added support for the FTLogical field type.
+	
+	* shapelibmodule.c, dbflibmodule.c: Added 'name' and 'mode' 
+	keywords for ShapeFile and DBFFile constructors and the module's
+	open() function, similiar to Python's file().  Reformatted 
+	the doc strings to have a standard look and feel when parsed
+	through pydoc.
+	
+	* shapelib_common.h: added no-data constants.
+	
+	* pytest.py: Added tests for multipatch shapefile with XYZM values.
+	Added tests for FTLogical field.
+
+2007-03-15	Bram de Greve <bram.degreve at intec.ugent.be>
+
+	* shapelibmodule.c, dbflibmodule.c: added some Unicode support for the
+	filenames (no internal encoding for DBFFile yet).  It now should similar
+	Unicode support Python's file() (concerning the filename, that is).
+
+2007-03-14  Bram de Greve <bram.degreve at intec.ugent.be>
+
+	* shapelibmodule.c: added support for shapetypes with Z and M values
+
+2007-03-14  Bram de Greve <bram.degreve at intec.ugent.be>
+
+	* dbflibmodule.c, dbflib.i: replaced dbflib.i by dbflibmodule.c to use
+	hand-crafted Python bindings instead of SWIG generated ones
+	
+	* shapelibmodule.c, shapelib.c: Renamed shapelib.c to shapelibmodule.c
+	to match style of dbflibmodule.c and shptreemodule.c.  Changed some
+	(well, most) names to match same style.
+	
+	* pyshapelib_common.h: do all necessary includes here
+	
+	* setup.py: updated building of dbflib.
+	
+2007-03-13  Bram de Greve <bram.degreve at intec.ugent.be>
+
+	* shapelib.c, shapelib_common.h: Added part_types() to SHPObject to
+	return tuple of part types. Added __repr__ operators to return a 
+	string that can reconstruct the object using eval()
+	
+	* pytest.py: Added tests for part_types() and __repr__.  
+	Humanized the output a bit.
+
+2007-03-12  Bram de Greve <bram.degreve at intec.ugent.be>
+
+	* shapelib.c, shapelib.i: replaced shapelib.i by shapelib.c to use 
+	hand-crafted Python bindings instead of SWIG generated ones.
+	
+	* pyshapelib_common.h: New file with some common stuff for both 
+	shapelib and dbflib
+	
+	* pyshapelib_api.h, setup.py: import/build shapelib instead of shapelibc
+	
 2006-09-24  Bernhard Reiter  <bernhard at intevation.de>
 
 	* dbflib_wrap.c, README: Checked for python version >= 2.4.0a0

Deleted: branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/dbflib.i
===================================================================
--- branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/dbflib.i	2007-12-12 20:23:04 UTC (rev 2794)
+++ branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/dbflib.i	2007-12-12 20:35:20 UTC (rev 2795)
@@ -1,597 +0,0 @@
-/* SWIG (www.swig.org) interface file for the dbf interface of shapelib
- *
- * At the moment (Dec 2000) this file is only useful to generate Python
- * bindings. Invoke swig as follows:
- *
- *	swig -python -shadow dbflib.i
- *
- * to generate dbflib_wrap.c and dbflib.py. dbflib_wrap.c defines a
- * bunch of Python-functions that wrap the appripriate dbflib functions
- * and dbflib.py contains an object oriented wrapper around
- * dbflib_wrap.c.
- *
- * This module defines one object type: DBFFile.
- */
-
-/* this is the dbflib module */
-%module dbflib
-
-/* first a %{,%} block. These blocks are copied verbatim to the
- * dbflib_wrap.c file and are not parsed by SWIG. This is the place to
- * import headerfiles and define helper-functions that are needed by the
- * automatically generated wrappers.
- */
-
-%{
-#include "shapefil.h"
-
-
-/* Read one attribute from the dbf handle and return it as a new python object
- *
- * If an error occurs, set the appropriate Python exception and return
- * NULL.
- *
- * Assume that the values of the record and field arguments are valid.
- * The name argument will be passed to DBFGetFieldInfo as is and should
- * thus be either NULL or a pointer to an array of at least 12 chars
- */
-static PyObject *
-do_read_attribute(DBFInfo * handle, int record, int field, char * name)
-{
-    int type, width;
-    PyObject *value;
-
-    type = DBFGetFieldInfo(handle, field, name, &width, NULL);
-    /* For strings NULL and the empty string are indistinguishable
-     * in DBF files. We prefer empty strings instead for backwards
-     * compatibility reasons because older wrapper versions returned
-     * emtpy strings as empty strings.
-     */
-    if (type != FTString && DBFIsAttributeNULL(handle, record, field))
-    {
-	value = Py_None;
-	Py_INCREF(value);
-    }
-    else
-    {
-	switch (type)
-	{
-	case FTString:
-	{
-	    const char * temp = DBFReadStringAttribute(handle, record, field);
-	    if (temp)
-	    {
-		value = PyString_FromString(temp);
-	    }
-	    else
-	    {
-		PyErr_Format(PyExc_IOError,
-			     "Can't read value for row %d column %d",
-			     record, field);
-		value = NULL;
-	    }
-	    break;
-	}
-	case FTInteger:
-	    value = PyInt_FromLong(DBFReadIntegerAttribute(handle, record,
-							   field));
-	    break;
-	case FTDouble:
-	    value = PyFloat_FromDouble(DBFReadDoubleAttribute(handle, record,
-							      field));
-	    break;
-	default:
-	    PyErr_Format(PyExc_TypeError, "Invalid field data type %d",
-			 type);
-	    value = NULL;
-	}
-    }
-    if (!value)
-	return NULL;
-
-    return value;
-}    
-
-/* the read_attribute method. Return the value of the given record and
- * field as a python object of the appropriate type.
- * 
- * In case of error, set a python exception and return NULL. Since that
- * value will be returned to the python interpreter as is, the
- * interpreter should recognize the exception.
- */
-
-static PyObject *
-DBFInfo_read_attribute(DBFInfo * handle, int record, int field)
-{
-    if (record < 0 || record >= DBFGetRecordCount(handle))
-    {
-	PyErr_Format(PyExc_ValueError,
-		     "record index %d out of bounds (record count: %d)",
-		     record, DBFGetRecordCount(handle));
-	return NULL;
-    }
-
-    if (field < 0 || field >= DBFGetFieldCount(handle))
-    {
-	PyErr_Format(PyExc_ValueError,
-		     "field index %d out of bounds (field count: %d)",
-		     field, DBFGetFieldCount(handle));
-	return NULL;
-    }
-
-    return do_read_attribute(handle, record, field, NULL);
-}
-    
-
-/* the read_record method. Return the record record as a dictionary with
- * whose keys are the names of the fields, and their values as the
- * appropriate Python type.
- * 
- * In case of error, set a python exception and return NULL. Since that
- * value will be returned to the python interpreter as is, the
- * interpreter should recognize the exception.
- */
-
-static PyObject *
-DBFInfo_read_record(DBFInfo * handle, int record)
-{
-    int num_fields;
-    int i;
-    int type, width;
-    char name[12];
-    PyObject *dict;
-    PyObject *value;
-
-    if (record < 0 || record >= DBFGetRecordCount(handle))
-    {
-	PyErr_Format(PyExc_ValueError,
-		     "record index %d out of bounds (record count: %d)",
-		     record, DBFGetRecordCount(handle));
-	return NULL;
-    }
-
-    dict = PyDict_New();
-    if (!dict)
-	return NULL;
-	
-    num_fields = DBFGetFieldCount(handle);
-    for (i = 0; i < num_fields; i++)
-    {
-	value = do_read_attribute(handle, record, i, name);
-	if (!value)
-	    goto fail;
-
-	PyDict_SetItemString(dict, name, value);
-	Py_DECREF(value);
-    }
-
-    return dict;
-
- fail:
-    Py_XDECREF(dict);
-    return NULL;
-}
-
-/* the write_record method. Write the record record given wither as a
- * dictionary or a sequence (i.e. a list or a tuple).
- *
- * If it's a dictionary the keys must be the names of the fields and
- * their value must have a suitable type. Only the fields actually
- * contained in the dictionary are written. Fields for which there's no
- * item in the dict are not modified.
- *
- * If it's a sequence, all fields must be present in the right order.
- *
- * In case of error, set a python exception and return NULL. Since that
- * value will be returned to the python interpreter as is, the
- * interpreter should recognize the exception.
- *
- * The method is implemented with two c-functions, write_field to write
- * a single field and DBFInfo_write_record as the front-end.
- */
-
-
-/* write a single field of a record. */
-static int
-write_field(DBFHandle handle, int record, int field, int type,
-	    PyObject * value)
-{
-    char * string_value;
-    int int_value;
-    double double_value;
-
-    if (value == Py_None)
-    {
-	if (!DBFWriteNULLAttribute(handle, record, field))
-	{
-	    PyErr_Format(PyExc_IOError,
-			 "can't write NULL field %d of record %d",
-			 field, record);
-	    return 0;
-	}
-    }
-    else
-    {
-	switch (type)
-	{
-	case FTString:
-	    string_value = PyString_AsString(value);
-	    if (!string_value)
-		return 0;
-	    if (!DBFWriteStringAttribute(handle, record, field, string_value))
-	    {
-		PyErr_Format(PyExc_IOError,
-			     "can't write field %d of record %d",
-			     field, record);
-		return 0;
-	    }
-	    break;
-
-	case FTInteger:
-	    int_value = PyInt_AsLong(value);
-	    if (int_value == -1 && PyErr_Occurred())
-		return 0;
-	    if (!DBFWriteIntegerAttribute(handle, record, field, int_value))
-	    {
-		PyErr_Format(PyExc_IOError,
-			     "can't write field %d of record %d",
-			     field, record);
-		return 0;
-	    }
-	    break;
-
-	case FTDouble:
-	    double_value = PyFloat_AsDouble(value);
-	    if (double_value == -1 && PyErr_Occurred())
-		return 0;
-	    if (!DBFWriteDoubleAttribute(handle, record, field, double_value))
-	    {
-		PyErr_Format(PyExc_IOError,
-			     "can't write field %d of record %d",
-			     field, record);
-		return 0;
-	    }
-	    break;
-
-	default:
-	    PyErr_Format(PyExc_TypeError, "Invalid field data type %d", type);
-	    return 0;
-	}
-    }
-
-    return 1;
-}
-
-static
-PyObject *
-DBFInfo_write_record(DBFHandle handle, int record, PyObject *record_object)
-{
-    int num_fields;
-    int i, length;
-    int type, width;
-    char name[12];
-    PyObject * value = NULL;
-
-    num_fields = DBFGetFieldCount(handle);
-
-    /* We used to use PyMapping_Check to test whether record_object is a
-     * dictionary like object instead of PySequence_Check to test
-     * whether it's a sequence. Unfortunately in Python 2.3
-     * PyMapping_Check returns true for lists and tuples too so the old
-     * approach doesn't work anymore.
-     */
-    if (PySequence_Check(record_object))
-    {
-	/* It's a sequence object. Iterate through all items in the
-	 * sequence and write them to the appropriate field.
-	 */
-	length = PySequence_Length(record_object);
-	if (length != num_fields)
-	{
-	    PyErr_SetString(PyExc_TypeError,
-			    "record must have one item for each field");
-	    goto fail;
-	}
-	for (i = 0; i < length; i++)
-	{
-	    type = DBFGetFieldInfo(handle, i, name, &width, NULL); 
-	    value = PySequence_GetItem(record_object, i);
-	    if (value)
-	    {
-		if (!write_field(handle, record, i, type, value))
-		    goto fail;
-		Py_DECREF(value);
-	    }
-	    else
-	    {
-		goto fail;
-	    }
-	}
-    }
-    else
-    {
-	/* It's a dictionary-like object. Iterate over the names of the
-         * known fields and write the corresponding item
-	 */
-	for (i = 0; i < num_fields; i++)
-	{
-	    type = DBFGetFieldInfo(handle, i, name, &width, NULL);
-
-	    /* if the dictionary has the key name write that object to
-	     * the appropriate field, other wise just clear the python
-	     * exception and do nothing.
-	     */
-	    value = PyMapping_GetItemString(record_object, name);
-	    if (value)
-	    {
-		if (!write_field(handle, record, i, type, value))
-		    goto fail;
-		Py_DECREF(value);
-	    }
-	    else
-	    {
-		PyErr_Clear();
-	    }
-	}
-    }
-
-    Py_INCREF(Py_None);
-    return Py_None;
-
- fail:
-    Py_XDECREF(value);
-    return NULL;
-}
-%}
-
-
-/* The commit method implementation
- *
- * The method relies on the DBFUpdateHeader method which is not
- * available in shapelib <= 1.2.10.  setup.py defines
- * HAVE_UPDATE_HEADER's value depending on whether the function is
- * available in the shapelib version the code is compiled with.
- */
-%{
-static
-void
-DBFInfo_commit(DBFHandle handle)
-{
-#if HAVE_UPDATE_HEADER
-    DBFUpdateHeader(handle);
-#endif
-}
-%} 
-
-
-/*
- * The SWIG Interface definition.
- */
-
-/* include some common SWIG type definitions and standard exception
-   handling code */
-%include typemaps.i
-%include exception.i
-
-/* As for ShapeFile in shapelib.i, We define a new C-struct that holds
- * the DBFHandle. This is mainly done so we can separate the close()
- * method from the destructor but it also helps with exception handling.
- *
- * After the DBFFile has been opened or created the handle is not NULL.
- * The close() method closes the file and sets handle to NULL as an
- * indicator that the file has been closed.
- */
-
-%{
-    typedef struct {
-	DBFHandle handle;
-    } DBFFile;
-%}
-
-
-/* The first argument to the DBFFile methods is a DBFFile pointer.
- * We have to check whether handle is not NULL in most methods but not
- * all. In the destructor and the close method, it's OK for handle to be
- * NULL. We achieve this by checking whether the preprocessor macro
- * NOCHECK_$name is defined. SWIG replaces $name with the name of the
- * function for which the code is inserted. In the %{,%}-block below we
- * define the macros for the destructor and the close() method.
- */
-
-%typemap(python,check) DBFFile *{
-%#ifndef NOCHECK_$name
-    if (!$target || !$target->handle)
-	SWIG_exception(SWIG_TypeError, "dbffile already closed");
-%#endif
-}
-
-%{
-#define NOCHECK_delete_DBFFile
-#define NOCHECK_DBFFile_close
-%}
-
-
-/* An exception handle for the constructor and the module level open()
- * and create() functions.
- *
- * Annoyingly, we *have* to put braces around the SWIG_exception()
- * calls, at least in the python case, because of the way the macro is
- * written. Of course, always putting braces around the branches of an
- * if-statement is often considered good practice.
- */
-%typemap(python,except) DBFFile * {
-    $function;
-    if (!$source)
-    {
-    	SWIG_exception(SWIG_MemoryError, "no memory");
-    }
-    else if (!$source->handle)
-    {
-	SWIG_exception(SWIG_IOError, "$name failed");
-    }
-}
-
-/* Exception handler for the add_field method */
-%typemap(python,except) int DBFFile_add_field {
-    $function;
-    if ($source < 0)
-    {
-    	SWIG_exception(SWIG_RuntimeError, "add_field failed");
-    }
-}
-
-/* define and use some typemaps for the field_info() method whose
- * C-implementation has three output parameters that are returned
- * through pointers passed into the function. SWIG already has
- * definitions for common types such as int* and we can use those for
- * the last two parameters:
- */
-
-%apply int * OUTPUT { int * output_width }
-%apply int * OUTPUT { int * output_decimals }
-
-/* the fieldname has to be defined manually: */
-%typemap(python,ignore) char *fieldname_out(char temp[12]) {
-    $target = temp;
-}
-
-%typemap(python,argout) char *fieldname_out() {
-    PyObject * string = PyString_FromString($source);
-    $target = t_output_helper($target,string);
-}
-
-
-
-/*
- * The SWIG-version of the DBFFile struct 
- */
-
-typedef	struct
-{
-    %addmethods {
-	DBFFile(const char *file, const char * mode = "rb") {
-	    DBFFile * self = malloc(sizeof(DBFFile));
-	    if (self)
-		self->handle = DBFOpen(file, mode);
-	    return self;
-	}
-	    
-	~DBFFile() {
-	    if (self->handle)
-		DBFClose(self->handle);
-	    free(self);
-	}
-
-	void close() {
-	    if (self->handle)
-		DBFClose(self->handle);
-	    self->handle = NULL;
-	}
-
-	int field_count() {
-	    return DBFGetFieldCount(self->handle);
-	}
-
-	int record_count() {
-	    return DBFGetRecordCount(self->handle);
-	}
-
-	int field_info(int iField, char * fieldname_out,
-		       int * output_width, int * output_decimals) {
-	    return DBFGetFieldInfo(self->handle, iField, fieldname_out,
-				   output_width, output_decimals);
-	}
-	    
-	PyObject * read_record(int record) {
-	    return DBFInfo_read_record(self->handle, record);
-	}
-
-	PyObject * read_attribute(int record, int field) {
-	    return DBFInfo_read_attribute(self->handle, record, field);
-	}
-
-	int add_field(const char * pszFieldName, DBFFieldType eType,
-		      int nWidth, int nDecimals) {
-	    return DBFAddField(self->handle, pszFieldName, eType, nWidth,
-			       nDecimals);
-	}
-
-	PyObject *write_record(int record, PyObject *dict_or_sequence) {
-	    return DBFInfo_write_record(self->handle, record,
-					dict_or_sequence);
-	}
-
-	void commit() {
-	    DBFInfo_commit(self->handle);
-	}
-	/* Delete the commit method from the class if it doesn't have a
-	 * real implementation.
-	 */
-	%pragma(python) addtomethod="__class__:if not dbflibc._have_commit: del commit"
-
-	/* The __del__ method generated by the old SWIG version we're
-	 * tries to access self.thisown which may not be set at all when
-	 * there was an exception during construction.  Therefore we
-	 * override it with our own version.
-	 * FIXME: It would be better to upgrade to a newer SWIG version
-	 * or to get rid of SWIG entirely.
-	 */
-	%pragma(python) addtoclass = "
-    def __del__(self,dbflibc=dbflibc):
-        if getattr(self, 'thisown', 0):
-            dbflibc.delete_DBFFile(self)
-    "
-
-
-    }
-} DBFFile;
-
-
-/*
- * Two module level functions, open() and create() that correspond to
- * DBFOpen and DBFCreate respectively. open() is equivalent to the
- * DBFFile constructor.
- */
-
-
-%{
-    DBFFile * open_DBFFile(const char * file, const char * mode)
-    {
-	DBFFile * self = malloc(sizeof(DBFFile));
-	if (self)
-	    self->handle = DBFOpen(file, mode);
-	return self;
-    }
-%}
-
-%name(open) %new DBFFile * open_DBFFile(const char * file,
-					const char * mode = "rb");
-
-%{
-    DBFFile * create_DBFFile(const char * file)
-    {
-	DBFFile * self = malloc(sizeof(DBFFile));
-	if (self)
-	    self->handle = DBFCreate(file);
-	return self;
-    }
-%}
-%name(create) %new DBFFile * create_DBFFile(const char * file);
-
-
-
-/* constant definitions copied from shapefil.h */
-typedef enum {
-  FTString,
-  FTInteger,
-  FTDouble,
-  FTInvalid
-} DBFFieldType;
-
-
-/* Put the value of the HAVE_UPDATE_HEADER preprocessor macro into the
- * wrapper so that the __class__ pragma above knows when to remove the
- * commit method
- */
-const int _have_commit = HAVE_UPDATE_HEADER;
-

Deleted: branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/dbflib.py
===================================================================
--- branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/dbflib.py	2007-12-12 20:23:04 UTC (rev 2794)
+++ branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/dbflib.py	2007-12-12 20:35:20 UTC (rev 2795)
@@ -1,76 +0,0 @@
-# This file was created automatically by SWIG.
-import dbflibc
-class DBFFile:
-    def __init__(self,*args):
-        self.this = apply(dbflibc.new_DBFFile,args)
-        self.thisown = 1
-
-    def __del__(self,dbflibc=dbflibc):
-        if self.thisown == 1 :
-            dbflibc.delete_DBFFile(self)
-    def close(*args):
-        val = apply(dbflibc.DBFFile_close,args)
-        return val
-    def field_count(*args):
-        val = apply(dbflibc.DBFFile_field_count,args)
-        return val
-    def record_count(*args):
-        val = apply(dbflibc.DBFFile_record_count,args)
-        return val
-    def field_info(*args):
-        val = apply(dbflibc.DBFFile_field_info,args)
-        return val
-    def read_record(*args):
-        val = apply(dbflibc.DBFFile_read_record,args)
-        return val
-    def read_attribute(*args):
-        val = apply(dbflibc.DBFFile_read_attribute,args)
-        return val
-    def add_field(*args):
-        val = apply(dbflibc.DBFFile_add_field,args)
-        return val
-    def write_record(*args):
-        val = apply(dbflibc.DBFFile_write_record,args)
-        return val
-    def commit(*args):
-        val = apply(dbflibc.DBFFile_commit,args)
-        return val
-    def __repr__(self):
-        return "<C DBFFile instance at %s>" % (self.this,)
-    if not dbflibc._have_commit: del commit
-    
-    def __del__(self,dbflibc=dbflibc):
-        if getattr(self, 'thisown', 0):
-            dbflibc.delete_DBFFile(self)
-    
-class DBFFilePtr(DBFFile):
-    def __init__(self,this):
-        self.this = this
-        self.thisown = 0
-        self.__class__ = DBFFile
-
-
-
-
-
-#-------------- FUNCTION WRAPPERS ------------------
-
-def open(*args, **kwargs):
-    val = apply(dbflibc.open,args,kwargs)
-    if val: val = DBFFilePtr(val); val.thisown = 1
-    return val
-
-def create(*args, **kwargs):
-    val = apply(dbflibc.create,args,kwargs)
-    if val: val = DBFFilePtr(val); val.thisown = 1
-    return val
-
-
-
-#-------------- VARIABLE WRAPPERS ------------------
-
-FTString = dbflibc.FTString
-FTInteger = dbflibc.FTInteger
-FTDouble = dbflibc.FTDouble
-FTInvalid = dbflibc.FTInvalid
-_have_commit = dbflibc._have_commit

Deleted: branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/dbflib_wrap.c
===================================================================
--- branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/dbflib_wrap.c	2007-12-12 20:23:04 UTC (rev 2794)
+++ branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/dbflib_wrap.c	2007-12-12 20:35:20 UTC (rev 2795)
@@ -1,1431 +0,0 @@
-/* ----------------------------------------------------------------------------
- * This file was automatically generated by SWIG (http://www.swig.org).
- * Version 1.3u-20020503-1857 (Alpha 5)
- * And later MANUALLY edited at the end.
- * 
- * This file is not intended to be easily readable and contains a number of 
- * coding conventions designed to improve portability and efficiency. Do not make
- * changes to this file unless you know what you are doing--modify the SWIG 
- * interface file instead. 
- * ----------------------------------------------------------------------------- */
-
-#define SWIGPYTHON
-/***********************************************************************
- * common.swg
- *
- *     This file contains generic SWIG runtime support for pointer
- *     type checking as well as a few commonly used macros to control
- *     external linkage.
- *
- * Author : David Beazley (beazley at cs.uchicago.edu)
- *
- * Copyright (c) 1999-2000, The University of Chicago
- * 
- * This file may be freely redistributed without license or fee provided
- * this copyright message remains intact.
- ************************************************************************/
-
-#include <string.h>
-
-#if defined(_WIN32) || defined(__WIN32__)
-#       if defined(_MSC_VER)
-#               if defined(STATIC_LINKED)
-#                       define SWIGEXPORT(a) a
-#               else
-#                       define SWIGEXPORT(a) __declspec(dllexport) a
-#               endif
-#       else
-#               if defined(__BORLANDC__)
-#                       define SWIGEXPORT(a) a _export
-#               else
-#                       define SWIGEXPORT(a) a
-#       endif
-#endif
-#else
-#       define SWIGEXPORT(a) a
-#endif
-
-#ifdef SWIG_GLOBAL
-#define SWIGRUNTIME(a) SWIGEXPORT(a)
-#else
-#define SWIGRUNTIME(a) static a
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct swig_type_info {
-  char  *name;                 
-  void *(*converter)(void *);
-  char  *str;
-  struct swig_type_info  *next;
-  struct swig_type_info  *prev;
-} swig_type_info;
-
-#ifdef SWIG_NOINCLUDE
-SWIGEXPORT(swig_type_info *) SWIG_TypeRegister(swig_type_info *);
-SWIGEXPORT(swig_type_info *) SWIG_TypeCheck(char *c, swig_type_info *);
-SWIGEXPORT(void *) SWIG_TypeCast(swig_type_info *, void *);
-#else
-
-static swig_type_info *swig_type_list = 0;
-
-/* Register a type mapping with the type-checking */
-SWIGRUNTIME(swig_type_info *)
-SWIG_TypeRegister(swig_type_info *ti)
-{
-  swig_type_info *tc, *head, *ret, *next;
-  /* Check to see if this type has already been registered */
-  tc = swig_type_list;
-  while (tc) {
-    if (strcmp(tc->name, ti->name) == 0) {
-      /* Already exists in the table.  Just add additional types to the list */
-      head = tc;
-      next = tc->next;
-      goto l1;
-    }
-    tc = tc->prev;
-  }
-  head = ti;
-  next = 0;
-
-  /* Place in list */
-  ti->prev = swig_type_list;
-  swig_type_list = ti;
-
-  /* Build linked lists */
- l1:
-  ret = head;
-  tc = ti + 1;
-  /* Patch up the rest of the links */
-  while (tc->name) {
-    head->next = tc;
-    tc->prev = head;
-    head = tc;
-    tc++;
-  }
-  head->next = next;
-  return ret;
-}
-
-/* Check the typename */
-SWIGRUNTIME(swig_type_info *) 
-SWIG_TypeCheck(char *c, swig_type_info *ty)
-{
-  swig_type_info *s;
-  if (!ty) return 0;        /* Void pointer */
-  s = ty->next;             /* First element always just a name */
-  while (s) {
-    if (strcmp(s->name,c) == 0) {
-      if (s == ty->next) return s;
-      /* Move s to the top of the linked list */
-      s->prev->next = s->next;
-      if (s->next) {
-	s->next->prev = s->prev;
-      }
-      /* Insert s as second element in the list */
-      s->next = ty->next;
-      if (ty->next) ty->next->prev = s;
-      ty->next = s;
-      return s;
-    }
-    s = s->next;
-  }
-  return 0;
-}
-
-/* Cast a pointer (needed for C++ inheritance */
-SWIGRUNTIME(void *) 
-SWIG_TypeCast(swig_type_info *ty, void *ptr) 
-{
-  if ((!ty) || (!ty->converter)) return ptr;
-  return (*ty->converter)(ptr);
-}
-
-/* Search for a swig_type_info structure */
-SWIGRUNTIME(void *)
-SWIG_TypeQuery(const char *name) {
-  swig_type_info *ty = swig_type_list;
-  while (ty) {
-    if (ty->str && (strcmp(name,ty->str) == 0)) return ty;
-    if (ty->name && (strcmp(name,ty->name) == 0)) return ty;
-    ty = ty->prev;
-  }
-  return 0;
-}
-
-#endif
-
-#ifdef __cplusplus
-}
-#endif
-
-
-
-/***********************************************************************
- * python.swg
- *
- *     This file contains the runtime support for Python modules
- *     and includes code for managing global variables and pointer
- *     type checking.
- *
- * Author : David Beazley (beazley at cs.uchicago.edu)
- ************************************************************************/
-
-#include <stdlib.h>
-#include "Python.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define SWIG_PY_INT     1
-#define SWIG_PY_FLOAT   2
-#define SWIG_PY_STRING  3
-#define SWIG_PY_POINTER 4
-
-/* Constant information structure */
-typedef struct swig_const_info {
-    int type;
-    char *name;
-    long lvalue;
-    double dvalue;
-    void   *pvalue;
-    swig_type_info **ptype;
-} swig_const_info;
-
-#ifdef SWIG_NOINCLUDE
-
-SWIGEXPORT(PyObject *)        SWIG_newvarlink();
-SWIGEXPORT(void)              SWIG_addvarlink(PyObject *, char *, PyObject *(*)(void), int (*)(PyObject *));
-SWIGEXPORT(int)               SWIG_ConvertPtr(PyObject *, void **, swig_type_info *, int);
-SWIGEXPORT(void)              SWIG_MakePtr(char *c, void *, swig_type_info *);
-SWIGEXPORT(PyObject *)        SWIG_NewPointerObj(void *, swig_type_info *);
-SWIGEXPORT(void)              SWIG_InstallConstants(PyObject *d, swig_const_info constants[]);
-
-#else
-
-/* -----------------------------------------------------------------------------
- * global variable support code.
- * ----------------------------------------------------------------------------- */
-
-typedef struct swig_globalvar {   
-  char       *name;                  /* Name of global variable */
-  PyObject *(*get_attr)(void);       /* Return the current value */
-  int       (*set_attr)(PyObject *); /* Set the value */
-  struct swig_globalvar *next;
-} swig_globalvar;
-
-typedef struct swig_varlinkobject {
-  PyObject_HEAD
-  swig_globalvar *vars;
-} swig_varlinkobject;
-
-static PyObject *
-swig_varlink_repr(swig_varlinkobject *v) {
-  v = v;
-  return PyString_FromString("<Global variables>");
-}
-
-static int
-swig_varlink_print(swig_varlinkobject *v, FILE *fp, int flags) {
-  swig_globalvar  *var;
-  flags = flags;
-  fprintf(fp,"Global variables { ");
-  for (var = v->vars; var; var=var->next) {
-    fprintf(fp,"%s", var->name);
-    if (var->next) fprintf(fp,", ");
-  }
-  fprintf(fp," }\n");
-  return 0;
-}
-
-static PyObject *
-swig_varlink_getattr(swig_varlinkobject *v, char *n) {
-  swig_globalvar *var = v->vars;
-  while (var) {
-    if (strcmp(var->name,n) == 0) {
-      return (*var->get_attr)();
-    }
-    var = var->next;
-  }
-  PyErr_SetString(PyExc_NameError,"Unknown C global variable");
-  return NULL;
-}
-
-static int
-swig_varlink_setattr(swig_varlinkobject *v, char *n, PyObject *p) {
-  swig_globalvar *var = v->vars;
-  while (var) {
-    if (strcmp(var->name,n) == 0) {
-      return (*var->set_attr)(p);
-    }
-    var = var->next;
-  }
-  PyErr_SetString(PyExc_NameError,"Unknown C global variable");
-  return 1;
-}
-
-statichere PyTypeObject varlinktype = {
-  PyObject_HEAD_INIT(0)              
-  0,
-  "swigvarlink",                      /* Type name    */
-  sizeof(swig_varlinkobject),         /* Basic size   */
-  0,                                  /* Itemsize     */
-  0,                                  /* Deallocator  */ 
-  (printfunc) swig_varlink_print,     /* Print        */
-  (getattrfunc) swig_varlink_getattr, /* get attr     */
-  (setattrfunc) swig_varlink_setattr, /* Set attr     */
-  0,                                  /* tp_compare   */
-  (reprfunc) swig_varlink_repr,       /* tp_repr      */    
-  0,                                  /* tp_as_number */
-  0,                                  /* tp_as_mapping*/
-  0,                                  /* tp_hash      */
-};
-
-/* Create a variable linking object for use later */
-SWIGRUNTIME(PyObject *)
-SWIG_newvarlink(void) {
-  swig_varlinkobject *result = 0;
-  result = PyMem_NEW(swig_varlinkobject,1);
-  varlinktype.ob_type = &PyType_Type;    /* Patch varlinktype into a PyType */
-  result->ob_type = &varlinktype;
-  result->vars = 0;
-  result->ob_refcnt = 0;
-  Py_XINCREF((PyObject *) result);
-  return ((PyObject*) result);
-}
-
-SWIGRUNTIME(void)
-SWIG_addvarlink(PyObject *p, char *name,
-	   PyObject *(*get_attr)(void), int (*set_attr)(PyObject *p)) {
-  swig_varlinkobject *v;
-  swig_globalvar *gv;
-  v= (swig_varlinkobject *) p;
-  gv = (swig_globalvar *) malloc(sizeof(swig_globalvar));
-  gv->name = (char *) malloc(strlen(name)+1);
-  strcpy(gv->name,name);
-  gv->get_attr = get_attr;
-  gv->set_attr = set_attr;
-  gv->next = v->vars;
-  v->vars = gv;
-}
-/* Convert a pointer value */
-SWIGRUNTIME(int)
-SWIG_ConvertPtr(PyObject *obj, void **ptr, swig_type_info *ty, int flags) {
-  unsigned long p;
-  register int d;
-  swig_type_info *tc;
-  char  *c;
-  static PyObject *SWIG_this = 0;
-  int    newref = 0;
-
-  if (!obj || (obj == Py_None)) {
-    *ptr = 0;
-    return 0;
-  }
-#ifdef SWIG_COBJECT_TYPES
-  if (!(PyCObject_Check(obj))) {
-    if (!SWIG_this)
-      SWIG_this = PyString_InternFromString("this");
-    obj = PyObject_GetAttr(obj,SWIG_this);
-    newref = 1;
-    if (!obj) goto type_error;
-    if (!PyCObject_Check(obj)) {
-      Py_DECREF(obj);
-      goto type_error;
-    }
-  } 
-  *ptr = PyCObject_AsVoidPtr(obj);
-  c = (char *) PyCObject_GetDesc(obj);
-  if (newref) Py_DECREF(obj);
-  goto cobject;
-#else
-  if (!(PyString_Check(obj))) {
-    if (!SWIG_this)
-      SWIG_this = PyString_InternFromString("this");
-    obj = PyObject_GetAttr(obj,SWIG_this);
-    newref = 1;
-    if (!obj) goto type_error;
-    if (!PyString_Check(obj)) {
-      Py_DECREF(obj);
-      goto type_error;
-    }
-  } 
-  c = PyString_AsString(obj);
-  p = 0;
-  /* Pointer values must start with leading underscore */
-  if (*c != '_') {
-    *ptr = (void *) 0;
-    if (strcmp(c,"NULL") == 0) {
-      if (newref) Py_DECREF(obj);
-      return 0;
-    } else {
-      if (newref) Py_DECREF(obj);
-      goto type_error;
-    }
-  }
-  c++;
-  /* Extract hex value from pointer */
-  while ((d = *c)) {
-    if ((d >= '0') && (d <= '9'))
-      p = (p << 4) + (d - '0');
-    else if ((d >= 'a') && (d <= 'f'))
-      p = (p << 4) + (d - ('a'-10));
-    else
-      break; 
-    c++;
-  }
-  *ptr = (void *) p;
-  if (newref) Py_DECREF(obj);
-#endif
-
-#ifdef SWIG_COBJECT_TYPES
-cobject:
-#endif
-
-  if (ty) {
-    tc = SWIG_TypeCheck(c,ty);
-    if (!tc) goto type_error;
-    *ptr = SWIG_TypeCast(tc,(void*)p);
-  }
-  return 0;
-
-type_error:
-
-  if (flags) {
-    if (ty) {
-      char *temp = (char *) malloc(64+strlen(ty->name));
-      sprintf(temp,"Type error. Expected %s", ty->name);
-      PyErr_SetString(PyExc_TypeError, temp);
-      free((char *) temp);
-    } else {
-      PyErr_SetString(PyExc_TypeError,"Expected a pointer");
-    }
-  }
-  return -1;
-}
-
-/* Take a pointer and convert it to a string */
-SWIGRUNTIME(void) 
-SWIG_MakePtr(char *c, void *ptr, swig_type_info *ty) {
-  static char hex[17] = "0123456789abcdef";
-  unsigned long p, s;
-  char result[32], *r; 
-  r = result;
-  p = (unsigned long) ptr;
-  if (p > 0) {
-    while (p > 0) {
-      s = p & 0xf;
-      *(r++) = hex[s];
-      p = p >> 4;
-    }
-    *r = '_';
-    while (r >= result)
-      *(c++) = *(r--);
-    strcpy (c, ty->name);
-  } else {
-    strcpy (c, "NULL");
-  }
-}
-
-/* Create a new pointer object */
-SWIGRUNTIME(PyObject *)
-SWIG_NewPointerObj(void *ptr, swig_type_info *type) {
-  char result[512];
-  PyObject *robj;
-  if (!ptr) {
-    Py_INCREF(Py_None);
-    return Py_None;
-  }
-#ifdef SWIG_COBJECT_TYPES
-  robj = PyCObject_FromVoidPtrAndDesc((void *) ptr, type->name, NULL);
-#else
-  SWIG_MakePtr(result,ptr,type);
-  robj = PyString_FromString(result);
-#endif
-  return robj;
-}
-
-/* Install Constants */
-SWIGRUNTIME(void)
-SWIG_InstallConstants(PyObject *d, swig_const_info constants[]) {
-  int i;
-  PyObject *obj;
-  for (i = 0; constants[i].type; i++) {
-    switch(constants[i].type) {
-    case SWIG_PY_INT:
-      obj = PyInt_FromLong(constants[i].lvalue);
-      break;
-    case SWIG_PY_FLOAT:
-      obj = PyFloat_FromDouble(constants[i].dvalue);
-      break;
-    case SWIG_PY_STRING:
-      obj = PyString_FromString((char *) constants[i].pvalue);
-      break;
-    case SWIG_PY_POINTER:
-      obj = SWIG_NewPointerObj(constants[i].pvalue, *(constants[i]).ptype);
-      break;
-    default:
-      obj = 0;
-      break;
-    }
-    if (obj) {
-      PyDict_SetItemString(d,constants[i].name,obj);
-      Py_DECREF(obj);
-    }
-  }
-}
-
-#endif
-
-#ifdef __cplusplus
-}
-#endif
-
-
-
-/* -------- TYPES TABLE (BEGIN) -------- */
-
-#define  SWIGTYPE_p_DBFFile swig_types[0] 
-static swig_type_info *swig_types[2];
-
-/* -------- TYPES TABLE (END) -------- */
-
-
-/*-----------------------------------------------
-              @(target):= dbflibc.so
-  ------------------------------------------------*/
-#define SWIG_init    initdbflibc
-
-#define SWIG_name    "dbflibc"
-
-#include "shapefil.h"
-
-
-/* Read one attribute from the dbf handle and return it as a new python object
- *
- * If an error occurs, set the appropriate Python exception and return
- * NULL.
- *
- * Assume that the values of the record and field arguments are valid.
- * The name argument will be passed to DBFGetFieldInfo as is and should
- * thus be either NULL or a pointer to an array of at least 12 chars
- */
-static PyObject *
-do_read_attribute(DBFInfo * handle, int record, int field, char * name)
-{
-    int type, width;
-    PyObject *value;
-
-    type = DBFGetFieldInfo(handle, field, name, &width, NULL);
-    /* For strings NULL and the empty string are indistinguishable
-     * in DBF files. We prefer empty strings instead for backwards
-     * compatibility reasons because older wrapper versions returned
-     * emtpy strings as empty strings.
-     */
-    if (type != FTString && DBFIsAttributeNULL(handle, record, field))
-    {
-	value = Py_None;
-	Py_INCREF(value);
-    }
-    else
-    {
-	switch (type)
-	{
-	case FTString:
-	{
-	    const char * temp = DBFReadStringAttribute(handle, record, field);
-	    if (temp)
-	    {
-		value = PyString_FromString(temp);
-	    }
-	    else
-	    {
-		PyErr_Format(PyExc_IOError,
-			     "Can't read value for row %d column %d",
-			     record, field);
-		value = NULL;
-	    }
-	    break;
-	}
-	case FTInteger:
-	    value = PyInt_FromLong(DBFReadIntegerAttribute(handle, record,
-							   field));
-	    break;
-	case FTDouble:
-	    value = PyFloat_FromDouble(DBFReadDoubleAttribute(handle, record,
-							      field));
-	    break;
-	default:
-	    PyErr_Format(PyExc_TypeError, "Invalid field data type %d",
-			 type);
-	    value = NULL;
-	}
-    }
-    if (!value)
-	return NULL;
-
-    return value;
-}    
-
-/* the read_attribute method. Return the value of the given record and
- * field as a python object of the appropriate type.
- * 
- * In case of error, set a python exception and return NULL. Since that
- * value will be returned to the python interpreter as is, the
- * interpreter should recognize the exception.
- */
-
-static PyObject *
-DBFInfo_read_attribute(DBFInfo * handle, int record, int field)
-{
-    if (record < 0 || record >= DBFGetRecordCount(handle))
-    {
-	PyErr_Format(PyExc_ValueError,
-		     "record index %d out of bounds (record count: %d)",
-		     record, DBFGetRecordCount(handle));
-	return NULL;
-    }
-
-    if (field < 0 || field >= DBFGetFieldCount(handle))
-    {
-	PyErr_Format(PyExc_ValueError,
-		     "field index %d out of bounds (field count: %d)",
-		     field, DBFGetFieldCount(handle));
-	return NULL;
-    }
-
-    return do_read_attribute(handle, record, field, NULL);
-}
-    
-
-/* the read_record method. Return the record record as a dictionary with
- * whose keys are the names of the fields, and their values as the
- * appropriate Python type.
- * 
- * In case of error, set a python exception and return NULL. Since that
- * value will be returned to the python interpreter as is, the
- * interpreter should recognize the exception.
- */
-
-static PyObject *
-DBFInfo_read_record(DBFInfo * handle, int record)
-{
-    int num_fields;
-    int i;
-    int type, width;
-    char name[12];
-    PyObject *dict;
-    PyObject *value;
-
-    if (record < 0 || record >= DBFGetRecordCount(handle))
-    {
-	PyErr_Format(PyExc_ValueError,
-		     "record index %d out of bounds (record count: %d)",
-		     record, DBFGetRecordCount(handle));
-	return NULL;
-    }
-
-    dict = PyDict_New();
-    if (!dict)
-	return NULL;
-	
-    num_fields = DBFGetFieldCount(handle);
-    for (i = 0; i < num_fields; i++)
-    {
-	value = do_read_attribute(handle, record, i, name);
-	if (!value)
-	    goto fail;
-
-	PyDict_SetItemString(dict, name, value);
-	Py_DECREF(value);
-    }
-
-    return dict;
-
- fail:
-    Py_XDECREF(dict);
-    return NULL;
-}
-
-/* the write_record method. Write the record record given wither as a
- * dictionary or a sequence (i.e. a list or a tuple).
- *
- * If it's a dictionary the keys must be the names of the fields and
- * their value must have a suitable type. Only the fields actually
- * contained in the dictionary are written. Fields for which there's no
- * item in the dict are not modified.
- *
- * If it's a sequence, all fields must be present in the right order.
- *
- * In case of error, set a python exception and return NULL. Since that
- * value will be returned to the python interpreter as is, the
- * interpreter should recognize the exception.
- *
- * The method is implemented with two c-functions, write_field to write
- * a single field and DBFInfo_write_record as the front-end.
- */
-
-
-/* write a single field of a record. */
-static int
-write_field(DBFHandle handle, int record, int field, int type,
-	    PyObject * value)
-{
-    char * string_value;
-    int int_value;
-    double double_value;
-
-    if (value == Py_None)
-    {
-	if (!DBFWriteNULLAttribute(handle, record, field))
-	{
-	    PyErr_Format(PyExc_IOError,
-			 "can't write NULL field %d of record %d",
-			 field, record);
-	    return 0;
-	}
-    }
-    else
-    {
-	switch (type)
-	{
-	case FTString:
-	    string_value = PyString_AsString(value);
-	    if (!string_value)
-		return 0;
-	    if (!DBFWriteStringAttribute(handle, record, field, string_value))
-	    {
-		PyErr_Format(PyExc_IOError,
-			     "can't write field %d of record %d",
-			     field, record);
-		return 0;
-	    }
-	    break;
-
-	case FTInteger:
-	    int_value = PyInt_AsLong(value);
-	    if (int_value == -1 && PyErr_Occurred())
-		return 0;
-	    if (!DBFWriteIntegerAttribute(handle, record, field, int_value))
-	    {
-		PyErr_Format(PyExc_IOError,
-			     "can't write field %d of record %d",
-			     field, record);
-		return 0;
-	    }
-	    break;
-
-	case FTDouble:
-	    double_value = PyFloat_AsDouble(value);
-	    if (double_value == -1 && PyErr_Occurred())
-		return 0;
-	    if (!DBFWriteDoubleAttribute(handle, record, field, double_value))
-	    {
-		PyErr_Format(PyExc_IOError,
-			     "can't write field %d of record %d",
-			     field, record);
-		return 0;
-	    }
-	    break;
-
-	default:
-	    PyErr_Format(PyExc_TypeError, "Invalid field data type %d", type);
-	    return 0;
-	}
-    }
-
-    return 1;
-}
-
-static
-PyObject *
-DBFInfo_write_record(DBFHandle handle, int record, PyObject *record_object)
-{
-    int num_fields;
-    int i, length;
-    int type, width;
-    char name[12];
-    PyObject * value = NULL;
-
-    num_fields = DBFGetFieldCount(handle);
-
-    /* We used to use PyMapping_Check to test whether record_object is a
-     * dictionary like object instead of PySequence_Check to test
-     * whether it's a sequence. Unfortunately in Python 2.3
-     * PyMapping_Check returns true for lists and tuples too so the old
-     * approach doesn't work anymore.
-     */
-    if (PySequence_Check(record_object))
-    {
-	/* It's a sequence object. Iterate through all items in the
-	 * sequence and write them to the appropriate field.
-	 */
-	length = PySequence_Length(record_object);
-	if (length != num_fields)
-	{
-	    PyErr_SetString(PyExc_TypeError,
-			    "record must have one item for each field");
-	    goto fail;
-	}
-	for (i = 0; i < length; i++)
-	{
-	    type = DBFGetFieldInfo(handle, i, name, &width, NULL); 
-	    value = PySequence_GetItem(record_object, i);
-	    if (value)
-	    {
-		if (!write_field(handle, record, i, type, value))
-		    goto fail;
-		Py_DECREF(value);
-	    }
-	    else
-	    {
-		goto fail;
-	    }
-	}
-    }
-    else
-    {
-	/* It's a dictionary-like object. Iterate over the names of the
-         * known fields and write the corresponding item
-	 */
-	for (i = 0; i < num_fields; i++)
-	{
-	    type = DBFGetFieldInfo(handle, i, name, &width, NULL);
-
-	    /* if the dictionary has the key name write that object to
-	     * the appropriate field, other wise just clear the python
-	     * exception and do nothing.
-	     */
-	    value = PyMapping_GetItemString(record_object, name);
-	    if (value)
-	    {
-		if (!write_field(handle, record, i, type, value))
-		    goto fail;
-		Py_DECREF(value);
-	    }
-	    else
-	    {
-		PyErr_Clear();
-	    }
-	}
-    }
-
-    Py_INCREF(Py_None);
-    return Py_None;
-
- fail:
-    Py_XDECREF(value);
-    return NULL;
-}
-
-static
-void
-DBFInfo_commit(DBFHandle handle)
-{
-#if HAVE_UPDATE_HEADER
-    DBFUpdateHeader(handle);
-#endif
-}
-
-static PyObject* l_output_helper(PyObject* target, PyObject* o) {
-    PyObject*   o2;
-    if (!target) {                   
-        target = o;
-    } else if (target == Py_None) {  
-        Py_DECREF(Py_None);
-        target = o;
-    } else {                         
-        if (!PyList_Check(target)) {
-            o2 = target;
-            target = PyList_New(0);
-            PyList_Append(target, o2);
-	    Py_XDECREF(o2);
-        }
-        PyList_Append(target,o);
-	Py_XDECREF(o);
-    }
-    return target;
-}
-
-static PyObject* t_output_helper(PyObject* target, PyObject* o) {
-    PyObject*   o2;
-    PyObject*   o3;
-
-    if (!target) {                   
-        target = o;
-    } else if (target == Py_None) {  
-        Py_DECREF(Py_None);
-        target = o;
-    } else {                         
-        if (!PyTuple_Check(target)) {
-            o2 = target;
-            target = PyTuple_New(1);
-            PyTuple_SetItem(target, 0, o2);
-        }
-        o3 = PyTuple_New(1);            
-        PyTuple_SetItem(o3, 0, o);      
-
-        o2 = target;
-        target = PySequence_Concat(o2, o3); 
-        Py_DECREF(o2);                      
-        Py_DECREF(o3);
-    }
-    return target;
-}
-
-#define  SWIG_MemoryError    1
-#define  SWIG_IOError        2
-#define  SWIG_RuntimeError   3
-#define  SWIG_IndexError     4
-#define  SWIG_TypeError      5
-#define  SWIG_DivisionByZero 6
-#define  SWIG_OverflowError  7
-#define  SWIG_SyntaxError    8
-#define  SWIG_ValueError     9
-#define  SWIG_SystemError   10
-#define  SWIG_UnknownError  99
-
-static void _SWIG_exception(int code, char *msg) {
-  switch(code) {
-  case SWIG_MemoryError:
-    PyErr_SetString(PyExc_MemoryError,msg);
-    break;
-  case SWIG_IOError:
-    PyErr_SetString(PyExc_IOError,msg);
-    break;
-  case SWIG_RuntimeError:
-    PyErr_SetString(PyExc_RuntimeError,msg);
-    break;
-  case SWIG_IndexError:
-    PyErr_SetString(PyExc_IndexError,msg);
-    break;
-  case SWIG_TypeError:
-    PyErr_SetString(PyExc_TypeError,msg);
-    break;
-  case SWIG_DivisionByZero:
-    PyErr_SetString(PyExc_ZeroDivisionError,msg);
-    break;
-  case SWIG_OverflowError:
-    PyErr_SetString(PyExc_OverflowError,msg);
-    break;
-  case SWIG_SyntaxError:
-    PyErr_SetString(PyExc_SyntaxError,msg);
-    break;
-  case SWIG_ValueError:
-    PyErr_SetString(PyExc_ValueError,msg);
-    break;
-  case SWIG_SystemError:
-    PyErr_SetString(PyExc_SystemError,msg);
-    break;
-  default:
-    PyErr_SetString(PyExc_RuntimeError,msg);
-    break;
-  }
-}
-
-#define SWIG_exception(a,b) { _SWIG_exception(a,b); return NULL; }
-
-    typedef struct {
-	DBFHandle handle;
-    } DBFFile;
-
-#define NOCHECK_delete_DBFFile
-#define NOCHECK_DBFFile_close
-
-    DBFFile * open_DBFFile(const char * file, const char * mode)
-    {
-	DBFFile * self = malloc(sizeof(DBFFile));
-	if (self)
-	    self->handle = DBFOpen(file, mode);
-	return self;
-    }
-
-    DBFFile * create_DBFFile(const char * file)
-    {
-	DBFFile * self = malloc(sizeof(DBFFile));
-	if (self)
-	    self->handle = DBFCreate(file);
-	return self;
-    }
-#ifdef __cplusplus
-extern "C" {
-#endif
-static PyObject *_wrap_open(PyObject *self, PyObject *args) {
-    PyObject *resultobj;
-    char *arg0 ;
-    char *arg1 = "rb" ;
-    DBFFile *result ;
-    
-    if(!PyArg_ParseTuple(args,"s|s:open",&arg0,&arg1)) return NULL;
-    {
-        result = (DBFFile *)open_DBFFile((char const *)arg0,(char const *)arg1);
-        ;
-        if (!result)
-        {
-            SWIG_exception(SWIG_MemoryError, "no memory");
-        }
-        else if (!result->handle)
-        {
-            SWIG_exception(SWIG_IOError, "open_DBFFile failed");
-        }
-    }resultobj = SWIG_NewPointerObj((void *) result, SWIGTYPE_p_DBFFile);
-    return resultobj;
-}
-
-
-static PyObject *_wrap_create(PyObject *self, PyObject *args) {
-    PyObject *resultobj;
-    char *arg0 ;
-    DBFFile *result ;
-    
-    if(!PyArg_ParseTuple(args,"s:create",&arg0)) return NULL;
-    {
-        result = (DBFFile *)create_DBFFile((char const *)arg0);
-        ;
-        if (!result)
-        {
-            SWIG_exception(SWIG_MemoryError, "no memory");
-        }
-        else if (!result->handle)
-        {
-            SWIG_exception(SWIG_IOError, "create_DBFFile failed");
-        }
-    }resultobj = SWIG_NewPointerObj((void *) result, SWIGTYPE_p_DBFFile);
-    return resultobj;
-}
-
-
-DBFFile * new_DBFFile(char const *file,char const *mode) {
-    {
-        DBFFile * self = malloc(sizeof(DBFFile));
-        if (self)
-        self->handle = DBFOpen(file, mode);
-        return self;
-    }
-}
-
-
-static PyObject *_wrap_new_DBFFile(PyObject *self, PyObject *args) {
-    PyObject *resultobj;
-    char *arg0 ;
-    char *arg1 = "rb" ;
-    DBFFile *result ;
-    
-    if(!PyArg_ParseTuple(args,"s|s:new_DBFFile",&arg0,&arg1)) return NULL;
-    {
-        result = (DBFFile *)new_DBFFile((char const *)arg0,(char const *)arg1);
-        ;
-        if (!result)
-        {
-            SWIG_exception(SWIG_MemoryError, "no memory");
-        }
-        else if (!result->handle)
-        {
-            SWIG_exception(SWIG_IOError, "new_DBFFile failed");
-        }
-    }resultobj = SWIG_NewPointerObj((void *) result, SWIGTYPE_p_DBFFile);
-    return resultobj;
-}
-
-
-void  delete_DBFFile(DBFFile *self) {
-    {
-        if (self->handle)
-        DBFClose(self->handle);
-        free(self);
-    }
-}
-
-
-static PyObject *_wrap_delete_DBFFile(PyObject *self, PyObject *args) {
-    PyObject *resultobj;
-    DBFFile *arg0 ;
-    PyObject * argo0 =0 ;
-    
-    if(!PyArg_ParseTuple(args,"O:delete_DBFFile",&argo0)) return NULL;
-    if ((SWIG_ConvertPtr(argo0,(void **) &arg0,SWIGTYPE_p_DBFFile,1)) == -1) return NULL;
-    {
-        #ifndef NOCHECK_delete_DBFFile
-        if (!arg0 || !arg0->handle)
-        SWIG_exception(SWIG_TypeError, "dbffile already closed");
-        #endif
-    }
-    delete_DBFFile(arg0);
-    Py_INCREF(Py_None);
-    resultobj = Py_None;
-    return resultobj;
-}
-
-
-void  DBFFile_close(DBFFile *self) {
-    {
-        if (self->handle)
-        DBFClose(self->handle);
-        self->handle = NULL;
-    }
-}
-
-
-static PyObject *_wrap_DBFFile_close(PyObject *self, PyObject *args) {
-    PyObject *resultobj;
-    DBFFile *arg0 ;
-    PyObject * argo0 =0 ;
-    
-    if(!PyArg_ParseTuple(args,"O:DBFFile_close",&argo0)) return NULL;
-    if ((SWIG_ConvertPtr(argo0,(void **) &arg0,SWIGTYPE_p_DBFFile,1)) == -1) return NULL;
-    {
-        #ifndef NOCHECK_DBFFile_close
-        if (!arg0 || !arg0->handle)
-        SWIG_exception(SWIG_TypeError, "dbffile already closed");
-        #endif
-    }
-    DBFFile_close(arg0);
-    Py_INCREF(Py_None);
-    resultobj = Py_None;
-    return resultobj;
-}
-
-
-int  DBFFile_field_count(DBFFile *self) {
-    {
-        return DBFGetFieldCount(self->handle);
-    }
-}
-
-
-static PyObject *_wrap_DBFFile_field_count(PyObject *self, PyObject *args) {
-    PyObject *resultobj;
-    DBFFile *arg0 ;
-    PyObject * argo0 =0 ;
-    int result ;
-    
-    if(!PyArg_ParseTuple(args,"O:DBFFile_field_count",&argo0)) return NULL;
-    if ((SWIG_ConvertPtr(argo0,(void **) &arg0,SWIGTYPE_p_DBFFile,1)) == -1) return NULL;
-    {
-        #ifndef NOCHECK_DBFFile_field_count
-        if (!arg0 || !arg0->handle)
-        SWIG_exception(SWIG_TypeError, "dbffile already closed");
-        #endif
-    }
-    result = (int )DBFFile_field_count(arg0);
-    resultobj = PyInt_FromLong((long)result);
-    return resultobj;
-}
-
-
-int  DBFFile_record_count(DBFFile *self) {
-    {
-        return DBFGetRecordCount(self->handle);
-    }
-}
-
-
-static PyObject *_wrap_DBFFile_record_count(PyObject *self, PyObject *args) {
-    PyObject *resultobj;
-    DBFFile *arg0 ;
-    PyObject * argo0 =0 ;
-    int result ;
-    
-    if(!PyArg_ParseTuple(args,"O:DBFFile_record_count",&argo0)) return NULL;
-    if ((SWIG_ConvertPtr(argo0,(void **) &arg0,SWIGTYPE_p_DBFFile,1)) == -1) return NULL;
-    {
-        #ifndef NOCHECK_DBFFile_record_count
-        if (!arg0 || !arg0->handle)
-        SWIG_exception(SWIG_TypeError, "dbffile already closed");
-        #endif
-    }
-    result = (int )DBFFile_record_count(arg0);
-    resultobj = PyInt_FromLong((long)result);
-    return resultobj;
-}
-
-
-int  DBFFile_field_info(DBFFile *self,int iField,char *fieldname_out,int *output_width,int *output_decimals) {
-    {
-        return DBFGetFieldInfo(self->handle, iField, fieldname_out,
-        output_width, output_decimals);
-    }
-}
-
-
-static PyObject *_wrap_DBFFile_field_info(PyObject *self, PyObject *args) {
-    PyObject *resultobj;
-    DBFFile *arg0 ;
-    int arg1 ;
-    char *arg2 ;
-    int *arg3 ;
-    int *arg4 ;
-    char temp[12] ;
-    int temp0 ;
-    int temp1 ;
-    PyObject * argo0 =0 ;
-    int result ;
-    
-    {
-        arg2 = temp;
-    }
-    {
-        arg3 = &temp0;
-    }
-    {
-        arg4 = &temp1;
-    }
-    if(!PyArg_ParseTuple(args,"Oi:DBFFile_field_info",&argo0,&arg1)) return NULL;
-    if ((SWIG_ConvertPtr(argo0,(void **) &arg0,SWIGTYPE_p_DBFFile,1)) == -1) return NULL;
-    {
-        #ifndef NOCHECK_DBFFile_field_info
-        if (!arg0 || !arg0->handle)
-        SWIG_exception(SWIG_TypeError, "dbffile already closed");
-        #endif
-    }
-    result = (int )DBFFile_field_info(arg0,arg1,arg2,arg3,arg4);
-    resultobj = PyInt_FromLong((long)result);
-    {
-        PyObject * string = PyString_FromString(arg2);
-        resultobj = t_output_helper(resultobj,string);
-    }
-    {
-        PyObject *o;
-        o = PyInt_FromLong((long) (*arg3));
-        resultobj = t_output_helper(resultobj, o);
-    }
-    {
-        PyObject *o;
-        o = PyInt_FromLong((long) (*arg4));
-        resultobj = t_output_helper(resultobj, o);
-    }
-    return resultobj;
-}
-
-
-PyObject * DBFFile_read_record(DBFFile *self,int record) {
-    {
-        return DBFInfo_read_record(self->handle, record);
-    }
-}
-
-
-static PyObject *_wrap_DBFFile_read_record(PyObject *self, PyObject *args) {
-    PyObject *resultobj;
-    DBFFile *arg0 ;
-    int arg1 ;
-    PyObject * argo0 =0 ;
-    PyObject *result ;
-    
-    if(!PyArg_ParseTuple(args,"Oi:DBFFile_read_record",&argo0,&arg1)) return NULL;
-    if ((SWIG_ConvertPtr(argo0,(void **) &arg0,SWIGTYPE_p_DBFFile,1)) == -1) return NULL;
-    {
-        #ifndef NOCHECK_DBFFile_read_record
-        if (!arg0 || !arg0->handle)
-        SWIG_exception(SWIG_TypeError, "dbffile already closed");
-        #endif
-    }
-    result = (PyObject *)DBFFile_read_record(arg0,arg1);
-    {
-        resultobj = result;
-    }
-    return resultobj;
-}
-
-
-PyObject * DBFFile_read_attribute(DBFFile *self,int record,int field) {
-    {
-        return DBFInfo_read_attribute(self->handle, record, field);
-    }
-}
-
-
-static PyObject *_wrap_DBFFile_read_attribute(PyObject *self, PyObject *args) {
-    PyObject *resultobj;
-    DBFFile *arg0 ;
-    int arg1 ;
-    int arg2 ;
-    PyObject * argo0 =0 ;
-    PyObject *result ;
-    
-    if(!PyArg_ParseTuple(args,"Oii:DBFFile_read_attribute",&argo0,&arg1,&arg2)) return NULL;
-    if ((SWIG_ConvertPtr(argo0,(void **) &arg0,SWIGTYPE_p_DBFFile,1)) == -1) return NULL;
-    {
-        #ifndef NOCHECK_DBFFile_read_attribute
-        if (!arg0 || !arg0->handle)
-        SWIG_exception(SWIG_TypeError, "dbffile already closed");
-        #endif
-    }
-    result = (PyObject *)DBFFile_read_attribute(arg0,arg1,arg2);
-    {
-        resultobj = result;
-    }
-    return resultobj;
-}
-
-
-int  DBFFile_add_field(DBFFile *self,char const *pszFieldName,DBFFieldType eType,int nWidth,int nDecimals) {
-    {
-        return DBFAddField(self->handle, pszFieldName, eType, nWidth,
-        nDecimals);
-    }
-}
-
-
-static PyObject *_wrap_DBFFile_add_field(PyObject *self, PyObject *args) {
-    PyObject *resultobj;
-    DBFFile *arg0 ;
-    char *arg1 ;
-    int arg2 ;
-    int arg3 ;
-    int arg4 ;
-    PyObject * argo0 =0 ;
-    int result ;
-    
-    if(!PyArg_ParseTuple(args,"Osiii:DBFFile_add_field",&argo0,&arg1,&arg2,&arg3,&arg4)) return NULL;
-    if ((SWIG_ConvertPtr(argo0,(void **) &arg0,SWIGTYPE_p_DBFFile,1)) == -1) return NULL;
-    {
-        #ifndef NOCHECK_DBFFile_add_field
-        if (!arg0 || !arg0->handle)
-        SWIG_exception(SWIG_TypeError, "dbffile already closed");
-        #endif
-    }
-    {
-        result = (int )DBFFile_add_field(arg0,(char const *)arg1,(DBFFieldType )arg2,arg3,arg4);
-        ;
-        if (result < 0)
-        {
-            SWIG_exception(SWIG_RuntimeError, "add_field failed");
-        }
-    }resultobj = PyInt_FromLong((long)result);
-    return resultobj;
-}
-
-
-PyObject * DBFFile_write_record(DBFFile *self,int record,PyObject *dict_or_sequence) {
-    {
-        return DBFInfo_write_record(self->handle, record,
-        dict_or_sequence);
-    }
-}
-
-
-static PyObject *_wrap_DBFFile_write_record(PyObject *self, PyObject *args) {
-    PyObject *resultobj;
-    DBFFile *arg0 ;
-    int arg1 ;
-    PyObject *arg2 ;
-    PyObject * argo0 =0 ;
-    PyObject * obj2  = 0 ;
-    PyObject *result ;
-    
-    if(!PyArg_ParseTuple(args,"OiO:DBFFile_write_record",&argo0,&arg1,&obj2)) return NULL;
-    if ((SWIG_ConvertPtr(argo0,(void **) &arg0,SWIGTYPE_p_DBFFile,1)) == -1) return NULL;
-    {
-        arg2 = obj2;
-    }
-    {
-        #ifndef NOCHECK_DBFFile_write_record
-        if (!arg0 || !arg0->handle)
-        SWIG_exception(SWIG_TypeError, "dbffile already closed");
-        #endif
-    }
-    result = (PyObject *)DBFFile_write_record(arg0,arg1,arg2);
-    {
-        resultobj = result;
-    }
-    return resultobj;
-}
-
-
-void  DBFFile_commit(DBFFile *self) {
-    {
-        DBFInfo_commit(self->handle);
-    }
-}
-
-
-static PyObject *_wrap_DBFFile_commit(PyObject *self, PyObject *args) {
-    PyObject *resultobj;
-    DBFFile *arg0 ;
-    PyObject * argo0 =0 ;
-    
-    if(!PyArg_ParseTuple(args,"O:DBFFile_commit",&argo0)) return NULL;
-    if ((SWIG_ConvertPtr(argo0,(void **) &arg0,SWIGTYPE_p_DBFFile,1)) == -1) return NULL;
-    {
-        #ifndef NOCHECK_DBFFile_commit
-        if (!arg0 || !arg0->handle)
-        SWIG_exception(SWIG_TypeError, "dbffile already closed");
-        #endif
-    }
-    DBFFile_commit(arg0);
-    Py_INCREF(Py_None);
-    resultobj = Py_None;
-    return resultobj;
-}
-
-
-static PyMethodDef dbflibcMethods[] = {
-	 { "open", _wrap_open, METH_VARARGS },
-	 { "create", _wrap_create, METH_VARARGS },
-	 { "new_DBFFile", _wrap_new_DBFFile, METH_VARARGS },
-	 { "delete_DBFFile", _wrap_delete_DBFFile, METH_VARARGS },
-	 { "DBFFile_close", _wrap_DBFFile_close, METH_VARARGS },
-	 { "DBFFile_field_count", _wrap_DBFFile_field_count, METH_VARARGS },
-	 { "DBFFile_record_count", _wrap_DBFFile_record_count, METH_VARARGS },
-	 { "DBFFile_field_info", _wrap_DBFFile_field_info, METH_VARARGS },
-	 { "DBFFile_read_record", _wrap_DBFFile_read_record, METH_VARARGS },
-	 { "DBFFile_read_attribute", _wrap_DBFFile_read_attribute, METH_VARARGS },
-	 { "DBFFile_add_field", _wrap_DBFFile_add_field, METH_VARARGS },
-	 { "DBFFile_write_record", _wrap_DBFFile_write_record, METH_VARARGS },
-	 { "DBFFile_commit", _wrap_DBFFile_commit, METH_VARARGS },
-	 { NULL, NULL }
-};
-
-#ifdef __cplusplus
-}
-#endif
-
-/* -------- TYPE CONVERSION AND EQUIVALENCE RULES (BEGIN) -------- */
-
-static swig_type_info _swigt__p_DBFFile[] = {{"_p_DBFFile", 0, "DBFFile *"},{"_p_DBFFile"},{0}};
-
-static swig_type_info *swig_types_initial[] = {
-_swigt__p_DBFFile, 
-0
-};
-
-
-/* -------- TYPE CONVERSION AND EQUIVALENCE RULES (END) -------- */
-
-static swig_const_info swig_const_table[] = {
-    { SWIG_PY_INT,     "FTString", (long) FTString, 0, 0, 0},
-    { SWIG_PY_INT,     "FTInteger", (long) FTInteger, 0, 0, 0},
-    { SWIG_PY_INT,     "FTDouble", (long) FTDouble, 0, 0, 0},
-    { SWIG_PY_INT,     "FTInvalid", (long) FTInvalid, 0, 0, 0},
-    { SWIG_PY_INT,     "_have_commit", (long) HAVE_UPDATE_HEADER, 0, 0, 0},
-{0}};
-
-static PyObject *SWIG_globals;
-#ifdef __cplusplus
-extern "C" 
-#endif
-SWIGEXPORT(void) initdbflibc(void) {
-    PyObject *m, *d;
-    int i;
-    SWIG_globals = SWIG_newvarlink();
-    m = Py_InitModule("dbflibc", dbflibcMethods);
-    d = PyModule_GetDict(m);
-    for (i = 0; swig_types_initial[i]; i++) {
-        swig_types[i] = SWIG_TypeRegister(swig_types_initial[i]);
-    }
-    SWIG_InstallConstants(d,swig_const_table);
-
-#   if PY_VERSION_HEX >=0x02040000 
-    /* because we are in a python module now, we can give out
-     * pointers to python's locale agonistic function 
-     * XXX this clearly is a hack
-     */
-    DBFSetatof_function(&PyOS_ascii_atof);
-#   endif
-
-}
-

Copied: branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/dbflibmodule.c (from rev 2755, branches/WIP-pyshapelib-bramz/libraries/pyshapelib/dbflibmodule.c)

Modified: branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/pyshapelib_api.h
===================================================================
--- branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/pyshapelib_api.h	2007-12-12 20:23:04 UTC (rev 2794)
+++ branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/pyshapelib_api.h	2007-12-12 20:35:20 UTC (rev 2795)
@@ -22,7 +22,7 @@
  * assign it to the variable given as argument */
 #define PYSHAPELIB_IMPORT_API(apivariable)				   \
 {									   \
-    PyObject * shapelib = PyImport_ImportModule("shapelibc");		   \
+    PyObject * shapelib = PyImport_ImportModule("shapelib");		   \
     if (shapelib)							   \
     {									   \
 	PyObject * c_api_func = PyObject_GetAttrString(shapelib, "c_api"); \

Copied: branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/pyshapelib_common.h (from rev 2755, branches/WIP-pyshapelib-bramz/libraries/pyshapelib/pyshapelib_common.h)

Modified: branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/pytest.py
===================================================================
--- branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/pytest.py	2007-12-12 20:23:04 UTC (rev 2794)
+++ branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/pytest.py	2007-12-12 20:35:20 UTC (rev 2795)
@@ -4,17 +4,51 @@
 #       The the shapefile module
 #
 
+def test_shpobject(obj):
+    # The vertices method returns the shape as a list of lists of tuples.
+    print "vertices:", obj.vertices()
+    
+    # The part_types method returns a tuple with the types of every part
+    print "part_types:", obj.part_types()
+
+    # The extents returns a tuple with two 4-element lists with the min.
+    # and max. values of the vertices.
+    print "extents:", obj.extents()
+
+    # The type attribute is the type code (one of the SHPT* constants
+    # defined in the shapelib module)
+    print "type:", obj.type
+
+    # The id attribute is the shape id
+    print "id:", obj.id
+    
+    # the __repr__ method returns a string that can be eval()'ed to 
+    # recreate the object.  This __repr__ is also used by __str__
+    # and print
+    print "obj:", obj
+    print "reconstruction using __repr__:",
+    obj_repr = repr(obj)
+    obj_copy = eval(obj_repr)
+    if repr(obj_copy) == obj_repr:
+        print "ok"
+    else:
+        print "failed"
+    
+
+    
 def make_shapefile(filename):
+    print "\n* Creating a ShapeFile"
+    
     # Create a shapefile with polygons
     outfile = shapelib.create(filename, shapelib.SHPT_POLYGON)
 
     # Create one very simple polygon and write it to the shapefile.  The
     # vertices should be given in clockwise order to comply with the
     # shapefile specification.
+    print "\nA very simple polygon"
     obj = shapelib.SHPObject(shapelib.SHPT_POLYGON, 1,
                              [[(10, 10), (10, 20), (20, 20), (10, 10)]])
-    print obj.extents()
-    print obj.vertices()
+    test_shpobject(obj)
     outfile.write_object(-1, obj)
 
     # Create a polygon with a hole.  Note that according to the
@@ -26,18 +60,20 @@
     # list of part types, one for each part of the shape.  For polygons,
     # the part type is always shapelib.SHPP_RING, though.  The part
     # types are only relevant for SHPT_MULTIPATCH shapefiles.
+    print "\nPolygon with a hole"
     obj = shapelib.SHPObject(shapelib.SHPT_POLYGON, 1,
                              [[(0, 0), (0, 40), (40, 40), (40, 0), (0, 0)],
                               [(10, 10), (20, 10), (20, 20), (10, 20),(10, 10)],
                               ])
-    print obj.extents()
-    print obj.vertices()
+    test_shpobject(obj)
     outfile.write_object(-1, obj)
 
     # close the file.
     outfile.close()
 
 def read_shapefile(filename):
+    print "\n* Reading a ShapeFile"
+    
     # open the shapefile
     shp = shapelib.ShapeFile(filename)
 
@@ -46,30 +82,21 @@
     # the SHPT* constants defined in the shapelib module) and min and
     # max are 4-element lists with the min. and max. values of the
     # vertices.
-    print shp.info()
+    print "info:", shp.info()
 
-    # read_object reads a shape
-    obj = shp.read_object(0)
-
-    # The vertices method returns the shape as a list of lists of tuples.
-    print obj.vertices()[0][:10]
-
-    # The extents returns a tuple with two 4-element lists with the min.
-    # and max. values of the vertices.
-    print obj.extents()
-
-    # The type attribute is the type code (one of the SHPT* constants
-    # defined in the shapelib module)
-    print obj.type
-
-    # The id attribute is the shape id
-    print obj.id
-
     # the cobject method returns a PyCObject containing the shapelib
     # SHPHandle. This is useful for passing shapefile objects to
     # C-Python extensions.
-    print shp.cobject()
+    print "cobject:", shp.cobject()
+    
+    n = shp.info()[0]
+    for i in range(n):
+        obj = shp.read_object(i)
+        print "\nread_object(%i):" % i
+        test_shpobject(obj)
 
+    print "\n* SHPTree:"
+    
     # build a quad tree from the shapefile. The first argument must be
     # the return value of the shape file object's cobject method (this
     # is currently needed to access the shape file at the C-level). The
@@ -83,27 +110,87 @@
     print tree.find_shapes(minima[:2], maxima[:2])
 
 
+print "--- testing shapelib ---"
+
 make_shapefile("testfile")
 read_shapefile("testfile")
 
 #
+#		Test MultiPatch shapefiles
+#
+
+def make_multipatch(filename):
+    print "\n* Creating multipatch ShapeFile"
+    
+    # Create a shapefile with multipatches
+    outfile = shapelib.create(filename, shapelib.SHPT_MULTIPATCH)
+
+    # Create a quad as a triangle strip and as a triangle fan, in ONE object!
+    # Multipatch shapefiles use XYZM vertices, but you can get away with
+    # only specifying X and Y, Z and M are zero by default.
+    print "\nA triangle strip"
+    obj = shapelib.SHPObject(shapelib.SHPT_MULTIPATCH, 0,
+        [[(0, 0), (0, 10), (10, 0), (10, 10)],
+         [(20, 20), (20, 30), (30, 30), (30, 20)]], 
+        [shapelib.SHPP_TRISTRIP, shapelib.SHPP_TRIFAN])
+    test_shpobject(obj)
+    outfile.write_object(-1, obj)
+    
+    # A polygon as an Outer ring and inner ring, with XYZ coordinates
+    # and measure values M.  Here we will use the part types to specify 
+    # their particular type.
+    #
+    # You can have more than one polygon in a single Object, as long
+    # as you obey the following sequence: each polygon starts with an
+    # outer ring, followed by its holes as inner rings.  
+    #
+    # None is also accepted as M value to specify no-data.  The ESRI
+    # Shapefile specs define any M value smaller than 1e-38 as no-data.
+    # shapelib will store no-data as a zero. 
+    #
+    # If you don't need the M value, you can leave it out and use triples 
+    # as vertices instead.  For the first half of the inner ring,
+    # we used None to specify no-data.  In the second half, we just 
+    # omitted it.
+    #
+    print "\nA polygon as outer ring and inner ring with XYZM coordinates"
+    obj = shapelib.SHPObject(shapelib.SHPT_MULTIPATCH, 1,
+        [[(0, 0, 0, 35.3), (0, 40, 10, 15.4), (40, 40, 20, 9.5), (40, 0, 10, 24.6), (0, 0, 0, 31.8)],
+         [(10, 10, 5, None), (20, 10, 10, None), (20, 20, 15), (10, 20, 10, 20),(10, 10, 5)]],
+        [shapelib.SHPP_OUTERRING, shapelib.SHPP_INNERRING])
+    test_shpobject(obj)
+    outfile.write_object(-1, obj)
+
+    # close the file.
+    outfile.close()
+    
+
+print "--- testing multipatch ---"
+
+make_multipatch("multipatch")
+read_shapefile("multipatch")
+    
+#
 #       Test the DBF file module.
 #
 
+print "\n\n--- testing dbflib ---"
+
 def make_dbf(file):
     # create a new dbf file and add three fields.
     dbf = dbflib.create(file)
     dbf.add_field("NAME", dbflib.FTString, 20, 0)
     dbf.add_field("INT", dbflib.FTInteger, 10, 0)
     dbf.add_field("FLOAT", dbflib.FTDouble, 10, 4)
+    dbf.add_field("BOOL", dbflib.FTLogical, 1, 0)
 
 def add_dbf_records(file):
     # add some records to file
     dbf = dbflib.open(file, "r+b")
     # Records can be added as a dictionary...
-    dbf.write_record(0, {'NAME': "Weatherwax", "INT":1, "FLOAT":3.1415926535})
+    dbf.write_record(0, {'NAME': "Weatherwax", "INT":1, "FLOAT":3.1415926535, "BOOL":True})
     # ... or as a sequence
-    dbf.write_record(1, ("Ogg", 2, -1000.1234))
+    dbf.write_record(1, ("Ogg", 2, -1000.1234, False))
 
 def list_dbf(file):
     # print the contents of a dbf file to stdout
@@ -112,12 +199,14 @@
     format = ""
     for i in range(dbf.field_count()):
         type, name, len, decc = dbf.field_info(i)
-        if type == 0:
+        if type == dbflib.FTString:
             format = format + " %%(%s)%ds" % (name, len)
-        elif type == 1:
+        elif type == dbflib.FTInteger:
             format = format + " %%(%s)%dd" % (name, len)
-        elif type == 2:
+        elif type == dbflib.FTDouble:
             format = format + " %%(%s)%dg" % (name, len)
+        elif type == dbflib.FTLogical:
+            format = format + " %%(%s)s" % name
     print format
     for i in range(dbf.record_count()):
         print format % dbf.read_record(i)

Modified: branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/setup.py
===================================================================
--- branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/setup.py	2007-12-12 20:23:04 UTC (rev 2794)
+++ branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/setup.py	2007-12-12 20:35:20 UTC (rev 2795)
@@ -21,52 +21,60 @@
 # filenames exclusively, so we use posix conventions when making
 # filenames for distutils.
 for shp_dir in ["..", "../shapelib", "../../../../../../shapelib"]:
-    if (os.path.isdir(convert_path(shp_dir))
-        and os.path.exists(os.path.join(convert_path(shp_dir), "shpopen.c"))):
-        # shp_dir contains shpopen.c, so assume it's the directory with
-        # the shapefile library to use
-        break
+	if (os.path.isdir(convert_path(shp_dir))
+		and os.path.exists(os.path.join(convert_path(shp_dir), "shpopen.c"))):
+		# shp_dir contains shpopen.c, so assume it's the directory with
+		# the shapefile library to use
+		break
 else:
-    print >>sys.stderr, "no shapelib directory found"
-    sys.exit(1)
+	print >>sys.stderr, "no shapelib directory found"
+	sys.exit(1)
 
 def dbf_macros():
-    """Return the macros to define when compiling the dbflib wrapper.
+	"""Return the macros to define when compiling the dbflib wrapper.
 
-    The returned list specifies one macro, HAVE_UPDATE_HEADER, which is
-    '1' if the dbflib version we will be compiling with has the
-    DBFUpdateHeader function and '0' otherwise.  To check whether
-    DBFUpdateHeader is available, we scan shapefil.h for the string
-    'DBFUpdateHeader'.
-    """
-    f = open(convert_path(shp_dir + "/shapefil.h"))
-    contents = f.read()
-    f.close()
-    if contents.find("DBFUpdateHeader") >= 0:
-        return [("HAVE_UPDATE_HEADER", "1")]
-    else:
-        return [("HAVE_UPDATE_HEADER", "0")]
+	The returned list specifies following macros:
+	- HAVE_UPDATE_HEADER, which is 
+	'1' if the dbflib version we will be compiling with has the
+	DBFUpdateHeader function and '0' otherwise.  To check whether
+	DBFUpdateHeader is available, we scan shapefil.h for the string
+	'DBFUpdateHeader'.
+	- HAVE_LANGUAGE_DRIVER, whics is '1' if the dbflib version we will 
+	compiling with has the nLanguageDriver field in DBFInfo and '0' otherwise.
+	Again, shapefil.h is scanned to check this.
+	"""
+	f = open(convert_path(shp_dir + "/shapefil.h"))
+	contents = f.read()
+	f.close()
+	
+	def have(keyword):
+		if keyword in contents:
+			return "1"
+		return 0
+	
+	return [
+		("HAVE_UPDATE_HEADER", have("DBFUpdateHeader")),
+		("HAVE_LANGUAGE_DRIVER", have("nLanguageDriver"))]
 
-extensions = [Extension("shapelibc",
-                        ["shapelib_wrap.c",
-                         shp_dir + "/shpopen.c",
-                         shp_dir + "/shptree.c"],
-                        include_dirs = [shp_dir]),
-              Extension("shptree",
-                        ["shptreemodule.c"],
-                        include_dirs = [shp_dir]),
-              Extension("dbflibc",
-                        ["dbflib_wrap.c",
-                         shp_dir + "/dbfopen.c"],
-                        include_dirs = [shp_dir],
-                        define_macros = dbf_macros())]
+extensions = [Extension("shapelib",
+						["shapelibmodule.c",
+						shp_dir + "/shpopen.c",
+						shp_dir + "/shptree.c"],
+						include_dirs = [shp_dir]),
+			Extension("shptree",
+						["shptreemodule.c"],
+						include_dirs = [shp_dir]),
+			Extension("dbflib",
+						["dbflibmodule.c",
+						shp_dir + "/dbfopen.c"],
+						include_dirs = [shp_dir],
+						define_macros = dbf_macros())]
 
 setup(name = "pyshapelib",
-      version = "0.3",
-      description = "Python bindings for shapelib",
-      author = "Bernhard Herzog",
-      author_email = "bh at intevation.de",
-      url = "ftp:intevation.de/users/bh",
-      py_modules = ["shapelib", "dbflib"],
-      ext_modules = extensions)
+	version = "0.3",
+	description = "Python bindings for shapelib",
+	author = "Bernhard Herzog",
+	author_email = "bh at intevation.de",
+	url = "ftp:intevation.de/users/bh",
+	ext_modules = extensions)
 

Deleted: branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/shapelib.i
===================================================================
--- branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/shapelib.i	2007-12-12 20:23:04 UTC (rev 2794)
+++ branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/shapelib.i	2007-12-12 20:35:20 UTC (rev 2795)
@@ -1,612 +0,0 @@
-/* SWIG (www.swig.org) interface file for shapelib
- *
- * At the moment (Dec 2000) this file is only useful to generate Python
- * bindings. Invoke swig as follows:
- *
- *	swig -python -shadow shapelib.i
- *
- * to generate shapelib_wrap.c and shapelib.py. shapelib_wrap.c
- * defines a bunch of Python-functions that wrap the appripriate
- * shapelib functions and shapelib.py contains an object oriented
- * wrapper around shapelib_wrap.c.
- *
- * Shapelib, and hence this module too, defines two types of objects,
- * shapes and shapefiles.
- */
-
-%module shapelib
-
-/*
- * First, a %{,%}-Block. These blocks are copied verbatim to the
- * shapelib_wrap.c file and are not parsed by SWIG. This is the place to
- * import headerfiles and define helper-functions that are needed by the
- * automatically generated wrappers.
- */
-
-%{
-
-/* import the shapelib headefile. */
-#include "shapefil.h"
-#include "pyshapelib_api.h"
-    
-/*
- * Rename a few shapelib functions that are effectively methods with
- * preprocessor macros so that they have the names that swig expects
- * (e.g. the destructor of SHPObject has to be called delete_SHPObject)
- */
-
-#define delete_SHPObject SHPDestroyObject
-    
-/*
- * The extents() method of SHPObject.
- *
- * Return the extents as a tuple of two 4-element lists with the min.
- * and max. values of x, y, z, m.
- */
-static PyObject *
-SHPObject_extents(SHPObject *object)
-{
-    return Py_BuildValue("[dddd][dddd]",
-			 object->dfXMin, object->dfYMin, object->dfZMin,
-			 object->dfMMin, 
-			 object->dfXMax, object->dfYMax, object->dfZMax,
-			 object->dfMMax);
-}
-
-
-/*
- * The vertices() method of SHPObject.
- *
- * Return the x and y coords of the vertices as a list of lists of
- * tuples.
- */
-
-static PyObject* build_vertex_list(SHPObject *object, int index, int length);
-
-static PyObject*
-SHPObject_vertices(SHPObject *object)
-{
-    PyObject *result = NULL;
-    PyObject *part = NULL;
-    int part_idx, vertex_idx;
-    int length = 0;
-
-
-    if (object->nParts > 0)
-    {
-	/* A multipart shape. Usual for SHPT_ARC and SHPT_POLYGON */
-	
-	result = PyList_New(object->nParts);
-	if (!result)
-	    return NULL;
-
-	for (part_idx = 0, vertex_idx = 0; part_idx < object->nParts;
-	     part_idx++)
-	{
-	    if (part_idx < object->nParts - 1)
-		length = (object->panPartStart[part_idx + 1]
-			  - object->panPartStart[part_idx]);
-	    else
-		length = object->nVertices - object->panPartStart[part_idx];
-	    
-	    part = build_vertex_list(object, vertex_idx, length);
-	    if (!part)
-		goto fail;
-
-	    if (PyList_SetItem(result, part_idx, part) < 0)
-		goto fail;
-
-	    vertex_idx += length;
-	}
-    }
-    else
-    {
-	/* only one part. usual for SHPT_POINT */
-	result = build_vertex_list(object, 0, object->nVertices);
-    }
-
-    return result;
-
- fail:
-    Py_XDECREF(part);
-    Py_DECREF(result);
-    return NULL;
-}
-
-
-/* Return the length coordinates of the shape object starting at vertex
- * index as a Python-list of tuples. Helper function for
- * SHPObject_vertices.
- */
-static PyObject*
-build_vertex_list(SHPObject *object, int index, int length)
-{
-    int i;
-    PyObject * list;
-    PyObject * vertex = NULL;
-
-    list = PyList_New(length);
-    if (!list)
-	return NULL;
-
-    for (i = 0; i < length; i++, index++)
-    {
-	vertex = Py_BuildValue("dd", object->padfX[index],
-			       object->padfY[index]);
-	if (!vertex)
-	    goto fail;
-	if (PyList_SetItem(list, i, vertex) < 0)
-	    goto fail;
-    }
-
-    return list;
-
- fail:
-    Py_XDECREF(vertex);
-    Py_DECREF(list);
-    return NULL;
-}
-
-
-
-
-
-/* The constructor of SHPObject. parts is a list of lists of tuples
- * describing the parts and their vertices just likethe output of the
- * vertices() method. part_type_list is the list of part-types and may
- * be NULL. For the meaning of the part-types and their default value
- * see the Shaplib documentation.
- */
-SHPObject * new_SHPObject(int type, int id, PyObject * parts,
-			  PyObject * part_type_list)
-{
-    /* arrays to hold thex and y coordinates of the  vertices */
-    double *xs = NULL, *ys = NULL;
-    /* number of all vertices of all parts */
-    int num_vertices;
-    /* number of parts in the list parts */
-    int num_parts;
-    /* start index of in xs and ys of the part currently worked on */
-    int part_start;
-    /* array of start indices in xs and ys as expected by shapelib */
-    int *part_starts = NULL;
-
-    /* generic counter */
-    int i;
-
-    /* array of part types. holds the converted content of
-     * part_type_list. Stays NULL of part_type_list is NULL
-     */
-    int *part_types = NULL;
-
-    /* temporary python objects referring to the the list items being
-     * worked on.
-     */
-    PyObject * part = NULL, *tuple = NULL;
-
-    /* The result object */
-    SHPObject *result;
-
-    num_parts = PySequence_Length(parts);
-    num_vertices = 0; 
-
-    /* parts and part_types have to have the same lengths */
-    if (part_type_list
-	&& PySequence_Length(parts) != PySequence_Length(part_type_list))
-    {
-	PyErr_SetString(PyExc_TypeError,
-			"parts and part_types have to have the same lengths");
-	return NULL;
-    }
-
-    /* determine how many vertices there are altogether */
-    for (i = 0; i < num_parts; i++)
-    {
-	PyObject * part = PySequence_GetItem(parts, i);
-	if (!part)
-	    return NULL;
-	num_vertices += PySequence_Length(part);
-	Py_DECREF(part);
-    }
-
-    /* allocate the memory for the various arrays and check for memory
-       errors */
-    xs = malloc(num_vertices * sizeof(double));
-    ys = malloc(num_vertices * sizeof(double));
-    part_starts = malloc(num_parts * sizeof(int));
-    if (part_type_list)
-	part_types = malloc(num_parts * sizeof(int));
-
-    if (!xs || !ys || !part_starts || (part_type_list && !part_types))
-    {
-	PyErr_NoMemory();
-	goto fail;
-    }
-
-    /* convert the part types */
-    if (part_type_list)
-    {
-	for (i = 0; i < num_parts; i++)
-	{
-	    PyObject * otype = PySequence_GetItem(part_type_list, i);
-	    if (!otype)
-		return NULL;
-	    part_types[i] = PyInt_AsLong(otype);
-	    Py_DECREF(otype);
-	}
-    }
-
-    /* convert the list of parts */
-    part_start = 0;
-    for (i = 0; i < num_parts; i++)
-    {
-	int j, length;
-
-	part = PySequence_GetItem(parts, i);
-	length = PySequence_Length(part);
-	part_starts[i] = part_start;
-
-	for (j = 0; j < length; j++)
-	{
-	    tuple = PySequence_GetItem(part, j);
-	    if (!tuple)
-		goto fail;
-
-	    if (!PyArg_ParseTuple(tuple, "dd", xs + part_start + j,
-				  ys + part_start + j))
-	    {
-		goto fail;
-	    }
-	    Py_DECREF(tuple);
-	    tuple = NULL;
-	}
-	Py_DECREF(part);
-	part = NULL;
-	part_start += length;
-    }
-
-    result = SHPCreateObject(type, id, num_parts, part_starts, part_types,
-			     num_vertices, xs, ys, NULL, NULL);
-    free(xs);
-    free(ys);
-    free(part_starts);
-    free(part_types);
-    return result;
-
- fail:
-    free(xs);
-    free(ys);
-    free(part_starts);
-    free(part_types);
-    Py_XDECREF(part);
-    Py_XDECREF(tuple);
-    return NULL;
-}
-
-%}
-
-
-
-/*
- * The SWIG Interface definition.
- */
-
-/* include some common SWIG type definitions and standard exception
-   handling code */
-%include typemaps.i
-%include exception.i
-
-
-/*
- *  SHPObject -- Represents one shape
- */
-
-/* Exception typemap for the SHPObject constructor. The constructor the
-   the wrapper function defined above which returns NULL in case of
-   error. */
-   
-%typemap(python,except) SHPObject*new_SHPObject {
-    $function;
-    if (PyErr_Occurred())
-	return NULL;
-}
-
-/* Define the SHPObject struct for SWIG. This has to have the same name
- * as the underlying C-struct in shapfil.h, but we don't have to repeat
- * all the fields here, only those we want to access directly, and we
- * can define methods for the object oriented interface.
- */
-
-typedef struct {
-
-    /* The shape object has two read-only attributes: */
-
-    /* The type of the shape. In the c-struct defined the field is
-     * called 'nSHPType' but for the python bindings 'type' is more
-     * appropriate.
-     */
-    %readonly %name(type) int nSHPType;
-
-    /* The id of the shape. Here 'id' is a better name than 'nShapeId'. */
-    %readonly %name(id) int nShapeId;
-
-    /* The methods */
-    %addmethods {
-
-	/* the constructor */
-	SHPObject(int type, int id, PyObject * parts,
-		  PyObject * part_types = NULL);
-
-	/* The destructor */
-	~SHPObject();
-
-	/* extents and vertices correspond to the SHPObject_extents and
-	 * SHPObject_vertices defined above
-	 */
-	PyObject *extents();
-	PyObject *vertices();
-    }
-} SHPObject;
-
-
-/*
- * ShapeFile --  Represents the shape file
- */
-
-/* Here we do things a little different. We define a new C-struct that
- * holds the SHPHandle. This is mainly done so we can separate the
- * close() method from the destructor but it also helps with exception
- * handling.
- *
- * After the ShapeFile has been opened or created the handle is not
- * NULL. The close() method closes the file and sets handle to NULL as
- * an indicator that the file has been closed.
- */
-
-/* First, define the C-struct */
-%{
-    typedef struct {
-	SHPHandle handle;
-    } ShapeFile;
-%}
-
-/* define and use some typemaps for the info() method whose
- * C-implementation has four output parameters that are returned through
- * pointers passed into the function. SWIG already has definitions for
- * common types such as int* and we can use those for the first two
- * parameters:
- */
- 
-%apply int * OUTPUT { int * output_entities }
-%apply int * OUTPUT { int * output_type }
-
-/* for the last two, the 4-element arrays of min- and max-values, we
- * have to define our own typemaps:
- */
-%typemap (python,ignore) double * extents(double temp[4]) {
-    $target = temp;
-}
-
-%typemap (python,argout) double * extents {
-    PyObject * list = Py_BuildValue("[dddd]",
-				    $source[0], $source[1],
-				    $source[2], $source[3]);
-    $target = t_output_helper($target,list);
-}
-
-%apply double * extents { double * output_min_bounds }
-%apply double * extents { double * output_max_bounds }
-
-/* The first argument to the ShapeFile methods is a ShapeFile pointer.
- * We have to check whether handle is not NULL in most methods but not
- * all. In the destructor and the close method, it's OK for handle to be
- * NULL. We achieve this by checking whether the preprocessor macro
- * NOCHECK_$name is defined. SWIG replaces $name with the name of the
- * function for which the code is inserted. In the %{,%}-block below we
- * define the macros for the destructor and the close() method.
- */
-
-
-%typemap(python,check) ShapeFile *{
-    %#ifndef NOCHECK_$name
-    if (!$target || !$target->handle)
-	SWIG_exception(SWIG_TypeError, "shapefile already closed");
-    %#endif
-}
-
-%{
-#define NOCHECK_delete_ShapeFile
-#define NOCHECK_ShapeFile_close
-%}
-
-/* An exception handle for the constructor and the module level open()
- * and create() functions.
- *
- * Annoyingly, we *have* to put braces around the SWIG_exception()
- * calls, at least in the python case, because of the way the macro is
- * written. Of course, always putting braces around the branches of an
- * if-statement is often considered good practice.
- */
-%typemap(python,except) ShapeFile * {
-    $function;
-    if (!$source)
-    {
-    	SWIG_exception(SWIG_MemoryError, "no memory");
-    }
-    else if (!$source->handle)
-    {
-	SWIG_exception(SWIG_IOError, "$name failed");
-    }
-}
-
-
-/*
- * The SWIG-version of the ShapeFile struct.
- */
-
-typedef struct
-{
-    /* Only methods and no attributes here: */ 
-    %addmethods {
-
-	/* The constructor. Takes two arguments, the filename and the
-	 * optinal mode which are passed through to SHPOpen (due to the
-	 * renaming trick)
-	 */
-	ShapeFile(char *file, char * mode = "rb") {
-	    ShapeFile * self = malloc(sizeof(ShapeFile));
-	    if (self)
-		self->handle = SHPOpen(file, mode);
-	    return self;
-	}
-
-	/* The destructor. Equivalent to SHPClose */
-	~ShapeFile() {
-	    if (self->handle)
-		SHPClose(self->handle);
-	    free(self);
-	}
-
-	/* close the shape file and set handle to NULL */
-	void close() {
-	    if (self->handle)
-	    {
-		SHPClose(self->handle);
-		self->handle = NULL;
-	    }
-	}
-
-	/* info() -- Return a tuple (NUM_SHAPES, TYPE, MIN, MAX) where
-	 * NUM_SHAPES is the number of shapes in the file, TYPE is the
-	 * shape type and MIN and MAX are 4-element lists with the min.
-	 * and max. values of the data.
-	 *
-	 * The arguments of the underlying shapelib function SHPGetInfo
-	 * are all output parameters. To tell SWIG this, we have defined
-	 * some typemaps above
-	 */
-	void info(int * output_entities, int * output_type,
-		  double * output_min_bounds, double *output_max_bounds) {
-	    SHPGetInfo(self->handle, output_entities, output_type,
-		       output_min_bounds, output_max_bounds);
-	}
-
-	/* Return object number i */
-	%new SHPObject * read_object(int i) {
-	    return SHPReadObject(self->handle, i);
-	}
-
-	/* Write an object */
-	int write_object(int iShape, SHPObject * psObject) {
-	    return SHPWriteObject(self->handle, iShape, psObject);
-	}
-
-	/* Return the shapelib SHPHandle as a Python CObject */
-	PyObject * cobject() {
-	    return PyCObject_FromVoidPtr(self->handle, NULL);
-	}
-    }
-
-} ShapeFile;
-
-
-/*
- * Two module level functions, open() and create() that correspond to
- * SHPOpen and SHPCreate respectively. open() is equivalent to the
- * ShapeFile constructor.
- */
-
-%{
-    ShapeFile * open_ShapeFile(const char *filename, const char * mode) {
-	ShapeFile * self = malloc(sizeof(ShapeFile));
-	if (self)
-	    self->handle = SHPOpen(filename, mode);
-	return self;
-    }
-%}
-
-%name(open) %new ShapeFile *open_ShapeFile(const char *filename,
-					   const char * mode = "rb");
-
-
-%{
-    ShapeFile * create_ShapeFile(const char *filename, int type) {
-	ShapeFile * self = malloc(sizeof(ShapeFile));
-	if (self)
-	    self->handle = SHPCreate(filename, type);
-	return self;
-    }
-%}    
-
-%name(create) %new ShapeFile * create_ShapeFile(const char *filename,
-						int type);
-    
-
-/* Module level function to expose some of the shapelib functions linked
- * with the shapefile C-module to other Python extension modules. This
- * is a kludge to make a Thuban extension work that reads shapes from
- * shapefiles opened by the shapefile module.
- */
-
-%{
-    static PyShapeLibAPI the_api = {
-	SHPReadObject,
-	SHPDestroyObject,
-	SHPCreateTree,
-	SHPDestroyTree,
-	SHPTreeFindLikelyShapes
-    };
-
-    PyObject * c_api() {
-	return PyCObject_FromVoidPtr(&the_api, NULL);
-    }
-%}
-
-PyObject * c_api();
-
-
-/*
- *  Module Level functions 
- */
-
-/* convert shapefile types to names */
-%name(type_name) const char *SHPTypeName(int nSHPType);
-%name(part_type_name) const char *SHPPartTypeName(int nPartType);
-
-
-/*
- * Finally, constants copied from shapefil.h
- */
-
-/* -------------------------------------------------------------------- */
-/*      Shape types (nSHPType)                                          */
-/* -------------------------------------------------------------------- */
-#define SHPT_NULL	0
-#define SHPT_POINT	1
-#define SHPT_ARC	3
-#define SHPT_POLYGON	5
-#define SHPT_MULTIPOINT	8
-#define SHPT_POINTZ	11
-#define SHPT_ARCZ	13
-#define SHPT_POLYGONZ	15
-#define SHPT_MULTIPOINTZ 18
-#define SHPT_POINTM	21
-#define SHPT_ARCM	23
-#define SHPT_POLYGONM	25
-#define SHPT_MULTIPOINTM 28
-#define SHPT_MULTIPATCH 31
-
-
-/* -------------------------------------------------------------------- */
-/*      Part types - everything but SHPT_MULTIPATCH just uses           */
-/*      SHPP_RING.                                                      */
-/* -------------------------------------------------------------------- */
-
-#define SHPP_TRISTRIP	0
-#define SHPP_TRIFAN	1
-#define SHPP_OUTERRING	2
-#define SHPP_INNERRING	3
-#define SHPP_FIRSTRING	4
-#define SHPP_RING	5
-
-

Deleted: branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/shapelib.py
===================================================================
--- branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/shapelib.py	2007-12-12 20:23:04 UTC (rev 2794)
+++ branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/shapelib.py	2007-12-12 20:35:20 UTC (rev 2795)
@@ -1,119 +0,0 @@
-# This file was created automatically by SWIG.
-import shapelibc
-class SHPObject:
-    def __init__(self,*args):
-        self.this = apply(shapelibc.new_SHPObject,args)
-        self.thisown = 1
-
-    def __del__(self,shapelibc=shapelibc):
-        if self.thisown == 1 :
-            shapelibc.delete_SHPObject(self)
-    def extents(*args):
-        val = apply(shapelibc.SHPObject_extents,args)
-        return val
-    def vertices(*args):
-        val = apply(shapelibc.SHPObject_vertices,args)
-        return val
-    __setmethods__ = {
-    }
-    def __setattr__(self,name,value):
-        if (name == "this") or (name == "thisown"): self.__dict__[name] = value; return
-        method = SHPObject.__setmethods__.get(name,None)
-        if method: return method(self,value)
-        self.__dict__[name] = value
-    __getmethods__ = {
-        "type" : shapelibc.SHPObject_type_get,
-        "id" : shapelibc.SHPObject_id_get,
-    }
-    def __getattr__(self,name):
-        method = SHPObject.__getmethods__.get(name,None)
-        if method: return method(self)
-        raise AttributeError,name
-    def __repr__(self):
-        return "<C SHPObject instance at %s>" % (self.this,)
-class SHPObjectPtr(SHPObject):
-    def __init__(self,this):
-        self.this = this
-        self.thisown = 0
-        self.__class__ = SHPObject
-
-
-
-class ShapeFile:
-    def __init__(self,*args):
-        self.this = apply(shapelibc.new_ShapeFile,args)
-        self.thisown = 1
-
-    def __del__(self,shapelibc=shapelibc):
-        if self.thisown == 1 :
-            shapelibc.delete_ShapeFile(self)
-    def close(*args):
-        val = apply(shapelibc.ShapeFile_close,args)
-        return val
-    def info(*args):
-        val = apply(shapelibc.ShapeFile_info,args)
-        return val
-    def read_object(*args):
-        val = apply(shapelibc.ShapeFile_read_object,args)
-        if val: val = SHPObjectPtr(val) ; val.thisown = 1
-        return val
-    def write_object(*args):
-        val = apply(shapelibc.ShapeFile_write_object,args)
-        return val
-    def cobject(*args):
-        val = apply(shapelibc.ShapeFile_cobject,args)
-        return val
-    def __repr__(self):
-        return "<C ShapeFile instance at %s>" % (self.this,)
-class ShapeFilePtr(ShapeFile):
-    def __init__(self,this):
-        self.this = this
-        self.thisown = 0
-        self.__class__ = ShapeFile
-
-
-
-
-
-#-------------- FUNCTION WRAPPERS ------------------
-
-def open(*args, **kwargs):
-    val = apply(shapelibc.open,args,kwargs)
-    if val: val = ShapeFilePtr(val); val.thisown = 1
-    return val
-
-def create(*args, **kwargs):
-    val = apply(shapelibc.create,args,kwargs)
-    if val: val = ShapeFilePtr(val); val.thisown = 1
-    return val
-
-c_api = shapelibc.c_api
-
-type_name = shapelibc.type_name
-
-part_type_name = shapelibc.part_type_name
-
-
-
-#-------------- VARIABLE WRAPPERS ------------------
-
-SHPT_NULL = shapelibc.SHPT_NULL
-SHPT_POINT = shapelibc.SHPT_POINT
-SHPT_ARC = shapelibc.SHPT_ARC
-SHPT_POLYGON = shapelibc.SHPT_POLYGON
-SHPT_MULTIPOINT = shapelibc.SHPT_MULTIPOINT
-SHPT_POINTZ = shapelibc.SHPT_POINTZ
-SHPT_ARCZ = shapelibc.SHPT_ARCZ
-SHPT_POLYGONZ = shapelibc.SHPT_POLYGONZ
-SHPT_MULTIPOINTZ = shapelibc.SHPT_MULTIPOINTZ
-SHPT_POINTM = shapelibc.SHPT_POINTM
-SHPT_ARCM = shapelibc.SHPT_ARCM
-SHPT_POLYGONM = shapelibc.SHPT_POLYGONM
-SHPT_MULTIPOINTM = shapelibc.SHPT_MULTIPOINTM
-SHPT_MULTIPATCH = shapelibc.SHPT_MULTIPATCH
-SHPP_TRISTRIP = shapelibc.SHPP_TRISTRIP
-SHPP_TRIFAN = shapelibc.SHPP_TRIFAN
-SHPP_OUTERRING = shapelibc.SHPP_OUTERRING
-SHPP_INNERRING = shapelibc.SHPP_INNERRING
-SHPP_FIRSTRING = shapelibc.SHPP_FIRSTRING
-SHPP_RING = shapelibc.SHPP_RING

Deleted: branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/shapelib_wrap.c
===================================================================
--- branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/shapelib_wrap.c	2007-12-12 20:23:04 UTC (rev 2794)
+++ branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/shapelib_wrap.c	2007-12-12 20:35:20 UTC (rev 2795)
@@ -1,1411 +0,0 @@
-/* ----------------------------------------------------------------------------
- * This file was automatically generated by SWIG (http://www.swig.org).
- * Version 1.3u-20050630-1524 (Alpha 5)
- * 
- * This file is not intended to be easily readable and contains a number of 
- * coding conventions designed to improve portability and efficiency. Do not make
- * changes to this file unless you know what you are doing--modify the SWIG 
- * interface file instead. 
- * ----------------------------------------------------------------------------- */
-
-#define SWIGPYTHON
-/***********************************************************************
- * common.swg
- *
- *     This file contains generic SWIG runtime support for pointer
- *     type checking as well as a few commonly used macros to control
- *     external linkage.
- *
- * Author : David Beazley (beazley at cs.uchicago.edu)
- *
- * Copyright (c) 1999-2000, The University of Chicago
- * 
- * This file may be freely redistributed without license or fee provided
- * this copyright message remains intact.
- ************************************************************************/
-
-#include <string.h>
-
-#if defined(_WIN32) || defined(__WIN32__)
-#       if defined(_MSC_VER)
-#               if defined(STATIC_LINKED)
-#                       define SWIGEXPORT(a) a
-#               else
-#                       define SWIGEXPORT(a) __declspec(dllexport) a
-#               endif
-#       else
-#               if defined(__BORLANDC__)
-#                       define SWIGEXPORT(a) a _export
-#               else
-#                       define SWIGEXPORT(a) a
-#       endif
-#endif
-#else
-#       define SWIGEXPORT(a) a
-#endif
-
-#ifdef SWIG_GLOBAL
-#define SWIGRUNTIME(a) SWIGEXPORT(a)
-#else
-#define SWIGRUNTIME(a) static a
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct swig_type_info {
-  char  *name;                 
-  void *(*converter)(void *);
-  char  *str;
-  struct swig_type_info  *next;
-  struct swig_type_info  *prev;
-} swig_type_info;
-
-#ifdef SWIG_NOINCLUDE
-SWIGEXPORT(swig_type_info *) SWIG_TypeRegister(swig_type_info *);
-SWIGEXPORT(swig_type_info *) SWIG_TypeCheck(char *c, swig_type_info *);
-SWIGEXPORT(void *) SWIG_TypeCast(swig_type_info *, void *);
-#else
-
-static swig_type_info *swig_type_list = 0;
-
-/* Register a type mapping with the type-checking */
-SWIGRUNTIME(swig_type_info *)
-SWIG_TypeRegister(swig_type_info *ti)
-{
-  swig_type_info *tc, *head, *ret, *next;
-  /* Check to see if this type has already been registered */
-  tc = swig_type_list;
-  while (tc) {
-    if (strcmp(tc->name, ti->name) == 0) {
-      /* Already exists in the table.  Just add additional types to the list */
-      head = tc;
-      next = tc->next;
-      goto l1;
-    }
-    tc = tc->prev;
-  }
-  head = ti;
-  next = 0;
-
-  /* Place in list */
-  ti->prev = swig_type_list;
-  swig_type_list = ti;
-
-  /* Build linked lists */
- l1:
-  ret = head;
-  tc = ti + 1;
-  /* Patch up the rest of the links */
-  while (tc->name) {
-    head->next = tc;
-    tc->prev = head;
-    head = tc;
-    tc++;
-  }
-  head->next = next;
-  return ret;
-}
-
-/* Check the typename */
-SWIGRUNTIME(swig_type_info *) 
-SWIG_TypeCheck(char *c, swig_type_info *ty)
-{
-  swig_type_info *s;
-  if (!ty) return 0;        /* Void pointer */
-  s = ty->next;             /* First element always just a name */
-  while (s) {
-    if (strcmp(s->name,c) == 0) {
-      if (s == ty->next) return s;
-      /* Move s to the top of the linked list */
-      s->prev->next = s->next;
-      if (s->next) {
-	s->next->prev = s->prev;
-      }
-      /* Insert s as second element in the list */
-      s->next = ty->next;
-      if (ty->next) ty->next->prev = s;
-      ty->next = s;
-      return s;
-    }
-    s = s->next;
-  }
-  return 0;
-}
-
-/* Cast a pointer (needed for C++ inheritance */
-SWIGRUNTIME(void *) 
-SWIG_TypeCast(swig_type_info *ty, void *ptr) 
-{
-  if ((!ty) || (!ty->converter)) return ptr;
-  return (*ty->converter)(ptr);
-}
-
-/* Search for a swig_type_info structure */
-SWIGRUNTIME(void *)
-SWIG_TypeQuery(const char *name) {
-  swig_type_info *ty = swig_type_list;
-  while (ty) {
-    if (ty->str && (strcmp(name,ty->str) == 0)) return ty;
-    if (ty->name && (strcmp(name,ty->name) == 0)) return ty;
-    ty = ty->prev;
-  }
-  return 0;
-}
-
-#endif
-
-#ifdef __cplusplus
-}
-#endif
-
-
-
-/***********************************************************************
- * python.swg
- *
- *     This file contains the runtime support for Python modules
- *     and includes code for managing global variables and pointer
- *     type checking.
- *
- * Author : David Beazley (beazley at cs.uchicago.edu)
- ************************************************************************/
-
-#include <stdlib.h>
-#include "Python.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define SWIG_PY_INT     1
-#define SWIG_PY_FLOAT   2
-#define SWIG_PY_STRING  3
-#define SWIG_PY_POINTER 4
-
-/* Constant information structure */
-typedef struct swig_const_info {
-    int type;
-    char *name;
-    long lvalue;
-    double dvalue;
-    void   *pvalue;
-    swig_type_info **ptype;
-} swig_const_info;
-
-#ifdef SWIG_NOINCLUDE
-
-SWIGEXPORT(PyObject *)        SWIG_newvarlink();
-SWIGEXPORT(void)              SWIG_addvarlink(PyObject *, char *, PyObject *(*)(void), int (*)(PyObject *));
-SWIGEXPORT(int)               SWIG_ConvertPtr(PyObject *, void **, swig_type_info *, int);
-SWIGEXPORT(void)              SWIG_MakePtr(char *c, void *, swig_type_info *);
-SWIGEXPORT(PyObject *)        SWIG_NewPointerObj(void *, swig_type_info *);
-SWIGEXPORT(void)              SWIG_InstallConstants(PyObject *d, swig_const_info constants[]);
-
-#else
-
-/* -----------------------------------------------------------------------------
- * global variable support code.
- * ----------------------------------------------------------------------------- */
-
-typedef struct swig_globalvar {   
-  char       *name;                  /* Name of global variable */
-  PyObject *(*get_attr)(void);       /* Return the current value */
-  int       (*set_attr)(PyObject *); /* Set the value */
-  struct swig_globalvar *next;
-} swig_globalvar;
-
-typedef struct swig_varlinkobject {
-  PyObject_HEAD
-  swig_globalvar *vars;
-} swig_varlinkobject;
-
-static PyObject *
-swig_varlink_repr(swig_varlinkobject *v) {
-  v = v;
-  return PyString_FromString("<Global variables>");
-}
-
-static int
-swig_varlink_print(swig_varlinkobject *v, FILE *fp, int flags) {
-  swig_globalvar  *var;
-  flags = flags;
-  fprintf(fp,"Global variables { ");
-  for (var = v->vars; var; var=var->next) {
-    fprintf(fp,"%s", var->name);
-    if (var->next) fprintf(fp,", ");
-  }
-  fprintf(fp," }\n");
-  return 0;
-}
-
-static PyObject *
-swig_varlink_getattr(swig_varlinkobject *v, char *n) {
-  swig_globalvar *var = v->vars;
-  while (var) {
-    if (strcmp(var->name,n) == 0) {
-      return (*var->get_attr)();
-    }
-    var = var->next;
-  }
-  PyErr_SetString(PyExc_NameError,"Unknown C global variable");
-  return NULL;
-}
-
-static int
-swig_varlink_setattr(swig_varlinkobject *v, char *n, PyObject *p) {
-  swig_globalvar *var = v->vars;
-  while (var) {
-    if (strcmp(var->name,n) == 0) {
-      return (*var->set_attr)(p);
-    }
-    var = var->next;
-  }
-  PyErr_SetString(PyExc_NameError,"Unknown C global variable");
-  return 1;
-}
-
-statichere PyTypeObject varlinktype = {
-  PyObject_HEAD_INIT(0)              
-  0,
-  "swigvarlink",                      /* Type name    */
-  sizeof(swig_varlinkobject),         /* Basic size   */
-  0,                                  /* Itemsize     */
-  0,                                  /* Deallocator  */ 
-  (printfunc) swig_varlink_print,     /* Print        */
-  (getattrfunc) swig_varlink_getattr, /* get attr     */
-  (setattrfunc) swig_varlink_setattr, /* Set attr     */
-  0,                                  /* tp_compare   */
-  (reprfunc) swig_varlink_repr,       /* tp_repr      */    
-  0,                                  /* tp_as_number */
-  0,                                  /* tp_as_mapping*/
-  0,                                  /* tp_hash      */
-};
-
-/* Create a variable linking object for use later */
-SWIGRUNTIME(PyObject *)
-SWIG_newvarlink(void) {
-  swig_varlinkobject *result = 0;
-  result = PyMem_NEW(swig_varlinkobject,1);
-  varlinktype.ob_type = &PyType_Type;    /* Patch varlinktype into a PyType */
-  result->ob_type = &varlinktype;
-  result->vars = 0;
-  result->ob_refcnt = 0;
-  Py_XINCREF((PyObject *) result);
-  return ((PyObject*) result);
-}
-
-SWIGRUNTIME(void)
-SWIG_addvarlink(PyObject *p, char *name,
-	   PyObject *(*get_attr)(void), int (*set_attr)(PyObject *p)) {
-  swig_varlinkobject *v;
-  swig_globalvar *gv;
-  v= (swig_varlinkobject *) p;
-  gv = (swig_globalvar *) malloc(sizeof(swig_globalvar));
-  gv->name = (char *) malloc(strlen(name)+1);
-  strcpy(gv->name,name);
-  gv->get_attr = get_attr;
-  gv->set_attr = set_attr;
-  gv->next = v->vars;
-  v->vars = gv;
-}
-/* Convert a pointer value */
-SWIGRUNTIME(int)
-SWIG_ConvertPtr(PyObject *obj, void **ptr, swig_type_info *ty, int flags) {
-  unsigned long p;
-  register int d;
-  swig_type_info *tc;
-  char  *c;
-  static PyObject *SWIG_this = 0;
-  int    newref = 0;
-
-  if (!obj || (obj == Py_None)) {
-    *ptr = 0;
-    return 0;
-  }
-#ifdef SWIG_COBJECT_TYPES
-  if (!(PyCObject_Check(obj))) {
-    if (!SWIG_this)
-      SWIG_this = PyString_InternFromString("this");
-    obj = PyObject_GetAttr(obj,SWIG_this);
-    newref = 1;
-    if (!obj) goto type_error;
-    if (!PyCObject_Check(obj)) {
-      Py_DECREF(obj);
-      goto type_error;
-    }
-  } 
-  *ptr = PyCObject_AsVoidPtr(obj);
-  c = (char *) PyCObject_GetDesc(obj);
-  if (newref) Py_DECREF(obj);
-  goto cobject;
-#else
-  if (!(PyString_Check(obj))) {
-    if (!SWIG_this)
-      SWIG_this = PyString_InternFromString("this");
-    obj = PyObject_GetAttr(obj,SWIG_this);
-    newref = 1;
-    if (!obj) goto type_error;
-    if (!PyString_Check(obj)) {
-      Py_DECREF(obj);
-      goto type_error;
-    }
-  } 
-  c = PyString_AsString(obj);
-  p = 0;
-  /* Pointer values must start with leading underscore */
-  if (*c != '_') {
-    *ptr = (void *) 0;
-    if (strcmp(c,"NULL") == 0) {
-      if (newref) Py_DECREF(obj);
-      return 0;
-    } else {
-      if (newref) Py_DECREF(obj);
-      goto type_error;
-    }
-  }
-  c++;
-  /* Extract hex value from pointer */
-  while ((d = *c)) {
-    if ((d >= '0') && (d <= '9'))
-      p = (p << 4) + (d - '0');
-    else if ((d >= 'a') && (d <= 'f'))
-      p = (p << 4) + (d - ('a'-10));
-    else
-      break; 
-    c++;
-  }
-  *ptr = (void *) p;
-  if (newref) Py_DECREF(obj);
-#endif
-
-#ifdef SWIG_COBJECT_TYPES
-cobject:
-#endif
-
-  if (ty) {
-    tc = SWIG_TypeCheck(c,ty);
-    if (!tc) goto type_error;
-    *ptr = SWIG_TypeCast(tc,(void*)p);
-  }
-  return 0;
-
-type_error:
-
-  if (flags) {
-    if (ty) {
-      char *temp = (char *) malloc(64+strlen(ty->name));
-      sprintf(temp,"Type error. Expected %s", ty->name);
-      PyErr_SetString(PyExc_TypeError, temp);
-      free((char *) temp);
-    } else {
-      PyErr_SetString(PyExc_TypeError,"Expected a pointer");
-    }
-  }
-  return -1;
-}
-
-/* Take a pointer and convert it to a string */
-SWIGRUNTIME(void) 
-SWIG_MakePtr(char *c, void *ptr, swig_type_info *ty) {
-  static char hex[17] = "0123456789abcdef";
-  unsigned long p, s;
-  char result[32], *r; 
-  r = result;
-  p = (unsigned long) ptr;
-  if (p > 0) {
-    while (p > 0) {
-      s = p & 0xf;
-      *(r++) = hex[s];
-      p = p >> 4;
-    }
-    *r = '_';
-    while (r >= result)
-      *(c++) = *(r--);
-    strcpy (c, ty->name);
-  } else {
-    strcpy (c, "NULL");
-  }
-}
-
-/* Create a new pointer object */
-SWIGRUNTIME(PyObject *)
-SWIG_NewPointerObj(void *ptr, swig_type_info *type) {
-  char result[512];
-  PyObject *robj;
-  if (!ptr) {
-    Py_INCREF(Py_None);
-    return Py_None;
-  }
-#ifdef SWIG_COBJECT_TYPES
-  robj = PyCObject_FromVoidPtrAndDesc((void *) ptr, type->name, NULL);
-#else
-  SWIG_MakePtr(result,ptr,type);
-  robj = PyString_FromString(result);
-#endif
-  return robj;
-}
-
-/* Install Constants */
-SWIGRUNTIME(void)
-SWIG_InstallConstants(PyObject *d, swig_const_info constants[]) {
-  int i;
-  PyObject *obj;
-  for (i = 0; constants[i].type; i++) {
-    switch(constants[i].type) {
-    case SWIG_PY_INT:
-      obj = PyInt_FromLong(constants[i].lvalue);
-      break;
-    case SWIG_PY_FLOAT:
-      obj = PyFloat_FromDouble(constants[i].dvalue);
-      break;
-    case SWIG_PY_STRING:
-      obj = PyString_FromString((char *) constants[i].pvalue);
-      break;
-    case SWIG_PY_POINTER:
-      obj = SWIG_NewPointerObj(constants[i].pvalue, *(constants[i]).ptype);
-      break;
-    default:
-      obj = 0;
-      break;
-    }
-    if (obj) {
-      PyDict_SetItemString(d,constants[i].name,obj);
-      Py_DECREF(obj);
-    }
-  }
-}
-
-#endif
-
-#ifdef __cplusplus
-}
-#endif
-
-
-
-/* -------- TYPES TABLE (BEGIN) -------- */
-
-#define  SWIGTYPE_p_ShapeFile swig_types[0] 
-#define  SWIGTYPE_p_SHPObject swig_types[1] 
-static swig_type_info *swig_types[3];
-
-/* -------- TYPES TABLE (END) -------- */
-
-
-/*-----------------------------------------------
-              @(target):= shapelibc.so
-  ------------------------------------------------*/
-#define SWIG_init    initshapelibc
-
-#define SWIG_name    "shapelibc"
-
-
-/* import the shapelib headefile. */
-#include "shapefil.h"
-#include "pyshapelib_api.h"
-    
-/*
- * Rename a few shapelib functions that are effectively methods with
- * preprocessor macros so that they have the names that swig expects
- * (e.g. the destructor of SHPObject has to be called delete_SHPObject)
- */
-
-#define delete_SHPObject SHPDestroyObject
-    
-/*
- * The extents() method of SHPObject.
- *
- * Return the extents as a tuple of two 4-element lists with the min.
- * and max. values of x, y, z, m.
- */
-static PyObject *
-SHPObject_extents(SHPObject *object)
-{
-    return Py_BuildValue("[dddd][dddd]",
-			 object->dfXMin, object->dfYMin, object->dfZMin,
-			 object->dfMMin, 
-			 object->dfXMax, object->dfYMax, object->dfZMax,
-			 object->dfMMax);
-}
-
-
-/*
- * The vertices() method of SHPObject.
- *
- * Return the x and y coords of the vertices as a list of lists of
- * tuples.
- */
-
-static PyObject* build_vertex_list(SHPObject *object, int index, int length);
-
-static PyObject*
-SHPObject_vertices(SHPObject *object)
-{
-    PyObject *result = NULL;
-    PyObject *part = NULL;
-    int part_idx, vertex_idx;
-    int length = 0;
-
-
-    if (object->nParts > 0)
-    {
-	/* A multipart shape. Usual for SHPT_ARC and SHPT_POLYGON */
-	
-	result = PyList_New(object->nParts);
-	if (!result)
-	    return NULL;
-
-	for (part_idx = 0, vertex_idx = 0; part_idx < object->nParts;
-	     part_idx++)
-	{
-	    if (part_idx < object->nParts - 1)
-		length = (object->panPartStart[part_idx + 1]
-			  - object->panPartStart[part_idx]);
-	    else
-		length = object->nVertices - object->panPartStart[part_idx];
-	    
-	    part = build_vertex_list(object, vertex_idx, length);
-	    if (!part)
-		goto fail;
-
-	    if (PyList_SetItem(result, part_idx, part) < 0)
-		goto fail;
-
-	    vertex_idx += length;
-	}
-    }
-    else
-    {
-	/* only one part. usual for SHPT_POINT */
-	result = build_vertex_list(object, 0, object->nVertices);
-    }
-
-    return result;
-
- fail:
-    Py_XDECREF(part);
-    Py_DECREF(result);
-    return NULL;
-}
-
-
-/* Return the length coordinates of the shape object starting at vertex
- * index as a Python-list of tuples. Helper function for
- * SHPObject_vertices.
- */
-static PyObject*
-build_vertex_list(SHPObject *object, int index, int length)
-{
-    int i;
-    PyObject * list;
-    PyObject * vertex = NULL;
-
-    list = PyList_New(length);
-    if (!list)
-	return NULL;
-
-    for (i = 0; i < length; i++, index++)
-    {
-	vertex = Py_BuildValue("dd", object->padfX[index],
-			       object->padfY[index]);
-	if (!vertex)
-	    goto fail;
-	if (PyList_SetItem(list, i, vertex) < 0)
-	    goto fail;
-    }
-
-    return list;
-
- fail:
-    Py_XDECREF(vertex);
-    Py_DECREF(list);
-    return NULL;
-}
-
-
-
-
-
-/* The constructor of SHPObject. parts is a list of lists of tuples
- * describing the parts and their vertices just likethe output of the
- * vertices() method. part_type_list is the list of part-types and may
- * be NULL. For the meaning of the part-types and their default value
- * see the Shaplib documentation.
- */
-SHPObject * new_SHPObject(int type, int id, PyObject * parts,
-			  PyObject * part_type_list)
-{
-    /* arrays to hold thex and y coordinates of the  vertices */
-    double *xs = NULL, *ys = NULL;
-    /* number of all vertices of all parts */
-    int num_vertices;
-    /* number of parts in the list parts */
-    int num_parts;
-    /* start index of in xs and ys of the part currently worked on */
-    int part_start;
-    /* array of start indices in xs and ys as expected by shapelib */
-    int *part_starts = NULL;
-
-    /* generic counter */
-    int i;
-
-    /* array of part types. holds the converted content of
-     * part_type_list. Stays NULL of part_type_list is NULL
-     */
-    int *part_types = NULL;
-
-    /* temporary python objects referring to the the list items being
-     * worked on.
-     */
-    PyObject * part = NULL, *tuple = NULL;
-
-    /* The result object */
-    SHPObject *result;
-
-    num_parts = PySequence_Length(parts);
-    num_vertices = 0; 
-
-    /* parts and part_types have to have the same lengths */
-    if (part_type_list
-	&& PySequence_Length(parts) != PySequence_Length(part_type_list))
-    {
-	PyErr_SetString(PyExc_TypeError,
-			"parts and part_types have to have the same lengths");
-	return NULL;
-    }
-
-    /* determine how many vertices there are altogether */
-    for (i = 0; i < num_parts; i++)
-    {
-	PyObject * part = PySequence_GetItem(parts, i);
-	if (!part)
-	    return NULL;
-	num_vertices += PySequence_Length(part);
-	Py_DECREF(part);
-    }
-
-    /* allocate the memory for the various arrays and check for memory
-       errors */
-    xs = malloc(num_vertices * sizeof(double));
-    ys = malloc(num_vertices * sizeof(double));
-    part_starts = malloc(num_parts * sizeof(int));
-    if (part_type_list)
-	part_types = malloc(num_parts * sizeof(int));
-
-    if (!xs || !ys || !part_starts || (part_type_list && !part_types))
-    {
-	PyErr_NoMemory();
-	goto fail;
-    }
-
-    /* convert the part types */
-    if (part_type_list)
-    {
-	for (i = 0; i < num_parts; i++)
-	{
-	    PyObject * otype = PySequence_GetItem(part_type_list, i);
-	    if (!otype)
-		return NULL;
-	    part_types[i] = PyInt_AsLong(otype);
-	    Py_DECREF(otype);
-	}
-    }
-
-    /* convert the list of parts */
-    part_start = 0;
-    for (i = 0; i < num_parts; i++)
-    {
-	int j, length;
-
-	part = PySequence_GetItem(parts, i);
-	length = PySequence_Length(part);
-	part_starts[i] = part_start;
-
-	for (j = 0; j < length; j++)
-	{
-	    tuple = PySequence_GetItem(part, j);
-	    if (!tuple)
-		goto fail;
-
-	    if (!PyArg_ParseTuple(tuple, "dd", xs + part_start + j,
-				  ys + part_start + j))
-	    {
-		goto fail;
-	    }
-	    Py_DECREF(tuple);
-	    tuple = NULL;
-	}
-	Py_DECREF(part);
-	part = NULL;
-	part_start += length;
-    }
-
-    result = SHPCreateObject(type, id, num_parts, part_starts, part_types,
-			     num_vertices, xs, ys, NULL, NULL);
-    free(xs);
-    free(ys);
-    free(part_starts);
-    free(part_types);
-    return result;
-
- fail:
-    free(xs);
-    free(ys);
-    free(part_starts);
-    free(part_types);
-    Py_XDECREF(part);
-    Py_XDECREF(tuple);
-    return NULL;
-}
-
-
-static PyObject* l_output_helper(PyObject* target, PyObject* o) {
-    PyObject*   o2;
-    if (!target) {                   
-        target = o;
-    } else if (target == Py_None) {  
-        Py_DECREF(Py_None);
-        target = o;
-    } else {                         
-        if (!PyList_Check(target)) {
-            o2 = target;
-            target = PyList_New(0);
-            PyList_Append(target, o2);
-	    Py_XDECREF(o2);
-        }
-        PyList_Append(target,o);
-	Py_XDECREF(o);
-    }
-    return target;
-}
-
-static PyObject* t_output_helper(PyObject* target, PyObject* o) {
-    PyObject*   o2;
-    PyObject*   o3;
-
-    if (!target) {                   
-        target = o;
-    } else if (target == Py_None) {  
-        Py_DECREF(Py_None);
-        target = o;
-    } else {                         
-        if (!PyTuple_Check(target)) {
-            o2 = target;
-            target = PyTuple_New(1);
-            PyTuple_SetItem(target, 0, o2);
-        }
-        o3 = PyTuple_New(1);            
-        PyTuple_SetItem(o3, 0, o);      
-
-        o2 = target;
-        target = PySequence_Concat(o2, o3); 
-        Py_DECREF(o2);                      
-        Py_DECREF(o3);
-    }
-    return target;
-}
-
-#define  SWIG_MemoryError    1
-#define  SWIG_IOError        2
-#define  SWIG_RuntimeError   3
-#define  SWIG_IndexError     4
-#define  SWIG_TypeError      5
-#define  SWIG_DivisionByZero 6
-#define  SWIG_OverflowError  7
-#define  SWIG_SyntaxError    8
-#define  SWIG_ValueError     9
-#define  SWIG_SystemError   10
-#define  SWIG_UnknownError  99
-
-static void _SWIG_exception(int code, char *msg) {
-  switch(code) {
-  case SWIG_MemoryError:
-    PyErr_SetString(PyExc_MemoryError,msg);
-    break;
-  case SWIG_IOError:
-    PyErr_SetString(PyExc_IOError,msg);
-    break;
-  case SWIG_RuntimeError:
-    PyErr_SetString(PyExc_RuntimeError,msg);
-    break;
-  case SWIG_IndexError:
-    PyErr_SetString(PyExc_IndexError,msg);
-    break;
-  case SWIG_TypeError:
-    PyErr_SetString(PyExc_TypeError,msg);
-    break;
-  case SWIG_DivisionByZero:
-    PyErr_SetString(PyExc_ZeroDivisionError,msg);
-    break;
-  case SWIG_OverflowError:
-    PyErr_SetString(PyExc_OverflowError,msg);
-    break;
-  case SWIG_SyntaxError:
-    PyErr_SetString(PyExc_SyntaxError,msg);
-    break;
-  case SWIG_ValueError:
-    PyErr_SetString(PyExc_ValueError,msg);
-    break;
-  case SWIG_SystemError:
-    PyErr_SetString(PyExc_SystemError,msg);
-    break;
-  default:
-    PyErr_SetString(PyExc_RuntimeError,msg);
-    break;
-  }
-}
-
-#define SWIG_exception(a,b) { _SWIG_exception(a,b); return NULL; }
-
-    typedef struct {
-	SHPHandle handle;
-    } ShapeFile;
-
-#define NOCHECK_delete_ShapeFile
-#define NOCHECK_ShapeFile_close
-
-    ShapeFile * open_ShapeFile(const char *filename, const char * mode) {
-	ShapeFile * self = malloc(sizeof(ShapeFile));
-	if (self)
-	    self->handle = SHPOpen(filename, mode);
-	return self;
-    }
-
-    ShapeFile * create_ShapeFile(const char *filename, int type) {
-	ShapeFile * self = malloc(sizeof(ShapeFile));
-	if (self)
-	    self->handle = SHPCreate(filename, type);
-	return self;
-    }
-
-    static PyShapeLibAPI the_api = {
-	SHPReadObject,
-	SHPDestroyObject,
-	SHPCreateTree,
-	SHPDestroyTree,
-	SHPTreeFindLikelyShapes
-    };
-
-    PyObject * c_api() {
-	return PyCObject_FromVoidPtr(&the_api, NULL);
-    }
-#ifdef __cplusplus
-extern "C" {
-#endif
-static PyObject *_wrap_open(PyObject *self, PyObject *args) {
-    PyObject *resultobj;
-    char *arg0 ;
-    char *arg1 = "rb" ;
-    ShapeFile *result ;
-    
-    if(!PyArg_ParseTuple(args,"s|s:open",&arg0,&arg1)) return NULL;
-    {
-        result = (ShapeFile *)open_ShapeFile((char const *)arg0,(char const *)arg1);
-        ;
-        if (!result)
-        {
-            SWIG_exception(SWIG_MemoryError, "no memory");
-        }
-        else if (!result->handle)
-        {
-            SWIG_exception(SWIG_IOError, "open_ShapeFile failed");
-        }
-    }resultobj = SWIG_NewPointerObj((void *) result, SWIGTYPE_p_ShapeFile);
-    return resultobj;
-}
-
-
-static PyObject *_wrap_create(PyObject *self, PyObject *args) {
-    PyObject *resultobj;
-    char *arg0 ;
-    int arg1 ;
-    ShapeFile *result ;
-    
-    if(!PyArg_ParseTuple(args,"si:create",&arg0,&arg1)) return NULL;
-    {
-        result = (ShapeFile *)create_ShapeFile((char const *)arg0,arg1);
-        ;
-        if (!result)
-        {
-            SWIG_exception(SWIG_MemoryError, "no memory");
-        }
-        else if (!result->handle)
-        {
-            SWIG_exception(SWIG_IOError, "create_ShapeFile failed");
-        }
-    }resultobj = SWIG_NewPointerObj((void *) result, SWIGTYPE_p_ShapeFile);
-    return resultobj;
-}
-
-
-static PyObject *_wrap_c_api(PyObject *self, PyObject *args) {
-    PyObject *resultobj;
-    PyObject *result ;
-    
-    if(!PyArg_ParseTuple(args,":c_api")) return NULL;
-    result = (PyObject *)c_api();
-    {
-        resultobj = result;
-    }
-    return resultobj;
-}
-
-
-static PyObject *_wrap_type_name(PyObject *self, PyObject *args) {
-    PyObject *resultobj;
-    int arg0 ;
-    char *result ;
-    
-    if(!PyArg_ParseTuple(args,"i:type_name",&arg0)) return NULL;
-    result = (char *)SHPTypeName(arg0);
-    resultobj = PyString_FromString(result);
-    return resultobj;
-}
-
-
-static PyObject *_wrap_part_type_name(PyObject *self, PyObject *args) {
-    PyObject *resultobj;
-    int arg0 ;
-    char *result ;
-    
-    if(!PyArg_ParseTuple(args,"i:part_type_name",&arg0)) return NULL;
-    result = (char *)SHPPartTypeName(arg0);
-    resultobj = PyString_FromString(result);
-    return resultobj;
-}
-
-
-static PyObject *_wrap_SHPObject_type_get(PyObject *self, PyObject *args) {
-    PyObject *resultobj;
-    SHPObject *arg0 ;
-    PyObject * argo0 =0 ;
-    int result ;
-    
-    if(!PyArg_ParseTuple(args,"O:SHPObject_type_get",&argo0)) return NULL;
-    if ((SWIG_ConvertPtr(argo0,(void **) &arg0,SWIGTYPE_p_SHPObject,1)) == -1) return NULL;
-    result = (int ) (arg0->nSHPType);
-    resultobj = PyInt_FromLong((long)result);
-    return resultobj;
-}
-
-
-static PyObject *_wrap_SHPObject_id_get(PyObject *self, PyObject *args) {
-    PyObject *resultobj;
-    SHPObject *arg0 ;
-    PyObject * argo0 =0 ;
-    int result ;
-    
-    if(!PyArg_ParseTuple(args,"O:SHPObject_id_get",&argo0)) return NULL;
-    if ((SWIG_ConvertPtr(argo0,(void **) &arg0,SWIGTYPE_p_SHPObject,1)) == -1) return NULL;
-    result = (int ) (arg0->nShapeId);
-    resultobj = PyInt_FromLong((long)result);
-    return resultobj;
-}
-
-
-static PyObject *_wrap_new_SHPObject(PyObject *self, PyObject *args) {
-    PyObject *resultobj;
-    int arg0 ;
-    int arg1 ;
-    PyObject *arg2 ;
-    PyObject *arg3 = NULL ;
-    PyObject * obj2  = 0 ;
-    PyObject * obj3  = 0 ;
-    SHPObject *result ;
-    
-    if(!PyArg_ParseTuple(args,"iiO|O:new_SHPObject",&arg0,&arg1,&obj2,&obj3)) return NULL;
-    {
-        arg2 = obj2;
-    }
-    if (obj3)
-    {
-        arg3 = obj3;
-    }
-    {
-        result = (SHPObject *)new_SHPObject(arg0,arg1,arg2,arg3);
-        ;
-        if (PyErr_Occurred())
-        return NULL;
-    }resultobj = SWIG_NewPointerObj((void *) result, SWIGTYPE_p_SHPObject);
-    return resultobj;
-}
-
-
-static PyObject *_wrap_delete_SHPObject(PyObject *self, PyObject *args) {
-    PyObject *resultobj;
-    SHPObject *arg0 ;
-    PyObject * argo0 =0 ;
-    
-    if(!PyArg_ParseTuple(args,"O:delete_SHPObject",&argo0)) return NULL;
-    if ((SWIG_ConvertPtr(argo0,(void **) &arg0,SWIGTYPE_p_SHPObject,1)) == -1) return NULL;
-    delete_SHPObject(arg0);
-    Py_INCREF(Py_None);
-    resultobj = Py_None;
-    return resultobj;
-}
-
-
-static PyObject *_wrap_SHPObject_extents(PyObject *self, PyObject *args) {
-    PyObject *resultobj;
-    SHPObject *arg0 ;
-    PyObject * argo0 =0 ;
-    PyObject *result ;
-    
-    if(!PyArg_ParseTuple(args,"O:SHPObject_extents",&argo0)) return NULL;
-    if ((SWIG_ConvertPtr(argo0,(void **) &arg0,SWIGTYPE_p_SHPObject,1)) == -1) return NULL;
-    result = (PyObject *)SHPObject_extents(arg0);
-    {
-        resultobj = result;
-    }
-    return resultobj;
-}
-
-
-static PyObject *_wrap_SHPObject_vertices(PyObject *self, PyObject *args) {
-    PyObject *resultobj;
-    SHPObject *arg0 ;
-    PyObject * argo0 =0 ;
-    PyObject *result ;
-    
-    if(!PyArg_ParseTuple(args,"O:SHPObject_vertices",&argo0)) return NULL;
-    if ((SWIG_ConvertPtr(argo0,(void **) &arg0,SWIGTYPE_p_SHPObject,1)) == -1) return NULL;
-    result = (PyObject *)SHPObject_vertices(arg0);
-    {
-        resultobj = result;
-    }
-    return resultobj;
-}
-
-
-ShapeFile * new_ShapeFile(char *file,char *mode) {
-    {
-        ShapeFile * self = malloc(sizeof(ShapeFile));
-        if (self)
-        self->handle = SHPOpen(file, mode);
-        return self;
-    }
-}
-
-
-static PyObject *_wrap_new_ShapeFile(PyObject *self, PyObject *args) {
-    PyObject *resultobj;
-    char *arg0 ;
-    char *arg1 = "rb" ;
-    ShapeFile *result ;
-    
-    if(!PyArg_ParseTuple(args,"s|s:new_ShapeFile",&arg0,&arg1)) return NULL;
-    {
-        result = (ShapeFile *)new_ShapeFile(arg0,arg1);
-        ;
-        if (!result)
-        {
-            SWIG_exception(SWIG_MemoryError, "no memory");
-        }
-        else if (!result->handle)
-        {
-            SWIG_exception(SWIG_IOError, "new_ShapeFile failed");
-        }
-    }resultobj = SWIG_NewPointerObj((void *) result, SWIGTYPE_p_ShapeFile);
-    return resultobj;
-}
-
-
-void  delete_ShapeFile(ShapeFile *self) {
-    {
-        if (self->handle)
-        SHPClose(self->handle);
-        free(self);
-    }
-}
-
-
-static PyObject *_wrap_delete_ShapeFile(PyObject *self, PyObject *args) {
-    PyObject *resultobj;
-    ShapeFile *arg0 ;
-    PyObject * argo0 =0 ;
-    
-    if(!PyArg_ParseTuple(args,"O:delete_ShapeFile",&argo0)) return NULL;
-    if ((SWIG_ConvertPtr(argo0,(void **) &arg0,SWIGTYPE_p_ShapeFile,1)) == -1) return NULL;
-    {
-        #ifndef NOCHECK_delete_ShapeFile
-        if (!arg0 || !arg0->handle)
-        SWIG_exception(SWIG_TypeError, "shapefile already closed");
-        #endif
-    }
-    delete_ShapeFile(arg0);
-    Py_INCREF(Py_None);
-    resultobj = Py_None;
-    return resultobj;
-}
-
-
-void  ShapeFile_close(ShapeFile *self) {
-    {
-        if (self->handle)
-        {
-            SHPClose(self->handle);
-            self->handle = NULL;
-        }
-    }
-}
-
-
-static PyObject *_wrap_ShapeFile_close(PyObject *self, PyObject *args) {
-    PyObject *resultobj;
-    ShapeFile *arg0 ;
-    PyObject * argo0 =0 ;
-    
-    if(!PyArg_ParseTuple(args,"O:ShapeFile_close",&argo0)) return NULL;
-    if ((SWIG_ConvertPtr(argo0,(void **) &arg0,SWIGTYPE_p_ShapeFile,1)) == -1) return NULL;
-    {
-        #ifndef NOCHECK_ShapeFile_close
-        if (!arg0 || !arg0->handle)
-        SWIG_exception(SWIG_TypeError, "shapefile already closed");
-        #endif
-    }
-    ShapeFile_close(arg0);
-    Py_INCREF(Py_None);
-    resultobj = Py_None;
-    return resultobj;
-}
-
-
-void  ShapeFile_info(ShapeFile *self,int *output_entities,int *output_type,double *output_min_bounds,double *output_max_bounds) {
-    {
-        SHPGetInfo(self->handle, output_entities, output_type,
-        output_min_bounds, output_max_bounds);
-    }
-}
-
-
-static PyObject *_wrap_ShapeFile_info(PyObject *self, PyObject *args) {
-    PyObject *resultobj;
-    ShapeFile *arg0 ;
-    int *arg1 ;
-    int *arg2 ;
-    double *arg3 ;
-    double *arg4 ;
-    int temp ;
-    int temp0 ;
-    double temp1[4] ;
-    double temp2[4] ;
-    PyObject * argo0 =0 ;
-    
-    {
-        arg1 = &temp;
-    }
-    {
-        arg2 = &temp0;
-    }
-    {
-        arg3 = temp1;
-    }
-    {
-        arg4 = temp2;
-    }
-    if(!PyArg_ParseTuple(args,"O:ShapeFile_info",&argo0)) return NULL;
-    if ((SWIG_ConvertPtr(argo0,(void **) &arg0,SWIGTYPE_p_ShapeFile,1)) == -1) return NULL;
-    {
-        #ifndef NOCHECK_ShapeFile_info
-        if (!arg0 || !arg0->handle)
-        SWIG_exception(SWIG_TypeError, "shapefile already closed");
-        #endif
-    }
-    ShapeFile_info(arg0,arg1,arg2,arg3,arg4);
-    Py_INCREF(Py_None);
-    resultobj = Py_None;
-    {
-        PyObject *o;
-        o = PyInt_FromLong((long) (*arg1));
-        resultobj = t_output_helper(resultobj, o);
-    }
-    {
-        PyObject *o;
-        o = PyInt_FromLong((long) (*arg2));
-        resultobj = t_output_helper(resultobj, o);
-    }
-    {
-        PyObject * list = Py_BuildValue("[dddd]",
-        arg3[0], arg3[1],
-        arg3[2], arg3[3]);
-        resultobj = t_output_helper(resultobj,list);
-    }
-    {
-        PyObject * list = Py_BuildValue("[dddd]",
-        arg4[0], arg4[1],
-        arg4[2], arg4[3]);
-        resultobj = t_output_helper(resultobj,list);
-    }
-    return resultobj;
-}
-
-
-SHPObject * ShapeFile_read_object(ShapeFile *self,int i) {
-    {
-        return SHPReadObject(self->handle, i);
-    }
-}
-
-
-static PyObject *_wrap_ShapeFile_read_object(PyObject *self, PyObject *args) {
-    PyObject *resultobj;
-    ShapeFile *arg0 ;
-    int arg1 ;
-    PyObject * argo0 =0 ;
-    SHPObject *result ;
-    
-    if(!PyArg_ParseTuple(args,"Oi:ShapeFile_read_object",&argo0,&arg1)) return NULL;
-    if ((SWIG_ConvertPtr(argo0,(void **) &arg0,SWIGTYPE_p_ShapeFile,1)) == -1) return NULL;
-    {
-        #ifndef NOCHECK_ShapeFile_read_object
-        if (!arg0 || !arg0->handle)
-        SWIG_exception(SWIG_TypeError, "shapefile already closed");
-        #endif
-    }
-    result = (SHPObject *)ShapeFile_read_object(arg0,arg1);
-    resultobj = SWIG_NewPointerObj((void *) result, SWIGTYPE_p_SHPObject);
-    return resultobj;
-}
-
-
-int  ShapeFile_write_object(ShapeFile *self,int iShape,SHPObject *psObject) {
-    {
-        return SHPWriteObject(self->handle, iShape, psObject);
-    }
-}
-
-
-static PyObject *_wrap_ShapeFile_write_object(PyObject *self, PyObject *args) {
-    PyObject *resultobj;
-    ShapeFile *arg0 ;
-    int arg1 ;
-    SHPObject *arg2 ;
-    PyObject * argo0 =0 ;
-    PyObject * argo2 =0 ;
-    int result ;
-    
-    if(!PyArg_ParseTuple(args,"OiO:ShapeFile_write_object",&argo0,&arg1,&argo2)) return NULL;
-    if ((SWIG_ConvertPtr(argo0,(void **) &arg0,SWIGTYPE_p_ShapeFile,1)) == -1) return NULL;
-    if ((SWIG_ConvertPtr(argo2,(void **) &arg2,SWIGTYPE_p_SHPObject,1)) == -1) return NULL;
-    {
-        #ifndef NOCHECK_ShapeFile_write_object
-        if (!arg0 || !arg0->handle)
-        SWIG_exception(SWIG_TypeError, "shapefile already closed");
-        #endif
-    }
-    result = (int )ShapeFile_write_object(arg0,arg1,arg2);
-    resultobj = PyInt_FromLong((long)result);
-    return resultobj;
-}
-
-
-PyObject * ShapeFile_cobject(ShapeFile *self) {
-    {
-        return PyCObject_FromVoidPtr(self->handle, NULL);
-    }
-}
-
-
-static PyObject *_wrap_ShapeFile_cobject(PyObject *self, PyObject *args) {
-    PyObject *resultobj;
-    ShapeFile *arg0 ;
-    PyObject * argo0 =0 ;
-    PyObject *result ;
-    
-    if(!PyArg_ParseTuple(args,"O:ShapeFile_cobject",&argo0)) return NULL;
-    if ((SWIG_ConvertPtr(argo0,(void **) &arg0,SWIGTYPE_p_ShapeFile,1)) == -1) return NULL;
-    {
-        #ifndef NOCHECK_ShapeFile_cobject
-        if (!arg0 || !arg0->handle)
-        SWIG_exception(SWIG_TypeError, "shapefile already closed");
-        #endif
-    }
-    result = (PyObject *)ShapeFile_cobject(arg0);
-    {
-        resultobj = result;
-    }
-    return resultobj;
-}
-
-
-static PyMethodDef shapelibcMethods[] = {
-	 { "open", _wrap_open, METH_VARARGS },
-	 { "create", _wrap_create, METH_VARARGS },
-	 { "c_api", _wrap_c_api, METH_VARARGS },
-	 { "type_name", _wrap_type_name, METH_VARARGS },
-	 { "part_type_name", _wrap_part_type_name, METH_VARARGS },
-	 { "SHPObject_type_get", _wrap_SHPObject_type_get, METH_VARARGS },
-	 { "SHPObject_id_get", _wrap_SHPObject_id_get, METH_VARARGS },
-	 { "new_SHPObject", _wrap_new_SHPObject, METH_VARARGS },
-	 { "delete_SHPObject", _wrap_delete_SHPObject, METH_VARARGS },
-	 { "SHPObject_extents", _wrap_SHPObject_extents, METH_VARARGS },
-	 { "SHPObject_vertices", _wrap_SHPObject_vertices, METH_VARARGS },
-	 { "new_ShapeFile", _wrap_new_ShapeFile, METH_VARARGS },
-	 { "delete_ShapeFile", _wrap_delete_ShapeFile, METH_VARARGS },
-	 { "ShapeFile_close", _wrap_ShapeFile_close, METH_VARARGS },
-	 { "ShapeFile_info", _wrap_ShapeFile_info, METH_VARARGS },
-	 { "ShapeFile_read_object", _wrap_ShapeFile_read_object, METH_VARARGS },
-	 { "ShapeFile_write_object", _wrap_ShapeFile_write_object, METH_VARARGS },
-	 { "ShapeFile_cobject", _wrap_ShapeFile_cobject, METH_VARARGS },
-	 { NULL, NULL }
-};
-
-#ifdef __cplusplus
-}
-#endif
-
-/* -------- TYPE CONVERSION AND EQUIVALENCE RULES (BEGIN) -------- */
-
-static swig_type_info _swigt__p_ShapeFile[] = {{"_p_ShapeFile", 0, "ShapeFile *"},{"_p_ShapeFile"},{0}};
-static swig_type_info _swigt__p_SHPObject[] = {{"_p_SHPObject", 0, "SHPObject *"},{"_p_SHPObject"},{0}};
-
-static swig_type_info *swig_types_initial[] = {
-_swigt__p_ShapeFile, 
-_swigt__p_SHPObject, 
-0
-};
-
-
-/* -------- TYPE CONVERSION AND EQUIVALENCE RULES (END) -------- */
-
-static swig_const_info swig_const_table[] = {
-    { SWIG_PY_INT,     "SHPT_NULL", (long) 0, 0, 0, 0},
-    { SWIG_PY_INT,     "SHPT_POINT", (long) 1, 0, 0, 0},
-    { SWIG_PY_INT,     "SHPT_ARC", (long) 3, 0, 0, 0},
-    { SWIG_PY_INT,     "SHPT_POLYGON", (long) 5, 0, 0, 0},
-    { SWIG_PY_INT,     "SHPT_MULTIPOINT", (long) 8, 0, 0, 0},
-    { SWIG_PY_INT,     "SHPT_POINTZ", (long) 11, 0, 0, 0},
-    { SWIG_PY_INT,     "SHPT_ARCZ", (long) 13, 0, 0, 0},
-    { SWIG_PY_INT,     "SHPT_POLYGONZ", (long) 15, 0, 0, 0},
-    { SWIG_PY_INT,     "SHPT_MULTIPOINTZ", (long) 18, 0, 0, 0},
-    { SWIG_PY_INT,     "SHPT_POINTM", (long) 21, 0, 0, 0},
-    { SWIG_PY_INT,     "SHPT_ARCM", (long) 23, 0, 0, 0},
-    { SWIG_PY_INT,     "SHPT_POLYGONM", (long) 25, 0, 0, 0},
-    { SWIG_PY_INT,     "SHPT_MULTIPOINTM", (long) 28, 0, 0, 0},
-    { SWIG_PY_INT,     "SHPT_MULTIPATCH", (long) 31, 0, 0, 0},
-    { SWIG_PY_INT,     "SHPP_TRISTRIP", (long) 0, 0, 0, 0},
-    { SWIG_PY_INT,     "SHPP_TRIFAN", (long) 1, 0, 0, 0},
-    { SWIG_PY_INT,     "SHPP_OUTERRING", (long) 2, 0, 0, 0},
-    { SWIG_PY_INT,     "SHPP_INNERRING", (long) 3, 0, 0, 0},
-    { SWIG_PY_INT,     "SHPP_FIRSTRING", (long) 4, 0, 0, 0},
-    { SWIG_PY_INT,     "SHPP_RING", (long) 5, 0, 0, 0},
-{0}};
-
-static PyObject *SWIG_globals;
-#ifdef __cplusplus
-extern "C" 
-#endif
-SWIGEXPORT(void) initshapelibc(void) {
-    PyObject *m, *d;
-    int i;
-    SWIG_globals = SWIG_newvarlink();
-    m = Py_InitModule("shapelibc", shapelibcMethods);
-    d = PyModule_GetDict(m);
-    for (i = 0; swig_types_initial[i]; i++) {
-        swig_types[i] = SWIG_TypeRegister(swig_types_initial[i]);
-    }
-    SWIG_InstallConstants(d,swig_const_table);
-}
-

Copied: branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/shapelibmodule.c (from rev 2755, branches/WIP-pyshapelib-bramz/libraries/pyshapelib/shapelibmodule.c)

Modified: branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/shptreemodule.c
===================================================================
--- branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/shptreemodule.c	2007-12-12 20:23:04 UTC (rev 2794)
+++ branches/WIP-pyshapelib-Unicode/thuban/libraries/pyshapelib/shptreemodule.c	2007-12-12 20:35:20 UTC (rev 2795)
@@ -166,8 +166,7 @@
 };
 
 
-void
-initshptree()
+PyMODINIT_FUNC initshptree(void)
 {
     SHPTreeType.ob_type = &PyType_Type;
 

Modified: branches/WIP-pyshapelib-Unicode/thuban/libraries/shapelib/dbfopen.c
===================================================================
--- branches/WIP-pyshapelib-Unicode/thuban/libraries/shapelib/dbfopen.c	2007-12-12 20:23:04 UTC (rev 2794)
+++ branches/WIP-pyshapelib-Unicode/thuban/libraries/shapelib/dbfopen.c	2007-12-12 20:35:20 UTC (rev 2795)
@@ -251,6 +251,10 @@
 #  define TRUE		1
 #endif
 
+#if defined(_WIN32) || defined(_WIN64)
+#	define MS_WINDOWS
+#endif
+
 static int	nStringFieldLen = 0;
 static char * pszStringField = NULL;
 
@@ -335,6 +339,8 @@
     abyHeader[10] = (unsigned char) (psDBF->nRecordLength % 256);
     abyHeader[11] = (unsigned char) (psDBF->nRecordLength / 256);
 
+	abyHeader[29] = (unsigned char) (psDBF->nLanguageDriver);
+
 /* -------------------------------------------------------------------- */
 /*      Write the initial 32 byte file header, and all the field        */
 /*      descriptions.                                     		*/
@@ -417,9 +423,8 @@
 DBFOpen( const char * pszFilename, const char * pszAccess )
 
 {
-    DBFHandle		psDBF;
-    unsigned char		*pabyBuf;
-    int			nFields, nHeadLen, nRecLen, iField, i;
+	FILE*		fp;
+    int			i;
     char		*pszBasename, *pszFullname;
 
 /* -------------------------------------------------------------------- */
@@ -453,24 +458,109 @@
     pszFullname = (char *) malloc(strlen(pszBasename) + 5);
     sprintf( pszFullname, "%s.dbf", pszBasename );
         
-    psDBF = (DBFHandle) calloc( 1, sizeof(DBFInfo) );
-    psDBF->fp = fopen( pszFullname, pszAccess );
+    fp = fopen( pszFullname, pszAccess );
 
-    if( psDBF->fp == NULL )
+    if( fp == NULL )
     {
         sprintf( pszFullname, "%s.DBF", pszBasename );
-        psDBF->fp = fopen(pszFullname, pszAccess );
+        fp = fopen(pszFullname, pszAccess );
     }
     
     free( pszBasename );
     free( pszFullname );
-    
-    if( psDBF->fp == NULL )
+
+	return DBFOpenEx( fp );
+}
+
+
+
+/************************************************************************/
+/*                              DBFOpenW()                              */
+/*                                                                      */
+/*      Open a .dbf file with a wide character filename                 */
+/************************************************************************/
+
+#ifdef SHPAPI_HAS_WIDE
+
+DBFHandle SHPAPI_CALL
+DBFOpenW( const wchar_t * pszFilename, const wchar_t * pszAccess )
+
+{
+    FILE*		fp;
+    int			i;
+    wchar_t		*pszBasename, *pszFullname;
+
+/* -------------------------------------------------------------------- */
+/*      We only allow the access strings "rb" and "r+".                  */
+/* -------------------------------------------------------------------- */
+    if( wcscmp(pszAccess,L"r") != 0 && wcscmp(pszAccess,L"r+") != 0 
+        && wcscmp(pszAccess,L"rb") != 0 && wcscmp(pszAccess,L"rb+") != 0
+        && wcscmp(pszAccess,L"r+b") != 0 )
+        return( NULL );
+
+    if( wcscmp(pszAccess,L"r") == 0 )
+        pszAccess = L"rb";
+ 
+    if( wcscmp(pszAccess,L"r+") == 0 )
+        pszAccess = L"rb+";
+
+/* -------------------------------------------------------------------- */
+/*	Compute the base (layer) name.  If there is any extension	*/
+/*	on the passed in filename we will strip it off.			*/
+/* -------------------------------------------------------------------- */
+    pszBasename = (wchar_t *) malloc(sizeof(wchar_t)*(wcslen(pszFilename)+5));
+    wcscpy( pszBasename, pszFilename );
+    for( i = wcslen(pszBasename)-1; 
+	 i > 0 && pszBasename[i] != L'.' && pszBasename[i] != L'/'
+	       && pszBasename[i] != L'\\';
+	 i-- ) {}
+
+    if( pszBasename[i] == L'.' )
+        pszBasename[i] = L'\0';
+
+    pszFullname = (wchar_t *) malloc(sizeof(wchar_t)*(wcslen(pszBasename) + 5));
+    swprintf( pszFullname, L"%s.dbf", pszBasename );
+        
+    fp = _wfopen( pszFullname, pszAccess );
+
+    if( fp == NULL )
     {
-        free( psDBF );
-        return( NULL );
+        swprintf( pszFullname, L"%s.DBF", pszBasename );
+        fp = _wfopen(pszFullname, pszAccess );
     }
+    
+    free( pszBasename );
+    free( pszFullname );
 
+	return DBFOpenEx( fp );
+}
+
+#endif
+
+
+
+/************************************************************************/
+/*                              DBFOpenEx()                             */
+/*                                                                      */
+/*      Open a .dbf file from a freshly opened FILE                     */
+/************************************************************************/
+   
+DBFHandle SHPAPI_CALL
+DBFOpenEx( FILE* fp )
+
+{
+    unsigned char	*pabyBuf;
+    int			nFields, nHeadLen, nRecLen, iField;
+	DBFHandle	psDBF = NULL;
+
+	if( fp == NULL )
+	{
+		return( NULL );
+	}
+
+    psDBF = (DBFHandle) calloc( 1, sizeof(DBFInfo) );
+	psDBF->fp = fp;
+
     psDBF->bNoHeader = FALSE;
     psDBF->nCurrentRecord = -1;
     psDBF->bCurrentRecordModified = FALSE;
@@ -492,6 +582,7 @@
 
     psDBF->nHeaderLength = nHeadLen = pabyBuf[8] + pabyBuf[9]*256;
     psDBF->nRecordLength = nRecLen = pabyBuf[10] + pabyBuf[11]*256;
+	psDBF->nLanguageDriver = pabyBuf[29];
     
     psDBF->nFields = nFields = (nHeadLen - 32) / 32;
 
@@ -553,6 +644,9 @@
 void SHPAPI_CALL
 DBFClose(DBFHandle psDBF)
 {
+	if( psDBF == NULL )
+		return;
+		
 /* -------------------------------------------------------------------- */
 /*      Write out header if not already written.                        */
 /* -------------------------------------------------------------------- */
@@ -604,7 +698,6 @@
 DBFCreate( const char * pszFilename )
 
 {
-    DBFHandle	psDBF;
     FILE	*fp;
     char	*pszFullname, *pszBasename;
     int		i;
@@ -643,7 +736,80 @@
 
     free( pszFullname );
 
+	return DBFCreateEx( fp );
+}
+
+
+
+/************************************************************************/
+/*                             DBFCreateW()                             */
+/*                                                                      */
+/*      Create a new .dbf file with a wide character filename           */
+/************************************************************************/
+
+#ifdef SHPAPI_HAS_WIDE
+
+DBFHandle SHPAPI_CALL
+DBFCreateW( const wchar_t * pszFilename )
+
+{
+    FILE	*fp;
+    wchar_t	*pszFullname, *pszBasename;
+    int		i;
+
 /* -------------------------------------------------------------------- */
+/*	Compute the base (layer) name.  If there is any extension	*/
+/*	on the passed in filename we will strip it off.			*/
+/* -------------------------------------------------------------------- */
+    pszBasename = (wchar_t *) malloc(sizeof(wchar_t)*(wcslen(pszFilename)+5));
+    wcscpy( pszBasename, pszFilename );
+    for( i = wcslen(pszBasename)-1; 
+	 i > 0 && pszBasename[i] != L'.' && pszBasename[i] != L'/'
+	       && pszBasename[i] != L'\\';
+	 i-- ) {}
+
+    if( pszBasename[i] == L'.' )
+        pszBasename[i] = L'\0';
+
+    pszFullname = (wchar_t *) malloc(sizeof(wchar_t)*(wcslen(pszBasename) + 5));
+    swprintf( pszFullname, L"%s.dbf", pszBasename );
+    free( pszBasename );
+
+/* -------------------------------------------------------------------- */
+/*      Create the file.                                                */
+/* -------------------------------------------------------------------- */
+    fp = _wfopen( pszFullname, L"wb" );
+    if( fp == NULL )
+        return( NULL );
+
+    fputc( 0, fp );
+    fclose( fp );
+
+    fp = _wfopen( pszFullname, L"rb+" );
+    if( fp == NULL )
+        return( NULL );
+
+    free( pszFullname );
+
+	return DBFCreateEx( fp );
+}
+
+#endif
+
+
+/************************************************************************/
+/*                             DBFCreateEx()                            */
+/*                                                                      */
+/*      Create a new .dbf file from a freshly created file              */
+/************************************************************************/
+
+DBFHandle SHPAPI_CALL
+DBFCreateEx( FILE* fp )
+
+{
+    DBFHandle	psDBF;
+
+/* -------------------------------------------------------------------- */
 /*	Create the info structure.					*/
 /* -------------------------------------------------------------------- */
     psDBF = (DBFHandle) malloc(sizeof(DBFInfo));
@@ -665,10 +831,13 @@
     psDBF->pszCurrentRecord = NULL;
 
     psDBF->bNoHeader = TRUE;
+	psDBF->nLanguageDriver = 0x03; // ANSI
 
     return( psDBF );
 }
 
+
+
 /************************************************************************/
 /*                            DBFAddField()                             */
 /*                                                                      */
@@ -1496,7 +1665,55 @@
     DBFHandle	newDBF;
 
    newDBF = DBFCreate ( pszFilename );
-   if ( newDBF == NULL ) return ( NULL ); 
+   if ( newDBF == NULL ) return ( NULL );
+
+   DBFCloneEmptyEx( psDBF, newDBF );
+
+   DBFClose( newDBF );      
+   newDBF = DBFOpen ( pszFilename, "rb+" );
+
+   return ( newDBF );
+}
+
+
+
+
+/************************************************************************/
+/*                          DBFCloneEmptyW                              */
+/*                                                                      */
+/*      Read one of the attribute fields of a record.                   */
+/************************************************************************/
+
+#ifdef SHPAPI_HAS_WIDE
+
+DBFHandle SHPAPI_CALL
+DBFCloneEmptyW(DBFHandle psDBF, const wchar_t * pszFilename ) 
+{
+    DBFHandle	newDBF;
+
+   newDBF = DBFCreateW ( pszFilename );
+   if ( newDBF == NULL ) return ( NULL );
+
+   DBFCloneEmptyEx( psDBF, newDBF );
+
+   DBFClose( newDBF );      
+   newDBF = DBFOpenW ( pszFilename, L"rb+" );
+
+   return ( newDBF );
+}
+
+#endif
+
+/************************************************************************/
+/*                          DBFCloneEmptyEx()                           */
+/*                                                                      */
+/*      Read one of the attribute fields of a record.                   */
+/************************************************************************/
+
+void SHPAPI_CALL
+DBFCloneEmptyEx(DBFHandle psDBF, DBFHandle newDBF) 
+{
+   if ( newDBF == NULL ) return; 
    
    newDBF->pszHeader = (char *) malloc ( 32 * psDBF->nFields );
    memcpy ( newDBF->pszHeader, psDBF->pszHeader, 32 * psDBF->nFields );
@@ -1518,11 +1735,6 @@
    newDBF->bUpdated = TRUE;
    
    DBFWriteHeader ( newDBF );
-   DBFClose ( newDBF );
-   
-   newDBF = DBFOpen ( pszFilename, "rb+" );
-
-   return ( newDBF );
 }
 
 /************************************************************************/

Modified: branches/WIP-pyshapelib-Unicode/thuban/libraries/shapelib/shapefil.h
===================================================================
--- branches/WIP-pyshapelib-Unicode/thuban/libraries/shapelib/shapefil.h	2007-12-12 20:23:04 UTC (rev 2794)
+++ branches/WIP-pyshapelib-Unicode/thuban/libraries/shapelib/shapefil.h	2007-12-12 20:35:20 UTC (rev 2795)
@@ -173,6 +173,10 @@
 extern "C" {
 #endif
 
+#if defined(_WIN32) || defined(_WIN64)
+#define SHPAPI_HAS_WIDE
+#endif
+
 /************************************************************************/
 /*                        Configuration options.                        */
 /************************************************************************/
@@ -329,7 +333,18 @@
       SHPOpen( const char * pszShapeFile, const char * pszAccess );
 SHPHandle SHPAPI_CALL
       SHPCreate( const char * pszShapeFile, int nShapeType );
+#ifdef SHPAPI_HAS_WIDE
+SHPHandle SHPAPI_CALL
+      SHPOpenW( const wchar_t * pszShapeFile, const wchar_t * pszAccess );
+SHPHandle SHPAPI_CALL
+      SHPCreateW( const wchar_t * pszShapeFile, int nShapeType );
+#endif
+SHPHandle SHPAPI_CALL
+      SHPOpenEx( FILE * pfSHP, FILE * pfSHX );
 void SHPAPI_CALL
+      SHPCreateEx( FILE * pfSHP, FILE * pfSHX, int nShapeType );
+
+void SHPAPI_CALL
       SHPGetInfo( SHPHandle hSHP, int * pnEntities, int * pnShapeType,
                   double * padfMinBound, double * padfMaxBound );
 
@@ -406,6 +421,12 @@
       SHPWriteTree( SHPTree *hTree, const char * pszFilename );
 SHPTree SHPAPI_CALL
       SHPReadTree( const char * pszFilename );
+#ifdef SHPAPI_HAS_WIDE
+int	SHPAPI_CALL
+      SHPWriteTreeW( SHPTree *hTree, const wchar_t * pszFilename );
+SHPTree SHPAPI_CALL
+      SHPReadTreeW( const wchar_t * pszFilename );
+#endif
 
 int	SHPAPI_CALL
       SHPTreeAddObject( SHPTree * hTree, SHPObject * psObject );
@@ -450,6 +471,7 @@
     
     int		bNoHeader;
     int		bUpdated;
+	int		nLanguageDriver;
 } DBFInfo;
 
 typedef DBFInfo * DBFHandle;
@@ -472,6 +494,16 @@
       DBFOpen( const char * pszDBFFile, const char * pszAccess );
 DBFHandle SHPAPI_CALL
       DBFCreate( const char * pszDBFFile );
+#ifdef SHPAPI_HAS_WIDE
+DBFHandle SHPAPI_CALL
+      DBFOpenW( const wchar_t * pszDBFFile, const wchar_t * pszAccess );
+DBFHandle SHPAPI_CALL
+      DBFCreateW( const wchar_t * pszDBFFile );
+#endif
+DBFHandle SHPAPI_CALL
+      DBFOpenEx( FILE* pf );
+DBFHandle SHPAPI_CALL
+      DBFCreateEx( FILE* pf );
 
 int	SHPAPI_CALL
       DBFGetFieldCount( DBFHandle psDBF );
@@ -524,7 +556,13 @@
 
 DBFHandle SHPAPI_CALL
       DBFCloneEmpty(DBFHandle psDBF, const char * pszFilename );
- 
+#ifdef DBFAPI_HAS_WIDE
+DBFHandle SHPAPI_CALL
+      DBFCloneEmptyW(DBFHandle psDBF, const wchar_t * pszFilename );
+#endif
+void SHPAPI_CALL
+      DBFCloneEmptyEx(DBFHandle psDBF, DBFHandle newDBF );
+
 void	SHPAPI_CALL
       DBFClose( DBFHandle hDBF );
 void    SHPAPI_CALL

Modified: branches/WIP-pyshapelib-Unicode/thuban/libraries/shapelib/shpopen.c
===================================================================
--- branches/WIP-pyshapelib-Unicode/thuban/libraries/shapelib/shpopen.c	2007-12-12 20:23:04 UTC (rev 2794)
+++ branches/WIP-pyshapelib-Unicode/thuban/libraries/shapelib/shpopen.c	2007-12-12 20:35:20 UTC (rev 2795)
@@ -423,11 +423,8 @@
 
 {
     char		*pszFullname, *pszBasename;
-    SHPHandle		psSHP;
-    
-    uchar		*pabyBuf;
+    FILE		*fpSHP, *fpSHX;
     int			i;
-    double		dValue;
     
 /* -------------------------------------------------------------------- */
 /*      Ensure the access string is one of the legal ones.  We          */
@@ -450,13 +447,6 @@
         bBigEndian = TRUE;
 
 /* -------------------------------------------------------------------- */
-/*	Initialize the info structure.					*/
-/* -------------------------------------------------------------------- */
-    psSHP = (SHPHandle) calloc(sizeof(SHPInfo),1);
-
-    psSHP->bUpdated = FALSE;
-
-/* -------------------------------------------------------------------- */
 /*	Compute the base (layer) name.  If there is any extension	*/
 /*	on the passed in filename we will strip it off.			*/
 /* -------------------------------------------------------------------- */
@@ -476,43 +466,41 @@
 /* -------------------------------------------------------------------- */
     pszFullname = (char *) malloc(strlen(pszBasename) + 5);
     sprintf( pszFullname, "%s.shp", pszBasename );
-    psSHP->fpSHP = fopen(pszFullname, pszAccess );
-    if( psSHP->fpSHP == NULL )
+    fpSHP = fopen(pszFullname, pszAccess );
+    if( fpSHP == NULL )
     {
         sprintf( pszFullname, "%s.SHP", pszBasename );
-        psSHP->fpSHP = fopen(pszFullname, pszAccess );
+        fpSHP = fopen(pszFullname, pszAccess );
     }
     
-    if( psSHP->fpSHP == NULL )
+    if( fpSHP == NULL )
     {
 #ifdef USE_CPL
         CPLError( CE_Failure, CPLE_OpenFailed, 
                   "Unable to open %s.shp or %s.SHP.", 
                   pszBasename, pszBasename );
 #endif
-        free( psSHP );
         free( pszBasename );
         free( pszFullname );
         return( NULL );
     }
 
     sprintf( pszFullname, "%s.shx", pszBasename );
-    psSHP->fpSHX = fopen(pszFullname, pszAccess );
-    if( psSHP->fpSHX == NULL )
+    fpSHX = fopen(pszFullname, pszAccess );
+    if( fpSHX == NULL )
     {
         sprintf( pszFullname, "%s.SHX", pszBasename );
-        psSHP->fpSHX = fopen(pszFullname, pszAccess );
+        fpSHX = fopen(pszFullname, pszAccess );
     }
     
-    if( psSHP->fpSHX == NULL )
+    if( fpSHX == NULL )
     {
 #ifdef USE_CPL
         CPLError( CE_Failure, CPLE_OpenFailed, 
                   "Unable to open %s.shx or %s.SHX.", 
                   pszBasename, pszBasename );
 #endif
-        fclose( psSHP->fpSHP );
-        free( psSHP );
+        fclose( fpSHP );
         free( pszBasename );
         free( pszFullname );
         return( NULL );
@@ -521,7 +509,139 @@
     free( pszFullname );
     free( pszBasename );
 
+	return SHPOpenEx( fpSHP, fpSHX );
+}
+
+
+/************************************************************************/
+/*                              SHPOpenW()                              */
+/*                                                                      */
+/*      Open the .shp and .shx files based on the basename of the       */
+/*      files or either file name, for wide character filenames         */
+/************************************************************************/
+   
+#ifdef SHPAPI_HAS_WIDE
+
+SHPHandle SHPAPI_CALL
+SHPOpenW( const wchar_t * pszLayer, const wchar_t * pszAccess )
+
+{
+    wchar_t		*pszFullname, *pszBasename;
+    FILE		*fpSHP, *fpSHX;
+    int			i;
+    
 /* -------------------------------------------------------------------- */
+/*      Ensure the access string is one of the legal ones.  We          */
+/*      ensure the result string indicates binary to avoid common       */
+/*      problems on Windows.                                            */
+/* -------------------------------------------------------------------- */
+    if( wcscmp(pszAccess,L"rb+") == 0 || wcscmp(pszAccess,L"r+b") == 0
+        || wcscmp(pszAccess,L"r+") == 0 )
+        pszAccess = L"r+b";
+    else
+        pszAccess = L"rb";
+
+/* -------------------------------------------------------------------- */
+/*	Compute the base (layer) name.  If there is any extension	*/
+/*	on the passed in filename we will strip it off.			*/
+/* -------------------------------------------------------------------- */
+    pszBasename = (wchar_t *) malloc(sizeof(wchar_t)*(wcslen(pszLayer)+5));
+    wcscpy( pszBasename, pszLayer );
+    for( i = wcslen(pszBasename)-1; 
+	 i > 0 && pszBasename[i] != L'.' && pszBasename[i] != L'/'
+	       && pszBasename[i] != L'\\';
+	 i-- ) {}
+
+    if( pszBasename[i] == L'.' )
+        pszBasename[i] = L'\0';
+
+/* -------------------------------------------------------------------- */
+/*	Open the .shp and .shx files.  Note that files pulled from	*/
+/*	a PC to Unix with upper case filenames won't work!		*/
+/* -------------------------------------------------------------------- */
+    pszFullname = (wchar_t *) malloc(sizeof(wchar_t)*(wcslen(pszBasename) + 5));
+    swprintf( pszFullname, L"%s.shp", pszBasename );
+    fpSHP = _wfopen(pszFullname, pszAccess );
+    if( fpSHP == NULL )
+    {
+        swprintf( pszFullname, L"%s.SHP", pszBasename );
+        fpSHP = _wfopen(pszFullname, pszAccess );
+    }
+    
+    if( fpSHP == NULL )
+    {
+#ifdef USE_CPL
+        CPLError( CE_Failure, CPLE_OpenFailed, 
+                  "Unable to open .shp file." );
+#endif
+        free( pszBasename );
+        free( pszFullname );
+        return( NULL );
+    }
+
+    swprintf( pszFullname, L"%s.shx", pszBasename );
+    fpSHX = _wfopen(pszFullname, pszAccess );
+    if( fpSHX == NULL )
+    {
+        swprintf( pszFullname, L"%s.SHX", pszBasename );
+        fpSHX = _wfopen(pszFullname, pszAccess );
+    }
+    
+    if( fpSHX == NULL )
+    {
+#ifdef USE_CPL
+        CPLError( CE_Failure, CPLE_OpenFailed, 
+                  "Unable to open .shx file." );
+#endif
+        fclose( fpSHP );
+        free( pszBasename );
+        free( pszFullname );
+        return( NULL );
+    }
+
+    free( pszFullname );
+    free( pszBasename );
+
+	return SHPOpenEx( fpSHP, fpSHX );
+}
+
+#endif
+
+/************************************************************************/
+/*                              shpopen()                               */
+/*                                                                      */
+/*      Open the .shp and .shx files based on the basename of the       */
+/*      files or either file name.                                      */
+/************************************************************************/
+   
+SHPHandle SHPAPI_CALL
+SHPOpenEx( FILE * fpSHP, FILE * fpSHX )
+{
+    SHPHandle	psSHP;
+    uchar		*pabyBuf;
+    int			i;
+    double		dValue;
+    
+/* -------------------------------------------------------------------- */
+/*	Establish the byte order on this machine.			*/
+/* -------------------------------------------------------------------- */
+    i = 1;
+    if( *((uchar *) &i) == 1 )
+        bBigEndian = FALSE;
+    else
+        bBigEndian = TRUE;
+
+/* -------------------------------------------------------------------- */
+/*	Initialize the info structure.					*/
+/* -------------------------------------------------------------------- */
+    psSHP = (SHPHandle) calloc(sizeof(SHPInfo),1);
+
+	psSHP->fpSHP = fpSHP;
+	psSHP->fpSHX = fpSHX;
+    psSHP->bUpdated = FALSE;
+
+
+/* -------------------------------------------------------------------- */
 /*  Read the file size from the SHP file.				*/
 /* -------------------------------------------------------------------- */
     pabyBuf = (uchar *) malloc(100);
@@ -738,18 +858,6 @@
     char	*pszBasename, *pszFullname;
     int		i;
     FILE	*fpSHP, *fpSHX;
-    uchar     	abyHeader[100];
-    int32	i32;
-    double	dValue;
-    
-/* -------------------------------------------------------------------- */
-/*      Establish the byte order on this system.                        */
-/* -------------------------------------------------------------------- */
-    i = 1;
-    if( *((uchar *) &i) == 1 )
-        bBigEndian = FALSE;
-    else
-        bBigEndian = TRUE;
 
 /* -------------------------------------------------------------------- */
 /*	Compute the base (layer) name.  If there is any extension	*/
@@ -796,7 +904,116 @@
     free( pszFullname );
     free( pszBasename );
 
+	SHPCreateEx( fpSHP, fpSHX, nShapeType );
+
 /* -------------------------------------------------------------------- */
+/*      Close the files, and then open them as regular existing files.  */
+/* -------------------------------------------------------------------- */
+    fclose( fpSHP );
+    fclose( fpSHX );
+
+    return( SHPOpen( pszLayer, "r+b" ) );
+}
+
+#ifdef SHPAPI_HAS_WIDE
+
+/************************************************************************/
+/*                             SHPCreate()                              */
+/*                                                                      */
+/*      Create a new shape file and return a handle to the open         */
+/*      shape file with read/write access.                              */
+/************************************************************************/
+
+SHPHandle SHPAPI_CALL
+SHPCreateW( const wchar_t * pszLayer, int nShapeType )
+
+{
+    wchar_t	*pszBasename, *pszFullname;
+    int		i;
+    FILE	*fpSHP, *fpSHX;
+
+/* -------------------------------------------------------------------- */
+/*	Compute the base (layer) name.  If there is any extension	*/
+/*	on the passed in filename we will strip it off.			*/
+/* -------------------------------------------------------------------- */
+    pszBasename = (wchar_t *) malloc(sizeof(wchar_t)*(wcslen(pszLayer)+5));
+    wcscpy( pszBasename, pszLayer );
+    for( i = wcslen(pszBasename)-1; 
+	 i > 0 && pszBasename[i] != L'.' && pszBasename[i] != L'/'
+	       && pszBasename[i] != L'\\';
+	 i-- ) {}
+
+    if( pszBasename[i] == L'.' )
+        pszBasename[i] = L'\0';
+
+/* -------------------------------------------------------------------- */
+/*      Open the two files so we can write their headers.               */
+/* -------------------------------------------------------------------- */
+    pszFullname = (wchar_t *) malloc(sizeof(wchar_t)*(wcslen(pszBasename) + 5));
+    swprintf( pszFullname, L"%s.shp", pszBasename );
+    fpSHP = _wfopen(pszFullname, L"wb" );
+    if( fpSHP == NULL )
+    {
+#ifdef USE_CPL
+        CPLError( CE_Failure, CPLE_AppDefined, 
+                  "Failed to create file." );
+#endif
+        return( NULL );
+    }
+
+    swprintf( pszFullname, L"%s.shx", pszBasename );
+    fpSHX = _wfopen(pszFullname, L"wb" );
+    if( fpSHX == NULL )
+    {
+#ifdef USE_CPL
+        CPLError( CE_Failure, CPLE_AppDefined, 
+                  "Failed to create file." );
+#endif
+        return( NULL );
+    }
+
+    free( pszFullname );
+    free( pszBasename );
+
+	SHPCreateEx( fpSHP, fpSHX, nShapeType );
+
+/* -------------------------------------------------------------------- */
+/*      Close the files, and then open them as regular existing files.  */
+/* -------------------------------------------------------------------- */
+    fclose( fpSHP );
+    fclose( fpSHX );
+
+    return( SHPOpenW( pszLayer, L"r+b" ) );
+}
+
+#endif
+
+/************************************************************************/
+/*                             SHPCreateEx()                            */
+/*                                                                      */
+/*      Create a new shape file and return a handle to the open         */
+/*      shape file with read/write access.                              */
+/************************************************************************/
+
+void SHPAPI_CALL
+SHPCreateEx( FILE * fpSHP, FILE * fpSHX, int nShapeType )
+
+{
+    int		i;
+    uchar     	abyHeader[100];
+    int32	i32;
+    double	dValue;
+    
+/* -------------------------------------------------------------------- */
+/*      Establish the byte order on this system.                        */
+/* -------------------------------------------------------------------- */
+    i = 1;
+    if( *((uchar *) &i) == 1 )
+        bBigEndian = FALSE;
+    else
+        bBigEndian = TRUE;
+
+/* -------------------------------------------------------------------- */
 /*      Prepare header block for .shp file.                             */
 /* -------------------------------------------------------------------- */
     for( i = 0; i < 100; i++ )
@@ -832,7 +1049,7 @@
         CPLError( CE_Failure, CPLE_AppDefined, 
                   "Failed to write .shp header." );
 #endif
-        return NULL;
+        return;
     }
 
 /* -------------------------------------------------------------------- */
@@ -848,18 +1065,11 @@
         CPLError( CE_Failure, CPLE_AppDefined, 
                   "Failed to write .shx header." );
 #endif
-        return NULL;
+        return;
     }
+}
 
-/* -------------------------------------------------------------------- */
-/*      Close the files, and then open them as regular existing files.  */
-/* -------------------------------------------------------------------- */
-    fclose( fpSHP );
-    fclose( fpSHX );
 
-    return( SHPOpen( pszLayer, "r+b" ) );
-}
-
 /************************************************************************/
 /*                           _SHPSetBounds()                            */
 /*                                                                      */

Modified: branches/WIP-pyshapelib-Unicode/thuban/setup.py
===================================================================
--- branches/WIP-pyshapelib-Unicode/thuban/setup.py	2007-12-12 20:23:04 UTC (rev 2794)
+++ branches/WIP-pyshapelib-Unicode/thuban/setup.py	2007-12-12 20:35:20 UTC (rev 2795)
@@ -269,22 +269,21 @@
 # shapelib wrappers are also distributed with thuban
 #
 
-extensions.append(Extension("Lib.shapelibc",
-                            [ext_dir + "/pyshapelib/shapelib_wrap.c",
+extensions.append(Extension("Lib.shapelib",
+                            [ext_dir + "/pyshapelib/shapelibmodule.c",
                              shp_dir + "/shpopen.c",
                              shp_dir + "/shptree.c"],
                             include_dirs = [shp_dir]))
 extensions.append(Extension("Lib.shptree",
                             [ext_dir + "/pyshapelib/shptreemodule.c"],
                             include_dirs = [shp_dir]))
-extensions.append(Extension("Lib.dbflibc",
-                            [ext_dir + "/pyshapelib/dbflib_wrap.c",
+extensions.append(Extension("Lib.dbflib",
+                            [ext_dir + "/pyshapelib/dbflibmodule.c",
                              shp_dir + "/dbfopen.c"],
                             include_dirs = [shp_dir],
                             define_macros = [("HAVE_UPDATE_HEADER", "1")]))
-for name in ("shapelib", "dbflib"):
-    py_modules.append(ext_dir + "/pyshapelib/" + name)
 
+
 #
 # PROJ4 bindings are also distributed with thuban
 #



More information about the Thuban-commits mailing list