[postgis-commits] svn - r2782 - in branches/1.3: . loader
postgis-commits at postgis.refractions.net
postgis-commits at postgis.refractions.net
Mon May 26 19:59:08 PDT 2008
Author: pramsey
Date: 2008-05-26 19:59:06 -0700 (Mon, 26 May 2008)
New Revision: 2782
Modified:
branches/1.3/ChangeLog
branches/1.3/loader/dbfopen.c
branches/1.3/loader/shapefil.h
branches/1.3/loader/shp2pgsql.c
Log:
Fix for DBF files with deleted records. (#29)
Modified: branches/1.3/ChangeLog
===================================================================
--- branches/1.3/ChangeLog 2008-05-22 20:43:00 UTC (rev 2781)
+++ branches/1.3/ChangeLog 2008-05-27 02:59:06 UTC (rev 2782)
@@ -1,4 +1,8 @@
+2008-06-26 Paul Ramsey <pramsey at cleverelephant.ca>
+ * loader/shapefil.h, dbfopen.c, shp2pgsql.c
+ Fix for DBF files with deleted records. (#29)
+
2008-04-12 Paul Ramsey <pramsey at cleverelephant.ca>
* lwgeom/Makefile, lwgeom/lwgeom_chip.c,
Modified: branches/1.3/loader/dbfopen.c
===================================================================
--- branches/1.3/loader/dbfopen.c 2008-05-22 20:43:00 UTC (rev 2781)
+++ branches/1.3/loader/dbfopen.c 2008-05-27 02:59:06 UTC (rev 2782)
@@ -718,31 +718,23 @@
return( psDBF->nFields-1 );
}
+
/************************************************************************/
-/* DBFReadAttribute() */
+/* DBFReadSetup() */
/* */
-/* Read one of the attribute fields of a record. */
+/* Prep a record for reading. */
/************************************************************************/
-static void *DBFReadAttribute(DBFHandle psDBF, int hEntity, int iField,
- char chReqType )
-
+int DBFReadSetup(DBFHandle psDBF, int hEntity)
{
int nRecordOffset;
- unsigned char *pabyRec;
- void *pReturnField = NULL;
- static double dDoubleField;
-
/* -------------------------------------------------------------------- */
/* Verify selection. */
/* -------------------------------------------------------------------- */
if( hEntity < 0 || hEntity >= psDBF->nRecords )
- return( NULL );
+ return( 0 );
- if( iField < 0 || iField >= psDBF->nFields )
- return( NULL );
-
/* -------------------------------------------------------------------- */
/* Have we read the record? */
/* -------------------------------------------------------------------- */
@@ -756,7 +748,7 @@
{
fprintf( stderr, "fseek(%d) failed on DBF file.\n",
nRecordOffset );
- return NULL;
+ return 0;
}
if( fread( psDBF->pszCurrentRecord, psDBF->nRecordLength,
@@ -764,25 +756,77 @@
{
fprintf( stderr, "fread(%d) failed on DBF file.\n",
psDBF->nRecordLength );
- return NULL;
+ return 0;
}
psDBF->nCurrentRecord = hEntity;
}
+
+ return 1;
+}
+
+
+/************************************************************************/
+/* DBFReadDeleted() */
+/* */
+/* Read whether a record is deleted. */
+/************************************************************************/
+
+int DBFReadDeleted(DBFHandle psDBF, int hEntity)
+{
+ unsigned char *pabyRec;
+ unsigned char *pDeleted;
+
+ if( ! DBFReadSetup( psDBF, hEntity) )
+ return NULL;
+
+ /* get reference to current record */
+ pabyRec = (unsigned char *) psDBF->pszCurrentRecord;
+
+ /* 0x20 => not deleted, 0x24 => deleted */
+ return *pabyRec == 0x20 ? 1 : 0;
+
+}
+
+/************************************************************************/
+/* DBFReadAttribute() */
+/* */
+/* Read one of the attribute fields of a record. */
+/************************************************************************/
+
+static void *DBFReadAttribute(DBFHandle psDBF, int hEntity, int iField,
+ char chReqType )
+
+{
+ unsigned char *pabyRec;
+ void *pReturnField = NULL;
+
+ static double dDoubleField;
+
+/* -------------------------------------------------------------------- */
+/* Verify selection. */
+/* -------------------------------------------------------------------- */
+ if( iField < 0 || iField >= psDBF->nFields )
+ return( NULL );
+
+ if( ! DBFReadSetup( psDBF, hEntity) )
+ return( NULL );
+
+ /* get reference to current record */
pabyRec = (unsigned char *) psDBF->pszCurrentRecord;
/* -------------------------------------------------------------------- */
-/* Ensure our field buffer is large enough to hold this buffer. */
+/* Ensure our field buffer is large enough to hold this buffer. */
/* -------------------------------------------------------------------- */
if( psDBF->panFieldSize[iField]+1 > nStringFieldLen )
{
- nStringFieldLen = psDBF->panFieldSize[iField]*2 + 10;
- pszStringField = (char *) SfRealloc(pszStringField,nStringFieldLen);
+ nStringFieldLen = psDBF->panFieldSize[iField]*2 + 10;
+ pszStringField = (char *) SfRealloc(pszStringField,nStringFieldLen);
}
/* -------------------------------------------------------------------- */
-/* Extract the requested field. */
+/* Extract the requested field. */
/* -------------------------------------------------------------------- */
strncpy( pszStringField,
((const char *) pabyRec) + psDBF->panFieldOffset[iField],
@@ -796,9 +840,8 @@
/* -------------------------------------------------------------------- */
if( chReqType == 'N' )
{
- dDoubleField = atof(pszStringField);
-
- pReturnField = &dDoubleField;
+ dDoubleField = atof(pszStringField);
+ pReturnField = &dDoubleField;
}
/* -------------------------------------------------------------------- */
Modified: branches/1.3/loader/shapefil.h
===================================================================
--- branches/1.3/loader/shapefil.h 2008-05-22 20:43:00 UTC (rev 2781)
+++ branches/1.3/loader/shapefil.h 2008-05-27 02:59:06 UTC (rev 2782)
@@ -456,6 +456,8 @@
int SHPAPI_CALL
DBFIsAttributeNULL( DBFHandle hDBF, int iShape, int iField );
+int SHPAPI_CALL DBFReadDeleted(DBFHandle psDBF, int hEntity);
+
int SHPAPI_CALL
DBFWriteIntegerAttribute( DBFHandle hDBF, int iShape, int iField,
int nFieldValue );
Modified: branches/1.3/loader/shp2pgsql.c
===================================================================
--- branches/1.3/loader/shp2pgsql.c 2008-05-22 20:43:00 UTC (rev 2781)
+++ branches/1.3/loader/shp2pgsql.c 2008-05-27 02:59:06 UTC (rev 2782)
@@ -673,6 +673,12 @@
trans++;
/* transaction stuff done */
+ /*skip the record if it has been deleted*/
+ if(readshape != 1 && DBFReadDeleted(hDBFHandle, j)) {
+ continue;
+ }
+
+
/*open the next object */
if (readshape == 1)
{
More information about the postgis-commits
mailing list