bh: thuban/libraries/shapelib shpopen.c, 1.2, 1.3 shapefil.h, 1.2, 1.3 dbfopen.c, 1.2, 1.3
cvs@intevation.de
cvs at intevation.de
Mon May 17 17:48:00 CEST 2004
Author: bh
Update of /thubanrepository/thuban/libraries/shapelib
In directory doto:/tmp/cvs-serv23933/libraries/shapelib
Modified Files:
shpopen.c shapefil.h dbfopen.c
Log Message:
Update to newest shapelib and get rid of Thuban specific extensions,
i.e. use the new DBFUpdateHeader instead of our DBFCommit kludge
* libraries/shapelib/shpopen.c: Update to version from current
shapelib CVS.
* libraries/shapelib/shapefil.h: Update to version from current
shapelib CVS.
* libraries/shapelib/dbfopen.c: Update to version from current
shapelib CVS.
(DBFCommit): Effectively removed since shapelib itself has
DBFUpdateHeader now which is better for what DBFCommit wanted to
achieve.
We're now using an unmodified version of dbfopen.
* libraries/pyshapelib/dbflib_wrap.c, libraries/pyshapelib/dbflib.py:
Update from dbflib.i
* libraries/pyshapelib/dbflib.i (DBFInfo_commit): New. Implementation of
the commit method. This new indirection is necessary because we use the
DBFUpdateHeader function now which is not available in shapelib <=
1.2.10
(DBFFile::commit): Use DBFInfo_commit as implementation
(pragma __class__): New. Kludge to remove the commit method when
the DBFUpdateHeader function isn't available
(_have_commit): New. Helper for the pragma kludge.
* libraries/pyshapelib/setup.py (dbf_macros): New. Return the
preprocessor macros needed to compile the dbflib wrapper. Determine
whether DBFUpdateHeader is available and define the right value of
HAVE_UPDATE_HEADER
(extensions): Use dbf_macros for the dbflibc extension
* setup.py (extensions): Add the HAVE_UPDATE_HEADER macro with
value '1' to the Lib.dbflibc extension. This simply reflects the
shapelib and pyshapelib updates
Index: shpopen.c
===================================================================
RCS file: /thubanrepository/thuban/libraries/shapelib/shpopen.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- shpopen.c 2 Oct 2003 15:15:16 -0000 1.2
+++ shpopen.c 17 May 2004 15:47:57 -0000 1.3
@@ -34,9 +34,59 @@
******************************************************************************
*
* $Log$
- * Revision 1.2 2003/10/02 15:15:16 bh
+ * Revision 1.3 2004/05/17 15:47:57 bh
+ * Update to newest shapelib and get rid of Thuban specific extensions,
+ * i.e. use the new DBFUpdateHeader instead of our DBFCommit kludge
*
- * Update to shapelib 1.2.10
+ * * libraries/shapelib/shpopen.c: Update to version from current
+ * shapelib CVS.
+ *
+ * * libraries/shapelib/shapefil.h: Update to version from current
+ * shapelib CVS.
+ *
+ * * libraries/shapelib/dbfopen.c: Update to version from current
+ * shapelib CVS.
+ * (DBFCommit): Effectively removed since shapelib itself has
+ * DBFUpdateHeader now which is better for what DBFCommit wanted to
+ * achieve.
+ * We're now using an unmodified version of dbfopen.
+ *
+ * * libraries/pyshapelib/dbflib_wrap.c, libraries/pyshapelib/dbflib.py:
+ * Update from dbflib.i
+ *
+ * * libraries/pyshapelib/dbflib.i (DBFInfo_commit): New. Implementation of
+ * the commit method. This new indirection is necessary because we use the
+ * DBFUpdateHeader function now which is not available in shapelib <=
+ * 1.2.10
+ * (DBFFile::commit): Use DBFInfo_commit as implementation
+ * (pragma __class__): New. Kludge to remove the commit method when
+ * the DBFUpdateHeader function isn't available
+ * (_have_commit): New. Helper for the pragma kludge.
+ *
+ * * libraries/pyshapelib/setup.py (dbf_macros): New. Return the
+ * preprocessor macros needed to compile the dbflib wrapper. Determine
+ * whether DBFUpdateHeader is available and define the right value of
+ * HAVE_UPDATE_HEADER
+ * (extensions): Use dbf_macros for the dbflibc extension
+ *
+ * * setup.py (extensions): Add the HAVE_UPDATE_HEADER macro with
+ * value '1' to the Lib.dbflibc extension. This simply reflects the
+ * shapelib and pyshapelib updates
+ *
+ * Revision 1.44 2003/12/29 00:18:39 fwarmerdam
+ * added error checking for failed IO and optional CPL error reporting
+ *
+ * Revision 1.43 2003/12/01 16:20:08 warmerda
+ * be careful of zero vertex shapes
+ *
+ * Revision 1.42 2003/12/01 14:58:27 warmerda
+ * added degenerate object check in SHPRewindObject()
+ *
+ * Revision 1.41 2003/07/08 15:22:43 warmerda
+ * avoid warning
+ *
+ * Revision 1.40 2003/04/21 18:30:37 warmerda
+ * added header write/update public methods
*
* Revision 1.39 2002/08/26 06:46:56 warmerda
* avoid c++ comments
@@ -238,7 +288,7 @@
/* contents of the index (.shx) file. */
/************************************************************************/
-static void SHPWriteHeader( SHPHandle psSHP )
+void SHPWriteHeader( SHPHandle psSHP )
{
uchar abyHeader[100];
@@ -303,8 +353,15 @@
/* -------------------------------------------------------------------- */
/* Write .shp file header. */
/* -------------------------------------------------------------------- */
- fseek( psSHP->fpSHP, 0, 0 );
- fwrite( abyHeader, 100, 1, psSHP->fpSHP );
+ if( fseek( psSHP->fpSHP, 0, 0 ) != 0
+ || fwrite( abyHeader, 100, 1, psSHP->fpSHP ) != 1 )
+ {
+#ifdef USE_CPL
+ CPLError( CE_Failure, CPLE_OpenFailed,
+ "Failure writing .shp header." );
+#endif
+ return;
+ }
/* -------------------------------------------------------------------- */
/* Prepare, and write .shx file header. */
@@ -313,8 +370,15 @@
ByteCopy( &i32, abyHeader+24, 4 );
if( !bBigEndian ) SwapWord( 4, abyHeader+24 );
- fseek( psSHP->fpSHX, 0, 0 );
- fwrite( abyHeader, 100, 1, psSHP->fpSHX );
+ if( fseek( psSHP->fpSHX, 0, 0 ) != 0
+ || fwrite( abyHeader, 100, 1, psSHP->fpSHX ) != 1 )
+ {
+#ifdef USE_CPL
+ CPLError( CE_Failure, CPLE_OpenFailed,
+ "Failure writing .shx header." );
+#endif
+ return;
+ }
/* -------------------------------------------------------------------- */
/* Write out the .shx contents. */
@@ -329,13 +393,26 @@
if( !bBigEndian ) SwapWord( 4, panSHX+i*2+1 );
}
- fwrite( panSHX, sizeof(int32) * 2, psSHP->nRecords, psSHP->fpSHX );
+ if( fwrite( panSHX, sizeof(int32) * 2, psSHP->nRecords, psSHP->fpSHX )
+ != psSHP->nRecords )
+ {
+#ifdef USE_CPL
+ CPLError( CE_Failure, CPLE_OpenFailed,
+ "Failure writing .shx contents." );
+#endif
+ }
free( panSHX );
+
+/* -------------------------------------------------------------------- */
+/* Flush to disk. */
+/* -------------------------------------------------------------------- */
+ fflush( psSHP->fpSHP );
+ fflush( psSHP->fpSHX );
}
/************************************************************************/
-/* SHPOpen() */
+/* shpopen() */
/* */
/* Open the .shp and .shx files based on the basename of the */
/* files or either file name. */
@@ -408,6 +485,11 @@
if( psSHP->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 );
@@ -424,6 +506,11 @@
if( psSHP->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 );
free( pszBasename );
@@ -448,13 +535,16 @@
/* -------------------------------------------------------------------- */
/* Read SHX file Header info */
/* -------------------------------------------------------------------- */
- fread( pabyBuf, 100, 1, psSHP->fpSHX );
-
- if( pabyBuf[0] != 0
+ if( fread( pabyBuf, 100, 1, psSHP->fpSHX ) != 1
+ || pabyBuf[0] != 0
|| pabyBuf[1] != 0
|| pabyBuf[2] != 0x27
|| (pabyBuf[3] != 0x0a && pabyBuf[3] != 0x0d) )
{
+#ifdef USE_CPL
+ CPLError( CE_Failure, CPLE_AppDefined,
+ ".shx file is unreadable, or corrupt." );
+#endif
fclose( psSHP->fpSHP );
fclose( psSHP->fpSHX );
free( psSHP );
@@ -470,7 +560,12 @@
if( psSHP->nRecords < 0 || psSHP->nRecords > 256000000 )
{
- /* this header appears to be corrupt. Give up. */
+#ifdef USE_CPL
+ CPLError( CE_Failure, CPLE_AppDefined,
+ "Record count in .shp header is %d, which seems\n"
+ "unreasonable. Assuming header is corrupt.",
+ psSHP->nRecords );
+#endif
fclose( psSHP->fpSHP );
fclose( psSHP->fpSHX );
free( psSHP );
@@ -527,7 +622,22 @@
(int *) malloc(sizeof(int) * MAX(1,psSHP->nMaxRecords) );
pabyBuf = (uchar *) malloc(8 * MAX(1,psSHP->nRecords) );
- fread( pabyBuf, 8, psSHP->nRecords, psSHP->fpSHX );
+ if( fread( pabyBuf, 8, psSHP->nRecords, psSHP->fpSHX ) != psSHP->nRecords )
+ {
+#ifdef USE_CPL
+ CPLError( CE_Failure, CPLE_AppDefined,
+ "Failed to read all values for %d records in .shx file.",
+ psSHP->nRecords );
+#endif
+ /* SHX is short or unreadable for some reason. */
+ fclose( psSHP->fpSHP );
+ fclose( psSHP->fpSHX );
+ free( psSHP->panRecOffset );
+ free( psSHP->panRecSize );
+ free( psSHP );
+
+ return( NULL );
+ }
for( i = 0; i < psSHP->nRecords; i++ )
{
@@ -557,13 +667,14 @@
SHPClose(SHPHandle psSHP )
{
+ if( psSHP == NULL )
+ return;
+
/* -------------------------------------------------------------------- */
/* Update the header if we have modified anything. */
/* -------------------------------------------------------------------- */
if( psSHP->bUpdated )
- {
SHPWriteHeader( psSHP );
- }
/* -------------------------------------------------------------------- */
/* Free all resources, and close files. */
@@ -594,6 +705,9 @@
{
int i;
+
+ if( psSHP == NULL )
+ return;
if( pnEntities != NULL )
*pnEntities = psSHP->nRecords;
@@ -658,12 +772,26 @@
sprintf( pszFullname, "%s.shp", pszBasename );
fpSHP = fopen(pszFullname, "wb" );
if( fpSHP == NULL )
+ {
+#ifdef USE_CPL
+ CPLError( CE_Failure, CPLE_AppDefined,
+ "Failed to create file %s.",
+ pszFullname );
+#endif
return( NULL );
+ }
sprintf( pszFullname, "%s.shx", pszBasename );
fpSHX = fopen(pszFullname, "wb" );
if( fpSHX == NULL )
+ {
+#ifdef USE_CPL
+ CPLError( CE_Failure, CPLE_AppDefined,
+ "Failed to create file %s.",
+ pszFullname );
+#endif
return( NULL );
+ }
free( pszFullname );
free( pszBasename );
@@ -698,7 +826,14 @@
/* -------------------------------------------------------------------- */
/* Write .shp file header. */
/* -------------------------------------------------------------------- */
- fwrite( abyHeader, 100, 1, fpSHP );
+ if( fwrite( abyHeader, 100, 1, fpSHP ) != 1 )
+ {
+#ifdef USE_CPL
+ CPLError( CE_Failure, CPLE_AppDefined,
+ "Failed to write .shp header." );
+#endif
+ return NULL;
+ }
/* -------------------------------------------------------------------- */
/* Prepare, and write .shx file header. */
@@ -707,7 +842,14 @@
ByteCopy( &i32, abyHeader+24, 4 );
if( !bBigEndian ) SwapWord( 4, abyHeader+24 );
- fwrite( abyHeader, 100, 1, fpSHX );
+ if( fwrite( abyHeader, 100, 1, fpSHX ) != 1 )
+ {
+#ifdef USE_CPL
+ CPLError( CE_Failure, CPLE_AppDefined,
+ "Failed to write .shx header." );
+#endif
+ return NULL;
+ }
/* -------------------------------------------------------------------- */
/* Close the files, and then open them as regular existing files. */
@@ -918,7 +1060,7 @@
SHPWriteObject(SHPHandle psSHP, int nShapeId, SHPObject * psObject )
{
- int nRecordOffset, i, nRecordSize;
+ int nRecordOffset, i, nRecordSize=0;
uchar *pabyRec;
int32 i32;
@@ -1232,7 +1374,10 @@
if( fseek( psSHP->fpSHP, nRecordOffset, 0 ) != 0
|| fwrite( pabyRec, nRecordSize, 1, psSHP->fpSHP ) < 1 )
{
- printf( "Error in fseek() or fwrite().\n" );
+#ifdef USE_CPL
+ CPLError( CE_Failure, CPLE_FileIO,
+ "Error in fseek() or fwrite() writing object to .shp file." );
+#endif
free( pabyRec );
return -1;
}
@@ -1245,13 +1390,22 @@
if( psSHP->adBoundsMin[0] == 0.0
&& psSHP->adBoundsMax[0] == 0.0
&& psSHP->adBoundsMin[1] == 0.0
- && psSHP->adBoundsMax[1] == 0.0
- && psObject->nSHPType != SHPT_NULL )
+ && psSHP->adBoundsMax[1] == 0.0 )
{
- psSHP->adBoundsMin[0] = psSHP->adBoundsMax[0] = psObject->padfX[0];
- psSHP->adBoundsMin[1] = psSHP->adBoundsMax[1] = psObject->padfY[0];
- psSHP->adBoundsMin[2] = psSHP->adBoundsMax[2] = psObject->padfZ[0];
- psSHP->adBoundsMin[3] = psSHP->adBoundsMax[3] = psObject->padfM[0];
+ if( psObject->nSHPType == SHPT_NULL || psObject->nVertices == 0 )
+ {
+ psSHP->adBoundsMin[0] = psSHP->adBoundsMax[0] = 0.0;
+ psSHP->adBoundsMin[1] = psSHP->adBoundsMax[1] = 0.0;
+ psSHP->adBoundsMin[2] = psSHP->adBoundsMax[2] = 0.0;
+ psSHP->adBoundsMin[3] = psSHP->adBoundsMax[3] = 0.0;
+ }
+ else
+ {
+ psSHP->adBoundsMin[0] = psSHP->adBoundsMax[0] = psObject->padfX[0];
+ psSHP->adBoundsMin[1] = psSHP->adBoundsMax[1] = psObject->padfY[0];
+ psSHP->adBoundsMin[2] = psSHP->adBoundsMax[2] = psObject->padfZ[0];
+ psSHP->adBoundsMin[3] = psSHP->adBoundsMax[3] = psObject->padfM[0];
+ }
}
for( i = 0; i < psObject->nVertices; i++ )
@@ -1300,8 +1454,16 @@
/* -------------------------------------------------------------------- */
/* Read the record. */
/* -------------------------------------------------------------------- */
- fseek( psSHP->fpSHP, psSHP->panRecOffset[hEntity], 0 );
- fread( psSHP->pabyRec, psSHP->panRecSize[hEntity]+8, 1, psSHP->fpSHP );
+ if( fseek( psSHP->fpSHP, psSHP->panRecOffset[hEntity], 0 ) != 0
+ || fread( psSHP->pabyRec, psSHP->panRecSize[hEntity]+8, 1,
+ psSHP->fpSHP ) != 1 )
+ {
+#ifdef USE_CPL
+ CPLError( CE_Failure, CPLE_FileIO,
+ "Error in fseek() or fread() reading object from .shp file." );
+#endif
+ return NULL;
+ }
/* -------------------------------------------------------------------- */
/* Allocate and minimally initialize the object. */
@@ -1737,6 +1899,9 @@
if( psObject->nSHPType != SHPT_POLYGON
&& psObject->nSHPType != SHPT_POLYGONZ
&& psObject->nSHPType != SHPT_POLYGONM )
+ return 0;
+
+ if( psObject->nVertices == 0 || psObject->nParts == 0 )
return 0;
/* -------------------------------------------------------------------- */
Index: shapefil.h
===================================================================
RCS file: /thubanrepository/thuban/libraries/shapelib/shapefil.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- shapefil.h 2 Oct 2003 15:15:16 -0000 1.2
+++ shapefil.h 17 May 2004 15:47:57 -0000 1.3
@@ -37,9 +37,50 @@
******************************************************************************
*
* $Log$
- * Revision 1.2 2003/10/02 15:15:16 bh
+ * Revision 1.3 2004/05/17 15:47:57 bh
+ * Update to newest shapelib and get rid of Thuban specific extensions,
+ * i.e. use the new DBFUpdateHeader instead of our DBFCommit kludge
*
- * Update to shapelib 1.2.10
+ * * libraries/shapelib/shpopen.c: Update to version from current
+ * shapelib CVS.
+ *
+ * * libraries/shapelib/shapefil.h: Update to version from current
+ * shapelib CVS.
+ *
+ * * libraries/shapelib/dbfopen.c: Update to version from current
+ * shapelib CVS.
+ * (DBFCommit): Effectively removed since shapelib itself has
+ * DBFUpdateHeader now which is better for what DBFCommit wanted to
+ * achieve.
+ * We're now using an unmodified version of dbfopen.
+ *
+ * * libraries/pyshapelib/dbflib_wrap.c, libraries/pyshapelib/dbflib.py:
+ * Update from dbflib.i
+ *
+ * * libraries/pyshapelib/dbflib.i (DBFInfo_commit): New. Implementation of
+ * the commit method. This new indirection is necessary because we use the
+ * DBFUpdateHeader function now which is not available in shapelib <=
+ * 1.2.10
+ * (DBFFile::commit): Use DBFInfo_commit as implementation
+ * (pragma __class__): New. Kludge to remove the commit method when
+ * the DBFUpdateHeader function isn't available
+ * (_have_commit): New. Helper for the pragma kludge.
+ *
+ * * libraries/pyshapelib/setup.py (dbf_macros): New. Return the
+ * preprocessor macros needed to compile the dbflib wrapper. Determine
+ * whether DBFUpdateHeader is available and define the right value of
+ * HAVE_UPDATE_HEADER
+ * (extensions): Use dbf_macros for the dbflibc extension
+ *
+ * * setup.py (extensions): Add the HAVE_UPDATE_HEADER macro with
+ * value '1' to the Lib.dbflibc extension. This simply reflects the
+ * shapelib and pyshapelib updates
+ *
+ * Revision 1.28 2003/12/29 06:02:18 fwarmerdam
+ * added cpl_error.h option
+ *
+ * Revision 1.27 2003/04/21 18:30:37 warmerda
+ * added header write/update public methods
*
* Revision 1.26 2002/09/29 00:00:08 warmerda
* added FTLogical and logical attribute read/write calls
@@ -124,6 +165,10 @@
#include <dbmalloc.h>
#endif
+#ifdef USE_CPL
+#include "cpl_error.h"
+#endif
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -309,8 +354,8 @@
int SHPAPI_CALL
SHPRewindObject( SHPHandle hSHP, SHPObject * psObject );
-void SHPAPI_CALL
- SHPClose( SHPHandle hSHP );
+void SHPAPI_CALL SHPClose( SHPHandle hSHP );
+void SHPAPI_CALL SHPWriteHeader( SHPHandle hSHP );
const char SHPAPI_CALL1(*)
SHPTypeName( int nSHPType );
@@ -478,11 +523,10 @@
void SHPAPI_CALL
DBFClose( DBFHandle hDBF );
+void SHPAPI_CALL
+ DBFUpdateHeader( DBFHandle hDBF );
char SHPAPI_CALL
DBFGetNativeFieldType( DBFHandle hDBF, int iField );
-
-int SHPAPI_CALL
- DBFCommit( DBFHandle hDBF );
#ifdef __cplusplus
}
Index: dbfopen.c
===================================================================
RCS file: /thubanrepository/thuban/libraries/shapelib/dbfopen.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- dbfopen.c 2 Oct 2003 15:15:16 -0000 1.2
+++ dbfopen.c 17 May 2004 15:47:57 -0000 1.3
@@ -34,9 +34,59 @@
******************************************************************************
*
* $Log$
- * Revision 1.2 2003/10/02 15:15:16 bh
+ * Revision 1.3 2004/05/17 15:47:57 bh
+ * Update to newest shapelib and get rid of Thuban specific extensions,
+ * i.e. use the new DBFUpdateHeader instead of our DBFCommit kludge
*
- * Update to shapelib 1.2.10
+ * * libraries/shapelib/shpopen.c: Update to version from current
+ * shapelib CVS.
+ *
+ * * libraries/shapelib/shapefil.h: Update to version from current
+ * shapelib CVS.
+ *
+ * * libraries/shapelib/dbfopen.c: Update to version from current
+ * shapelib CVS.
+ * (DBFCommit): Effectively removed since shapelib itself has
+ * DBFUpdateHeader now which is better for what DBFCommit wanted to
+ * achieve.
+ * We're now using an unmodified version of dbfopen.
+ *
+ * * libraries/pyshapelib/dbflib_wrap.c, libraries/pyshapelib/dbflib.py:
+ * Update from dbflib.i
+ *
+ * * libraries/pyshapelib/dbflib.i (DBFInfo_commit): New. Implementation of
+ * the commit method. This new indirection is necessary because we use the
+ * DBFUpdateHeader function now which is not available in shapelib <=
+ * 1.2.10
+ * (DBFFile::commit): Use DBFInfo_commit as implementation
+ * (pragma __class__): New. Kludge to remove the commit method when
+ * the DBFUpdateHeader function isn't available
+ * (_have_commit): New. Helper for the pragma kludge.
+ *
+ * * libraries/pyshapelib/setup.py (dbf_macros): New. Return the
+ * preprocessor macros needed to compile the dbflib wrapper. Determine
+ * whether DBFUpdateHeader is available and define the right value of
+ * HAVE_UPDATE_HEADER
+ * (extensions): Use dbf_macros for the dbflibc extension
+ *
+ * * setup.py (extensions): Add the HAVE_UPDATE_HEADER macro with
+ * value '1' to the Lib.dbflibc extension. This simply reflects the
+ * shapelib and pyshapelib updates
+ *
+ * Revision 1.53 2003/12/29 00:00:30 fwarmerdam
+ * mark DBFWriteAttributeDirectly as SHPAPI_CALL
+ *
+ * Revision 1.52 2003/07/08 15:20:03 warmerda
+ * avoid warnings about downcasting to unsigned char
+ *
+ * Revision 1.51 2003/07/08 13:50:15 warmerda
+ * DBFIsAttributeNULL check for pszValue==NULL - bug 360
+ *
+ * Revision 1.50 2003/04/21 18:58:25 warmerda
+ * ensure current record is flushed at same time as header is updated
+ *
+ * Revision 1.49 2003/04/21 18:30:37 warmerda
+ * added header write/update public methods
*
* Revision 1.48 2003/03/10 14:51:27 warmerda
* DBFWrite* calls now return FALSE if they have to truncate
@@ -248,13 +298,18 @@
abyHeader[0] = 0x03; /* memo field? - just copying */
- /* date updated on close, record count preset at zero */
+ /* write out a dummy date */
+ abyHeader[1] = 95; /* YY */
+ abyHeader[2] = 7; /* MM */
+ abyHeader[3] = 26; /* DD */
- abyHeader[8] = psDBF->nHeaderLength % 256;
- abyHeader[9] = psDBF->nHeaderLength / 256;
+ /* record count preset at zero */
+
+ abyHeader[8] = (unsigned char) (psDBF->nHeaderLength % 256);
+ abyHeader[9] = (unsigned char) (psDBF->nHeaderLength / 256);
- abyHeader[10] = psDBF->nRecordLength % 256;
- abyHeader[11] = psDBF->nRecordLength / 256;
+ abyHeader[10] = (unsigned char) (psDBF->nRecordLength % 256);
+ abyHeader[11] = (unsigned char) (psDBF->nRecordLength / 256);
/* -------------------------------------------------------------------- */
/* Write the initial 32 byte file header, and all the field */
@@ -300,6 +355,35 @@
}
/************************************************************************/
+/* DBFUpdateHeader() */
+/************************************************************************/
+
+void SHPAPI_CALL
+DBFUpdateHeader( DBFHandle psDBF )
+
+{
+ unsigned char abyFileHeader[32];
+
+ if( psDBF->bNoHeader )
+ DBFWriteHeader( psDBF );
+
+ DBFFlushRecord( psDBF );
+
+ fseek( psDBF->fp, 0, 0 );
+ fread( abyFileHeader, 32, 1, psDBF->fp );
+
+ abyFileHeader[4] = (unsigned char) (psDBF->nRecords % 256);
+ abyFileHeader[5] = (unsigned char) ((psDBF->nRecords/256) % 256);
+ abyFileHeader[6] = (unsigned char) ((psDBF->nRecords/(256*256)) % 256);
+ abyFileHeader[7] = (unsigned char) ((psDBF->nRecords/(256*256*256)) % 256);
+
+ fseek( psDBF->fp, 0, 0 );
+ fwrite( abyFileHeader, 32, 1, psDBF->fp );
+
+ fflush( psDBF->fp );
+}
+
+/************************************************************************/
/* DBFOpen() */
/* */
/* Open a .dbf file. */
@@ -458,24 +542,7 @@
/* write access. */
/* -------------------------------------------------------------------- */
if( psDBF->bUpdated )
- {
- unsigned char abyFileHeader[32];
-
- fseek( psDBF->fp, 0, 0 );
- fread( abyFileHeader, 32, 1, psDBF->fp );
-
- abyFileHeader[1] = 95; /* YY */
- abyFileHeader[2] = 7; /* MM */
- abyFileHeader[3] = 26; /* DD */
-
- abyFileHeader[4] = psDBF->nRecords % 256;
- abyFileHeader[5] = (psDBF->nRecords/256) % 256;
- abyFileHeader[6] = (psDBF->nRecords/(256*256)) % 256;
- abyFileHeader[7] = (psDBF->nRecords/(256*256*256)) % 256;
-
- fseek( psDBF->fp, 0, 0 );
- fwrite( abyFileHeader, 32, 1, psDBF->fp );
- }
+ DBFUpdateHeader( psDBF );
/* -------------------------------------------------------------------- */
/* Close, and free resources. */
@@ -663,13 +730,13 @@
if( eType == FTString )
{
- pszFInfo[16] = nWidth % 256;
- pszFInfo[17] = nWidth / 256;
+ pszFInfo[16] = (unsigned char) (nWidth % 256);
+ pszFInfo[17] = (unsigned char) (nWidth / 256);
}
else
{
- pszFInfo[16] = nWidth;
- pszFInfo[17] = nDecimals;
+ pszFInfo[16] = (unsigned char) nWidth;
+ pszFInfo[17] = (unsigned char) nDecimals;
}
/* -------------------------------------------------------------------- */
@@ -870,6 +937,9 @@
pszValue = DBFReadStringAttribute( psDBF, iRecord, iField );
+ if( pszValue == NULL )
+ return TRUE;
+
switch(psDBF->pachFieldType[iField])
{
case 'N':
@@ -1141,7 +1211,8 @@
/* as is to the field position in the record. */
/************************************************************************/
-int DBFWriteAttributeDirectly(DBFHandle psDBF, int hEntity, int iField,
+int SHPAPI_CALL
+DBFWriteAttributeDirectly(DBFHandle psDBF, int hEntity, int iField,
void * pValue )
{
@@ -1464,7 +1535,7 @@
while (++i < len)
if (isalpha(string[i]) && islower(string[i]))
- string[i] = toupper ((int)string[i]);
+ string[i] = (char) toupper ((int)string[i]);
}
/************************************************************************/
@@ -1496,21 +1567,4 @@
return(i);
}
return(-1);
-}
-
-/************************************************************************/
-/* DBFCommit() */
-/* */
-/* Write any changes made into the file. */
-/* */
-/************************************************************************/
-int SHPAPI_CALL
-DBFCommit( DBFHandle psDBF )
-
-{
- DBFFlushRecord( psDBF );
- if (fflush( psDBF->fp ) == EOF)
- return FALSE;
-
- return TRUE;
}
More information about the Thuban-devel
mailing list
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)