#include "shapefil.h"
#include <math.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
Go to the source code of this file.
Defines | |
| #define | FALSE 0 |
| #define | TRUE 1 |
Functions | |
| int SHPAPI_CALL | DBFAddField (DBFHandle psDBF, const char *pszFieldName, DBFFieldType eType, int nWidth, int nDecimals) |
| DBFHandle SHPAPI_CALL | DBFCloneEmpty (DBFHandle psDBF, const char *pszFilename) |
| void SHPAPI_CALL | DBFClose (DBFHandle psDBF) |
| DBFHandle SHPAPI_CALL | DBFCreate (const char *pszFilename) |
| static void | DBFFlushRecord (DBFHandle psDBF) |
| int SHPAPI_CALL | DBFGetFieldCount (DBFHandle psDBF) |
| int SHPAPI_CALL | DBFGetFieldIndex (DBFHandle psDBF, const char *pszFieldName) |
| DBFFieldType SHPAPI_CALL | DBFGetFieldInfo (DBFHandle psDBF, int iField, char *pszFieldName, int *pnWidth, int *pnDecimals) |
| char SHPAPI_CALL | DBFGetNativeFieldType (DBFHandle psDBF, int iField) |
| int SHPAPI_CALL | DBFGetRecordCount (DBFHandle psDBF) |
| int SHPAPI_CALL | DBFIsAttributeNULL (DBFHandle psDBF, int iRecord, int iField) |
| DBFHandle SHPAPI_CALL | DBFOpen (const char *pszFilename, const char *pszAccess) |
| static void * | DBFReadAttribute (DBFHandle psDBF, int hEntity, int iField, char chReqType) |
| const char SHPAPI_CALL1 * | DBFReadDateAttribute (DBFHandle psDBF, int iRecord, int iField){return((const char *) DBFReadAttribute(psDBF, iRecord, iField, 'D') |
| double SHPAPI_CALL | DBFReadDoubleAttribute (DBFHandle psDBF, int iRecord, int iField) |
| int SHPAPI_CALL | DBFReadIntegerAttribute (DBFHandle psDBF, int iRecord, int iField) |
| const char SHPAPI_CALL1 * | DBFReadLogicalAttribute (DBFHandle psDBF, int iRecord, int iField){return((const char *) DBFReadAttribute(psDBF, iRecord, iField, 'L') |
| const char SHPAPI_CALL1 * | DBFReadStringAttribute (DBFHandle psDBF, int iRecord, int iField){return((const char *) DBFReadAttribute(psDBF, iRecord, iField, 'C') |
| const char SHPAPI_CALL1 * | DBFReadTuple (DBFHandle psDBF, int hEntity){intnRecordOffset;unsigned char *pabyRec;static char *pReturnTuple=NULL;static int nTupleLen=0;if(hEntity< 0||hEntity >=psDBF->nRecords) return(NULL |
| static int | DBFWriteAttribute (DBFHandle psDBF, int hEntity, int iField, void *pValue) |
| int | DBFWriteAttributeDirectly (DBFHandle psDBF, int hEntity, int iField, void *pValue) |
| int SHPAPI_CALL | DBFWriteDateAttribute (DBFHandle psDBF, int iRecord, int iField, const char *pszValue) |
| int SHPAPI_CALL | DBFWriteDoubleAttribute (DBFHandle psDBF, int iRecord, int iField, double dValue) |
| static void | DBFWriteHeader (DBFHandle psDBF) |
| int SHPAPI_CALL | DBFWriteIntegerAttribute (DBFHandle psDBF, int iRecord, int iField, int nValue) |
| int SHPAPI_CALL | DBFWriteLogicalAttribute (DBFHandle psDBF, int iRecord, int iField, const char lValue) |
| int SHPAPI_CALL | DBFWriteNULLAttribute (DBFHandle psDBF, int iRecord, int iField) |
| int SHPAPI_CALL | DBFWriteStringAttribute (DBFHandle psDBF, int iRecord, int iField, const char *pszValue) |
| int SHPAPI_CALL | DBFWriteTuple (DBFHandle psDBF, int hEntity, void *pRawTuple) |
| if (nTupleLen< psDBF->nRecordLength) | |
| if (psDBF->nCurrentRecord!=hEntity) | |
| memcpy (pReturnTuple, pabyRec, psDBF->nRecordLength) | |
| return (pReturnTuple) | |
| static void * | SfRealloc (void *pMem, int nNewSize) |
| static void | str_to_upper (char *string) |
Variables | |
| static int | nStringFieldLen = 0 |
| pabyRec = (unsigned char *) psDBF->pszCurrentRecord | |
| static char * | pszStringField = NULL |
| #define FALSE 0 |
Definition at line 202 of file dbfopen.c.
Referenced by Convert2TerraLib(), DBFAddField(), DBFCreate(), DBFFlushRecord(), DBFOpen(), DBFWriteAttribute(), DBFWriteAttributeDirectly(), DBFWriteHeader(), DBFWriteTuple(), oracle::occi::getVector(), oracle::occi::getVectorOfRefs(), if(), TeGDALDecoder::initialize(), SHPCreate(), SHPOpen(), SHPRewindObject(), SHPWriteObject(), SPL::slcMutex::slcMutex(), and TeThreadSignal::TeThreadSignal().
| #define TRUE 1 |
Definition at line 203 of file dbfopen.c.
Referenced by TeOCICursor::allocateCursor(), TeOCIConnection::allocateObjectOrdinates(), TeOCICursor::appendOrdinates(), TeOCICursor::bindOrdinates(), DBFCloneEmpty(), DBFCreate(), DBFWriteAttribute(), DBFWriteTuple(), if(), METHODDEF(), TeOCICursor::open(), SHPCreate(), SHPOpen(), SHPWriteObject(), SPL::slcMutex::slcMutex(), TeMutex::TeMutex(), TeQtDatabasesListView::TeQtDatabasesListView(), TeQtViewsListView::TeQtViewsListView(), TeSemaphore::TeSemaphore(), and TeThreadSignal::TeThreadSignal().
| int SHPAPI_CALL DBFAddField | ( | DBFHandle | psDBF, | |
| const char * | pszFieldName, | |||
| DBFFieldType | eType, | |||
| int | nWidth, | |||
| int | nDecimals | |||
| ) |
Definition at line 591 of file dbfopen.c.
Referenced by exportPS2SHP(), TeCreateDBFFile(), and TeExportShapefile().
00594 { 00595 char *pszFInfo; 00596 int i; 00597 00598 /* -------------------------------------------------------------------- */ 00599 /* Do some checking to ensure we can add records to this file. */ 00600 /* -------------------------------------------------------------------- */ 00601 if( psDBF->nRecords > 0 ) 00602 return( -1 ); 00603 00604 if( !psDBF->bNoHeader ) 00605 return( -1 ); 00606 00607 if( eType != FTDouble && nDecimals != 0 ) 00608 return( -1 ); 00609 00610 if( nWidth < 1 ) 00611 return -1; 00612 00613 /* -------------------------------------------------------------------- */ 00614 /* SfRealloc all the arrays larger to hold the additional field */ 00615 /* information. */ 00616 /* -------------------------------------------------------------------- */ 00617 psDBF->nFields++; 00618 00619 psDBF->panFieldOffset = (int *) 00620 SfRealloc( psDBF->panFieldOffset, sizeof(int) * psDBF->nFields ); 00621 00622 psDBF->panFieldSize = (int *) 00623 SfRealloc( psDBF->panFieldSize, sizeof(int) * psDBF->nFields ); 00624 00625 psDBF->panFieldDecimals = (int *) 00626 SfRealloc( psDBF->panFieldDecimals, sizeof(int) * psDBF->nFields ); 00627 00628 psDBF->pachFieldType = (char *) 00629 SfRealloc( psDBF->pachFieldType, sizeof(char) * psDBF->nFields ); 00630 00631 /* -------------------------------------------------------------------- */ 00632 /* Assign the new field information fields. */ 00633 /* -------------------------------------------------------------------- */ 00634 psDBF->panFieldOffset[psDBF->nFields-1] = psDBF->nRecordLength; 00635 psDBF->nRecordLength += nWidth; 00636 psDBF->panFieldSize[psDBF->nFields-1] = nWidth; 00637 psDBF->panFieldDecimals[psDBF->nFields-1] = nDecimals; 00638 00639 if( eType == FTDate ) 00640 psDBF->pachFieldType[psDBF->nFields-1] = 'D'; 00641 else if( eType == FTLogical ) 00642 psDBF->pachFieldType[psDBF->nFields-1] = 'L'; 00643 else if( eType == FTString ) 00644 psDBF->pachFieldType[psDBF->nFields-1] = 'C'; 00645 else 00646 psDBF->pachFieldType[psDBF->nFields-1] = 'N'; 00647 00648 /* -------------------------------------------------------------------- */ 00649 /* Extend the required header information. */ 00650 /* -------------------------------------------------------------------- */ 00651 psDBF->nHeaderLength += 32; 00652 psDBF->bUpdated = FALSE; 00653 00654 psDBF->pszHeader = (char *) SfRealloc(psDBF->pszHeader,psDBF->nFields*32); 00655 00656 pszFInfo = psDBF->pszHeader + 32 * (psDBF->nFields-1); 00657 00658 for( i = 0; i < 32; i++ ) 00659 pszFInfo[i] = '\0'; 00660 00661 if( (int) strlen(pszFieldName) < 10 ) 00662 strncpy( pszFInfo, pszFieldName, strlen(pszFieldName)); 00663 else 00664 strncpy( pszFInfo, pszFieldName, 10); 00665 00666 pszFInfo[11] = psDBF->pachFieldType[psDBF->nFields-1]; 00667 00668 if( eType == FTDate ) 00669 { 00670 pszFInfo[16] = 8 % 256; 00671 pszFInfo[17] = 8 / 256; 00672 } 00673 else if( eType == FTString ) 00674 { 00675 pszFInfo[16] = nWidth % 256; 00676 pszFInfo[17] = nWidth / 256; 00677 } 00678 else 00679 { 00680 pszFInfo[16] = nWidth; 00681 pszFInfo[17] = nDecimals; 00682 } 00683 00684 /* -------------------------------------------------------------------- */ 00685 /* Make the current record buffer appropriately larger. */ 00686 /* -------------------------------------------------------------------- */ 00687 psDBF->pszCurrentRecord = (char *) SfRealloc(psDBF->pszCurrentRecord, 00688 psDBF->nRecordLength); 00689 00690 return( psDBF->nFields-1 ); 00691 }
Definition at line 1439 of file dbfopen.c.
01440 { 01441 DBFHandle newDBF; 01442 01443 newDBF = DBFCreate ( pszFilename ); 01444 if ( newDBF == NULL ) return ( NULL ); 01445 01446 newDBF->pszHeader = (char *) malloc ( 32 * psDBF->nFields ); 01447 memcpy ( newDBF->pszHeader, psDBF->pszHeader, 32 * psDBF->nFields ); 01448 01449 newDBF->nFields = psDBF->nFields; 01450 newDBF->nRecordLength = psDBF->nRecordLength; 01451 newDBF->nHeaderLength = 32 * (psDBF->nFields+1); 01452 01453 newDBF->panFieldOffset = (int *) malloc ( sizeof(int) * psDBF->nFields ); 01454 memcpy ( newDBF->panFieldOffset, psDBF->panFieldOffset, sizeof(int) * psDBF->nFields ); 01455 newDBF->panFieldSize = (int *) malloc ( sizeof(int) * psDBF->nFields ); 01456 memcpy ( newDBF->panFieldSize, psDBF->panFieldSize, sizeof(int) * psDBF->nFields ); 01457 newDBF->panFieldDecimals = (int *) malloc ( sizeof(int) * psDBF->nFields ); 01458 memcpy ( newDBF->panFieldDecimals, psDBF->panFieldDecimals, sizeof(int) * psDBF->nFields ); 01459 newDBF->pachFieldType = (char *) malloc ( sizeof(int) * psDBF->nFields ); 01460 memcpy ( newDBF->pachFieldType, psDBF->pachFieldType, sizeof(int) * psDBF->nFields ); 01461 01462 newDBF->bNoHeader = TRUE; 01463 newDBF->bUpdated = TRUE; 01464 01465 DBFWriteHeader ( newDBF ); 01466 DBFClose ( newDBF ); 01467 01468 newDBF = DBFOpen ( pszFilename, "rb+" ); 01469 01470 return ( newDBF ); 01471 }
| void SHPAPI_CALL DBFClose | ( | DBFHandle | psDBF | ) |
Definition at line 448 of file dbfopen.c.
Referenced by TeShapefileDriver::close(), DBFCloneEmpty(), exportPS2SHP(), TeExportPolygonSet2SHP(), TeExportQuerierToShapefile(), TeExportShapefile(), TeImportDBFIndexes(), TeImportDBFTable(), TeImportShape(), TeReadDBFAttributeList(), TeReadDBFAttributes(), TeReadSHPAttributes(), and TeSTOSetBuildSHP().
00449 { 00450 /* -------------------------------------------------------------------- */ 00451 /* Write out header if not already written. */ 00452 /* -------------------------------------------------------------------- */ 00453 if( psDBF->bNoHeader ) 00454 DBFWriteHeader( psDBF ); 00455 00456 DBFFlushRecord( psDBF ); 00457 00458 /* -------------------------------------------------------------------- */ 00459 /* Update last access date, and number of records if we have */ 00460 /* write access. */ 00461 /* -------------------------------------------------------------------- */ 00462 if( psDBF->bUpdated ) 00463 { 00464 unsigned char abyFileHeader[32]; 00465 00466 fseek( psDBF->fp, 0, 0 ); 00467 fread( abyFileHeader, 32, 1, psDBF->fp ); 00468 00469 abyFileHeader[1] = 95; /* YY */ 00470 abyFileHeader[2] = 7; /* MM */ 00471 abyFileHeader[3] = 26; /* DD */ 00472 00473 abyFileHeader[4] = psDBF->nRecords % 256; 00474 abyFileHeader[5] = (psDBF->nRecords/256) % 256; 00475 abyFileHeader[6] = (psDBF->nRecords/(256*256)) % 256; 00476 abyFileHeader[7] = (psDBF->nRecords/(256*256*256)) % 256; 00477 00478 fseek( psDBF->fp, 0, 0 ); 00479 fwrite( abyFileHeader, 32, 1, psDBF->fp ); 00480 } 00481 00482 /* -------------------------------------------------------------------- */ 00483 /* Close, and free resources. */ 00484 /* -------------------------------------------------------------------- */ 00485 fclose( psDBF->fp ); 00486 00487 if( psDBF->panFieldOffset != NULL ) 00488 { 00489 free( psDBF->panFieldOffset ); 00490 free( psDBF->panFieldSize ); 00491 free( psDBF->panFieldDecimals ); 00492 free( psDBF->pachFieldType ); 00493 } 00494 00495 free( psDBF->pszHeader ); 00496 free( psDBF->pszCurrentRecord ); 00497 00498 free( psDBF ); 00499 00500 if( pszStringField != NULL ) 00501 { 00502 free( pszStringField ); 00503 pszStringField = NULL; 00504 nStringFieldLen = 0; 00505 } 00506 }
| DBFHandle SHPAPI_CALL DBFCreate | ( | const char * | pszFilename | ) |
Definition at line 515 of file dbfopen.c.
Referenced by DBFCloneEmpty(), exportPS2SHP(), TeCreateDBFFile(), and TeExportShapefile().
00517 { 00518 DBFHandle psDBF; 00519 FILE *fp; 00520 char *pszFullname, *pszBasename; 00521 int i; 00522 00523 /* -------------------------------------------------------------------- */ 00524 /* Compute the base (layer) name. If there is any extension */ 00525 /* on the passed in filename we will strip it off. */ 00526 /* -------------------------------------------------------------------- */ 00527 pszBasename = (char *) malloc(strlen(pszFilename)+5); 00528 strcpy( pszBasename, pszFilename ); 00529 for( i = strlen(pszBasename)-1; 00530 i > 0 && pszBasename[i] != '.' && pszBasename[i] != '/' 00531 && pszBasename[i] != '\\'; 00532 i-- ) {} 00533 00534 if( pszBasename[i] == '.' ) 00535 pszBasename[i] = '\0'; 00536 00537 pszFullname = (char *) malloc(strlen(pszBasename) + 5); 00538 sprintf( pszFullname, "%s.dbf", pszBasename ); 00539 free( pszBasename ); 00540 00541 /* -------------------------------------------------------------------- */ 00542 /* Create the file. */ 00543 /* -------------------------------------------------------------------- */ 00544 fp = fopen( pszFullname, "wb" ); 00545 if( fp == NULL ) 00546 return( NULL ); 00547 00548 fputc( 0, fp ); 00549 fclose( fp ); 00550 00551 fp = fopen( pszFullname, "rb+" ); 00552 if( fp == NULL ) 00553 return( NULL ); 00554 00555 free( pszFullname ); 00556 00557 /* -------------------------------------------------------------------- */ 00558 /* Create the info structure. */ 00559 /* -------------------------------------------------------------------- */ 00560 psDBF = (DBFHandle) malloc(sizeof(DBFInfo)); 00561 00562 psDBF->fp = fp; 00563 psDBF->nRecords = 0; 00564 psDBF->nFields = 0; 00565 psDBF->nRecordLength = 1; 00566 psDBF->nHeaderLength = 33; 00567 00568 psDBF->panFieldOffset = NULL; 00569 psDBF->panFieldSize = NULL; 00570 psDBF->panFieldDecimals = NULL; 00571 psDBF->pachFieldType = NULL; 00572 psDBF->pszHeader = NULL; 00573 00574 psDBF->nCurrentRecord = -1; 00575 psDBF->bCurrentRecordModified = FALSE; 00576 psDBF->pszCurrentRecord = NULL; 00577 00578 psDBF->bNoHeader = TRUE; 00579 00580 return( psDBF ); 00581 }
| static void DBFFlushRecord | ( | DBFHandle | psDBF | ) | [static] |
Definition at line 287 of file dbfopen.c.
References DBFInfo::bCurrentRecordModified, FALSE, DBFInfo::fp, fseek(), DBFInfo::nCurrentRecord, DBFInfo::nHeaderLength, DBFInfo::nRecordLength, and DBFInfo::pszCurrentRecord.
Referenced by DBFClose(), DBFReadAttribute(), DBFWriteAttribute(), DBFWriteAttributeDirectly(), DBFWriteTuple(), and if().
00289 { 00290 int nRecordOffset; 00291 00292 if( psDBF->bCurrentRecordModified && psDBF->nCurrentRecord > -1 ) 00293 { 00294 psDBF->bCurrentRecordModified = FALSE; 00295 00296 nRecordOffset = psDBF->nRecordLength * psDBF->nCurrentRecord 00297 + psDBF->nHeaderLength; 00298 00299 fseek( psDBF->fp, nRecordOffset, 0 ); 00300 fwrite( psDBF->pszCurrentRecord, psDBF->nRecordLength, 1, psDBF->fp ); 00301 } 00302 }
| int SHPAPI_CALL DBFGetFieldCount | ( | DBFHandle | psDBF | ) |
Definition at line 930 of file dbfopen.c.
Referenced by DBFGetFieldIndex(), TeShapefileDriver::loadData(), TeQuerierSHP::loadInstances(), TeDBFRowDecode(), TeImportDBFIndexes(), TeImportDBFTable(), TeReadDBFAttributeList(), TeReadDBFAttributes(), TeReadSHPAttributes(), and TeSTOSetBuildSHP().
00932 { 00933 return( psDBF->nFields ); 00934 }
| int SHPAPI_CALL DBFGetFieldIndex | ( | DBFHandle | psDBF, | |
| const char * | pszFieldName | |||
| ) |
Definition at line 1519 of file dbfopen.c.
01521 { 01522 char name[12], name1[12], name2[12]; 01523 int i; 01524 01525 strncpy(name1, pszFieldName,11); 01526 name1[11] = '\0'; 01527 str_to_upper(name1); 01528 01529 for( i = 0; i < DBFGetFieldCount(psDBF); i++ ) 01530 { 01531 DBFGetFieldInfo( psDBF, i, name, NULL, NULL ); 01532 strncpy(name2,name,11); 01533 str_to_upper(name2); 01534 01535 if(!strncmp(name1,name2,10)) 01536 return(i); 01537 } 01538 return(-1); 01539 }
| DBFFieldType SHPAPI_CALL DBFGetFieldInfo | ( | DBFHandle | psDBF, | |
| int | iField, | |||
| char * | pszFieldName, | |||
| int * | pnWidth, | |||
| int * | pnDecimals | |||
| ) |
Definition at line 956 of file dbfopen.c.
Referenced by DBFGetFieldIndex(), TeDBFRowDecode(), and TeReadDBFAttributeList().
00959 { 00960 if( iField < 0 || iField >= psDBF->nFields ) 00961 return( FTInvalid ); 00962 00963 if( pnWidth != NULL ) 00964 *pnWidth = psDBF->panFieldSize[iField]; 00965 00966 if( pnDecimals != NULL ) 00967 *pnDecimals = psDBF->panFieldDecimals[iField]; 00968 00969 if( pszFieldName != NULL ) 00970 { 00971 int i; 00972 00973 strncpy( pszFieldName, (char *) psDBF->pszHeader+iField*32, 11 ); 00974 pszFieldName[11] = '\0'; 00975 for( i = 10; i > 0 && pszFieldName[i] == ' '; i-- ) 00976 pszFieldName[i] = '\0'; 00977 } 00978 00979 if ( psDBF->pachFieldType[iField] == 'L' ) 00980 return( FTLogical); 00981 else if ( psDBF->pachFieldType[iField] == 'D') 00982 return (FTDate); 00983 else if( psDBF->pachFieldType[iField] == 'N' || psDBF->pachFieldType[iField] == 'F') 00984 { 00985 if( psDBF->panFieldDecimals[iField] > 0 ) 00986 return( FTDouble ); 00987 else 00988 return( FTInteger ); 00989 } 00990 else 00991 { 00992 return( FTString ); 00993 } 00994 }
| char SHPAPI_CALL DBFGetNativeFieldType | ( | DBFHandle | psDBF, | |
| int | iField | |||
| ) |
Definition at line 1485 of file dbfopen.c.
01487 { 01488 if( iField >=0 && iField < psDBF->nFields ) 01489 return psDBF->pachFieldType[iField]; 01490 01491 return ' '; 01492 }
| int SHPAPI_CALL DBFGetRecordCount | ( | DBFHandle | psDBF | ) |
Definition at line 943 of file dbfopen.c.
Referenced by TeExportShapefile(), TeImportDBFTable(), TeReadDBFAttributes(), and TeReadSHPAttributes().
00945 { 00946 return( psDBF->nRecords ); 00947 }
| int SHPAPI_CALL DBFIsAttributeNULL | ( | DBFHandle | psDBF, | |
| int | iRecord, | |||
| int | iField | |||
| ) |
Definition at line 895 of file dbfopen.c.
References DBFReadStringAttribute(), and DBFInfo::pachFieldType.
Referenced by TeDBFRowDecode().
00897 { 00898 const char *pszValue; 00899 00900 pszValue = DBFReadStringAttribute( psDBF, iRecord, iField ); 00901 00902 switch(psDBF->pachFieldType[iField]) 00903 { 00904 case 'N': 00905 case 'F': 00906 /* NULL numeric fields have value "****************" */ 00907 return pszValue[0] == '*'; 00908 00909 case 'D': 00910 /* NULL date fields have value "00000000" */ 00911 return strncmp(pszValue,"00000000",8) == 0; 00912 00913 case 'L': 00914 /* NULL boolean fields have value "?" */ 00915 return pszValue[0] == '?'; 00916 00917 default: 00918 /* empty string fields are considered NULL */ 00919 return strlen(pszValue) == 0; 00920 } 00921 }
| DBFHandle SHPAPI_CALL DBFOpen | ( | const char * | pszFilename, | |
| const char * | pszAccess | |||
| ) |
Definition at line 311 of file dbfopen.c.
Referenced by DBFCloneEmpty(), TeQuerierSHP::loadInstances(), TeImportDBFIndexes(), TeImportDBFTable(), TeImportShape(), TeImportShapeGeometry(), TeReadDBFAttributeList(), TeReadDBFAttributes(), TeReadSHPAttributes(), TeShapefileDriver::TeShapefileDriver(), and TeSTOSetBuildSHP().
00313 { 00314 DBFHandle psDBF; 00315 unsigned char *pabyBuf; 00316 int nFields, nHeadLen, nRecLen, iField, i; 00317 char *pszBasename, *pszFullname; 00318 00319 /* -------------------------------------------------------------------- */ 00320 /* We only allow the access strings "rb" and "r+". */ 00321 /* -------------------------------------------------------------------- */ 00322 if( strcmp(pszAccess,"r") != 0 && strcmp(pszAccess,"r+") != 0 00323 && strcmp(pszAccess,"rb") != 0 && strcmp(pszAccess,"rb+") != 0 00324 && strcmp(pszAccess,"r+b") != 0 ) 00325 return( NULL ); 00326 00327 if( strcmp(pszAccess,"r") == 0 ) 00328 pszAccess = "rb"; 00329 00330 if( strcmp(pszAccess,"r+") == 0 ) 00331 pszAccess = "rb+"; 00332 00333 /* -------------------------------------------------------------------- */ 00334 /* Compute the base (layer) name. If there is any extension */ 00335 /* on the passed in filename we will strip it off. */ 00336 /* -------------------------------------------------------------------- */ 00337 pszBasename = (char *) malloc(strlen(pszFilename)+5); 00338 strcpy( pszBasename, pszFilename ); 00339 for( i = strlen(pszBasename)-1; 00340 i > 0 && pszBasename[i] != '.' && pszBasename[i] != '/' 00341 && pszBasename[i] != '\\'; 00342 i-- ) {} 00343 00344 if( pszBasename[i] == '.' ) 00345 pszBasename[i] = '\0'; 00346 00347 pszFullname = (char *) malloc(strlen(pszBasename) + 5); 00348 sprintf( pszFullname, "%s.dbf", pszBasename ); 00349 00350 psDBF = (DBFHandle) calloc( 1, sizeof(DBFInfo) ); 00351 psDBF->fp = fopen( pszFullname, pszAccess ); 00352 00353 if( psDBF->fp == NULL ) 00354 { 00355 sprintf( pszFullname, "%s.DBF", pszBasename ); 00356 psDBF->fp = fopen(pszFullname, pszAccess ); 00357 } 00358 00359 free( pszBasename ); 00360 free( pszFullname ); 00361 00362 if( psDBF->fp == NULL ) 00363 { 00364 free( psDBF ); 00365 return( NULL ); 00366 } 00367 00368 psDBF->bNoHeader = FALSE; 00369 psDBF->nCurrentRecord = -1; 00370 psDBF->bCurrentRecordModified = FALSE; 00371 00372 /* -------------------------------------------------------------------- */ 00373 /* Read Table Header info */ 00374 /* -------------------------------------------------------------------- */ 00375 pabyBuf = (unsigned char *) malloc(500); 00376 if( fread( pabyBuf, 32, 1, psDBF->fp ) != 1 ) 00377 { 00378 fclose( psDBF->fp ); 00379 free( pabyBuf ); 00380 free( psDBF ); 00381 return NULL; 00382 } 00383 00384 psDBF->nRecords = 00385 pabyBuf[4] + pabyBuf[5]*256 + pabyBuf[6]*256*256 + pabyBuf[7]*256*256*256; 00386 00387 psDBF->nHeaderLength = nHeadLen = pabyBuf[8] + pabyBuf[9]*256; 00388 psDBF->nRecordLength = nRecLen = pabyBuf[10] + pabyBuf[11]*256; 00389 00390 psDBF->nFields = nFields = (nHeadLen - 32) / 32; 00391 00392 psDBF->pszCurrentRecord = (char *) malloc(nRecLen); 00393 00394 /* -------------------------------------------------------------------- */ 00395 /* Read in Field Definitions */ 00396 /* -------------------------------------------------------------------- */ 00397 00398 pabyBuf = (unsigned char *) SfRealloc(pabyBuf,nHeadLen); 00399 psDBF->pszHeader = (char *) pabyBuf; 00400 00401 fseek( psDBF->fp, 32, 0 ); 00402 if( fread( pabyBuf, nHeadLen-32, 1, psDBF->fp ) != 1 ) 00403 { 00404 fclose( psDBF->fp ); 00405 free( pabyBuf ); 00406 free( psDBF ); 00407 return NULL; 00408 } 00409 00410 psDBF->panFieldOffset = (int *) malloc(sizeof(int) * nFields); 00411 psDBF->panFieldSize = (int *) malloc(sizeof(int) * nFields); 00412 psDBF->panFieldDecimals = (int *) malloc(sizeof(int) * nFields); 00413 psDBF->pachFieldType = (char *) malloc(sizeof(char) * nFields); 00414 00415 for( iField = 0; iField < nFields; iField++ ) 00416 { 00417 unsigned char *pabyFInfo; 00418 00419 pabyFInfo = pabyBuf+iField*32; 00420 00421 if( pabyFInfo[11] == 'N' || pabyFInfo[11] == 'F' ) 00422 { 00423 psDBF->panFieldSize[iField] = pabyFInfo[16]; 00424 psDBF->panFieldDecimals[iField] = pabyFInfo[17]; 00425 } 00426 else 00427 { 00428 psDBF->panFieldSize[iField] = pabyFInfo[16] + pabyFInfo[17]*256; 00429 psDBF->panFieldDecimals[iField] = 0; 00430 } 00431 00432 psDBF->pachFieldType[iField] = (char) pabyFInfo[11]; 00433 if( iField == 0 ) 00434 psDBF->panFieldOffset[iField] = 1; 00435 else 00436 psDBF->panFieldOffset[iField] = 00437 psDBF->panFieldOffset[iField-1] + psDBF->panFieldSize[iField-1]; 00438 } 00439 00440 return( psDBF ); 00441 }
| static void* DBFReadAttribute | ( | DBFHandle | psDBF, | |
| int | hEntity, | |||
| int | iField, | |||
| char | chReqType | |||
| ) | [static] |
Definition at line 699 of file dbfopen.c.
References DBFFlushRecord(), DBFInfo::fp, fread(), fseek(), DBFInfo::nCurrentRecord, DBFInfo::nFields, DBFInfo::nHeaderLength, DBFInfo::nRecordLength, DBFInfo::nRecords, nStringFieldLen, NULL, pabyRec, DBFInfo::panFieldOffset, DBFInfo::panFieldSize, DBFInfo::pszCurrentRecord, pszStringField, and SfRealloc().
Referenced by DBFReadDoubleAttribute(), and DBFReadIntegerAttribute().
00702 { 00703 int nRecordOffset; 00704 unsigned char *pabyRec; 00705 void *pReturnField = NULL; 00706 00707 static double dDoubleField; 00708 00709 /* -------------------------------------------------------------------- */ 00710 /* Verify selection. */ 00711 /* -------------------------------------------------------------------- */ 00712 if( hEntity < 0 || hEntity >= psDBF->nRecords ) 00713 return( NULL ); 00714 00715 if( iField < 0 || iField >= psDBF->nFields ) 00716 return( NULL ); 00717 00718 /* -------------------------------------------------------------------- */ 00719 /* Have we read the record? */ 00720 /* -------------------------------------------------------------------- */ 00721 if( psDBF->nCurrentRecord != hEntity ) 00722 { 00723 DBFFlushRecord( psDBF ); 00724 00725 nRecordOffset = psDBF->nRecordLength * hEntity + psDBF->nHeaderLength; 00726 00727 if( fseek( psDBF->fp, nRecordOffset, 0 ) != 0 ) 00728 { 00729 fprintf( stderr, "fseek(%d) failed on DBF file.\n", 00730 nRecordOffset ); 00731 return NULL; 00732 } 00733 00734 if( fread( psDBF->pszCurrentRecord, psDBF->nRecordLength, 00735 1, psDBF->fp ) != 1 ) 00736 { 00737 fprintf( stderr, "fread(%d) failed on DBF file.\n", 00738 psDBF->nRecordLength ); 00739 return NULL; 00740 } 00741 00742 psDBF->nCurrentRecord = hEntity; 00743 } 00744 00745 pabyRec = (unsigned char *) psDBF->pszCurrentRecord; 00746 00747 /* -------------------------------------------------------------------- */ 00748 /* Ensure our field buffer is large enough to hold this buffer. */ 00749 /* -------------------------------------------------------------------- */ 00750 if( psDBF->panFieldSize[iField]+1 > nStringFieldLen ) 00751 { 00752 nStringFieldLen = psDBF->panFieldSize[iField]*2 + 10; 00753 pszStringField = (char *) SfRealloc(pszStringField,nStringFieldLen); 00754 } 00755 00756 /* -------------------------------------------------------------------- */ 00757 /* Extract the requested field. */ 00758 /* -------------------------------------------------------------------- */ 00759 strncpy( pszStringField, 00760 ((const char *) pabyRec) + psDBF->panFieldOffset[iField], 00761 psDBF->panFieldSize[iField] ); 00762 pszStringField[psDBF->panFieldSize[iField]] = '\0'; 00763 00764 pReturnField = pszStringField; 00765 00766 /* -------------------------------------------------------------------- */ 00767 /* Decode the field. */ 00768 /* -------------------------------------------------------------------- */ 00769 if( chReqType == 'D' ) 00770 { 00771 char dateField[11]; 00772 sprintf(dateField,"%4s/%2s/%2s",pszStringField,pszStringField+4,pszStringField+6); 00773 dateField[10] = '\0'; 00774 pReturnField = dateField; 00775 } 00776 else if( chReqType == 'N' ) 00777 { 00778 dDoubleField = atof(pszStringField); 00779 00780 pReturnField = &dDoubleField; 00781 } 00782 00783 /* -------------------------------------------------------------------- */ 00784 /* Should we trim white space off the string attribute value? */ 00785 /* -------------------------------------------------------------------- */ 00786 #ifdef TRIM_DBF_WHITESPACE 00787 else 00788 { 00789 char *pchSrc, *pchDst; 00790 00791 pchDst = pchSrc = pszStringField; 00792 while( *pchSrc == ' ' ) 00793 pchSrc++; 00794 00795 while( *pchSrc != '\0' ) 00796 *(pchDst++) = *(pchSrc++); 00797 *pchDst = '\0'; 00798 00799 while( pchDst != pszStringField && *(--pchDst) == ' ' ) 00800 *pchDst = '\0'; 00801 } 00802 #endif 00803 00804 return( pReturnField ); 00805 }
| const char SHPAPI_CALL1* DBFReadDateAttribute | ( | DBFHandle | psDBF, | |
| int | iRecord, | |||
| int | iField | |||
| ) | const |
| double SHPAPI_CALL DBFReadDoubleAttribute | ( | DBFHandle | psDBF, | |
| int | iRecord, | |||
| int | iField | |||
| ) |
Definition at line 834 of file dbfopen.c.
00836 { 00837 double *pdValue; 00838 00839 pdValue = (double *) DBFReadAttribute( psDBF, iRecord, iField, 'N' ); 00840 00841 if( pdValue == NULL ) 00842 return 0.0; 00843 else 00844 return( *pdValue ); 00845 }
| int SHPAPI_CALL DBFReadIntegerAttribute | ( | DBFHandle | psDBF, | |
| int | iRecord, | |||
| int | iField | |||
| ) |
Definition at line 814 of file dbfopen.c.
00816 { 00817 double *pdValue; 00818 00819 pdValue = (double *) DBFReadAttribute( psDBF, iRecord, iField, 'N' ); 00820 00821 if( pdValue == NULL ) 00822 return 0; 00823 else 00824 return( (int) *pdValue ); 00825 }
| const char SHPAPI_CALL1* DBFReadLogicalAttribute | ( | DBFHandle | psDBF, | |
| int | iRecord, | |||
| int | iField | |||
| ) | const |
| const char SHPAPI_CALL1* DBFReadStringAttribute | ( | DBFHandle | psDBF, | |
| int | iRecord, | |||
| int | iField | |||
| ) | const |
| const char SHPAPI_CALL1* DBFReadTuple | ( | DBFHandle | psDBF, | |
| int | hEntity | |||
| ) |
| static int DBFWriteAttribute | ( | DBFHandle | psDBF, | |
| int | hEntity, | |||
| int | iField, | |||
| void * | pValue | |||
| ) | [static] |
Definition at line 1002 of file dbfopen.c.
References DBFInfo::bCurrentRecordModified, DBFInfo::bNoHeader, DBFInfo::bUpdated, DBFFlushRecord(), DBFWriteHeader(), FALSE, DBFInfo::fp, fread(), fseek(), DBFInfo::nCurrentRecord, DBFInfo::nHeaderLength, DBFInfo::nRecordLength, DBFInfo::nRecords, NULL, pabyRec, DBFInfo::pachFieldType, DBFInfo::panFieldDecimals, DBFInfo::panFieldOffset, DBFInfo::panFieldSize, DBFInfo::pszCurrentRecord, and TRUE.
Referenced by DBFWriteDateAttribute(), DBFWriteDoubleAttribute(), DBFWriteIntegerAttribute(), DBFWriteLogicalAttribute(), DBFWriteNULLAttribute(), and DBFWriteStringAttribute().
01005 { 01006 int nRecordOffset, i, j, nRetResult = TRUE; 01007 unsigned char *pabyRec; 01008 char szSField[400], szFormat[20]; 01009 01010 /* -------------------------------------------------------------------- */ 01011 /* Is this a valid record? */ 01012 /* -------------------------------------------------------------------- */ 01013 if( hEntity < 0 || hEntity > psDBF->nRecords ) 01014 return( FALSE ); 01015 01016 if( psDBF->bNoHeader ) 01017 DBFWriteHeader(psDBF); 01018 01019 /* -------------------------------------------------------------------- */ 01020 /* Is this a brand new record? */ 01021 /* -------------------------------------------------------------------- */ 01022 if( hEntity == psDBF->nRecords ) 01023 { 01024 DBFFlushRecord( psDBF ); 01025 01026 psDBF->nRecords++; 01027 for( i = 0; i < psDBF->nRecordLength; i++ ) 01028 psDBF->pszCurrentRecord[i] = ' '; 01029 01030 psDBF->nCurrentRecord = hEntity; 01031 } 01032 01033 /* -------------------------------------------------------------------- */ 01034 /* Is this an existing record, but different than the last one */ 01035 /* we accessed? */ 01036 /* -------------------------------------------------------------------- */ 01037 if( psDBF->nCurrentRecord != hEntity ) 01038 { 01039 DBFFlushRecord( psDBF ); 01040 01041 nRecordOffset = psDBF->nRecordLength * hEntity + psDBF->nHeaderLength; 01042 01043 fseek( psDBF->fp, nRecordOffset, 0 ); 01044 fread( psDBF->pszCurrentRecord, psDBF->nRecordLength, 1, psDBF->fp ); 01045 01046 psDBF->nCurrentRecord = hEntity; 01047 } 01048 01049 pabyRec = (unsigned char *) psDBF->pszCurrentRecord; 01050 01051 psDBF->bCurrentRecordModified = TRUE; 01052 psDBF->bUpdated = TRUE; 01053 01054 /* -------------------------------------------------------------------- */ 01055 /* Translate NULL value to valid DBF file representation. */ 01056 /* */ 01057 /* Contributed by Jim Matthews. */ 01058 /* -------------------------------------------------------------------- */ 01059 if( pValue == NULL ) 01060 { 01061 switch(psDBF->pachFieldType[iField]) 01062 { 01063 case 'N': 01064 case 'F': 01065 /* NULL numeric fields have value "****************" */ 01066 memset( (char *) (pabyRec+psDBF->panFieldOffset[iField]), '*', 01067 psDBF->panFieldSize[iField] ); 01068 break; 01069 01070 case 'D': 01071 /* NULL date fields have value "00000000" */ 01072 memset( (char *) (pabyRec+psDBF->panFieldOffset[iField]), '0', 01073 psDBF->panFieldSize[iField] ); 01074 break; 01075 01076 case 'L': 01077 /* NULL boolean fields have value "?" */ 01078 memset( (char *) (pabyRec+psDBF->panFieldOffset[iField]), '?', 01079 psDBF->panFieldSize[iField] ); 01080 break; 01081 01082 default: 01083 /* empty string fields are considered NULL */ 01084 memset( (char *) (pabyRec+psDBF->panFieldOffset[iField]), '\0', 01085 psDBF->panFieldSize[iField] ); 01086 break; 01087 } 01088 return TRUE; 01089 } 01090 01091 /* -------------------------------------------------------------------- */ 01092 /* Assign all the record fields. */ 01093 /* -------------------------------------------------------------------- */ 01094 switch( psDBF->pachFieldType[iField] ) 01095 { 01096 case 'N': 01097 case 'F': 01098 if( psDBF->panFieldDecimals[iField] == 0 ) 01099 { 01100 int nWidth = psDBF->panFieldSize[iField]; 01101 01102 if( sizeof(szSField)-2 < (unsigned int)nWidth ) 01103 nWidth = sizeof(szSField)-2; 01104 01105 sprintf( szFormat, "%%%dd", nWidth ); 01106 sprintf(szSField, szFormat, (int) *((double *) pValue) ); 01107 if( (int)strlen(szSField) > psDBF->panFieldSize[iField] ) 01108 { 01109 szSField[psDBF->panFieldSize[iField]] = '\0'; 01110 nRetResult = FALSE; 01111 } 01112 01113 strncpy((char *) (pabyRec+psDBF->panFieldOffset[iField]), 01114 szSField, strlen(szSField) ); 01115 } 01116 else 01117 { 01118 int nWidth = psDBF->panFieldSize[iField]; 01119 01120 if( sizeof(szSField)-2 < (unsigned int)nWidth ) 01121 nWidth = sizeof(szSField)-2; 01122 01123 sprintf( szFormat, "%%%d.%df", 01124 nWidth, psDBF->panFieldDecimals[iField] ); 01125 sprintf(szSField, szFormat, *((double *) pValue) ); 01126 if( (int) strlen(szSField) > psDBF->panFieldSize[iField] ) 01127 { 01128 szSField[psDBF->panFieldSize[iField]] = '\0'; 01129 nRetResult = FALSE; 01130 } 01131 strncpy((char *) (pabyRec+psDBF->panFieldOffset[iField]), 01132 szSField, strlen(szSField) ); 01133 } 01134 break; 01135 01136 case 'L': 01137 if (psDBF->panFieldSize[iField] >= 1 && 01138 (*(char*)pValue == 'F' || *(char*)pValue == 'T')) 01139 *(pabyRec+psDBF->panFieldOffset[iField]) = *(char*)pValue; 01140 break; 01141 01142 default: 01143 if( (int) strlen((char *) pValue) > psDBF->panFieldSize[iField] ) 01144 { 01145 j = psDBF->panFieldSize[iField]; 01146 nRetResult = FALSE; 01147 } 01148 else 01149 { 01150 memset( pabyRec+psDBF->panFieldOffset[iField], ' ', 01151 psDBF->panFieldSize[iField] ); 01152 j = strlen((char *) pValue); 01153 } 01154 01155 strncpy((char *) (pabyRec+psDBF->panFieldOffset[iField]),(char *) pValue, j ); 01156 break; 01157 } 01158 01159 return( nRetResult ); 01160 }
| int DBFWriteAttributeDirectly | ( | DBFHandle | psDBF, | |
| int | hEntity, | |||
| int | iField, | |||
| void * | pValue | |||
| ) |
Definition at line 1170 of file dbfopen.c.
01173 { 01174 int nRecordOffset, i, j; 01175 unsigned char *pabyRec; 01176 01177 /* -------------------------------------------------------------------- */ 01178 /* Is this a valid record? */ 01179 /* -------------------------------------------------------------------- */ 01180 if( hEntity < 0 || hEntity > psDBF->nRecords ) 01181 return( FALSE ); 01182 01183 if( psDBF->bNoHeader ) 01184 DBFWriteHeader(psDBF); 01185 01186 /* -------------------------------------------------------------------- */ 01187 /* Is this a brand new record? */ 01188 /* -------------------------------------------------------------------- */ 01189 if( hEntity == psDBF->nRecords ) 01190 { 01191 DBFFlushRecord( psDBF ); 01192 01193 psDBF->nRecords++; 01194 for( i = 0; i < psDBF->nRecordLength; i++ ) 01195 psDBF->pszCurrentRecord[i] = ' '; 01196 01197 psDBF->nCurrentRecord = hEntity; 01198 } 01199 01200 /* -------------------------------------------------------------------- */ 01201 /* Is this an existing record, but different than the last one */ 01202 /* we accessed? */ 01203 /* -------------------------------------------------------------------- */ 01204 if( psDBF->nCurrentRecord != hEntity ) 01205 { 01206 DBFFlushRecord( psDBF ); 01207 01208 nRecordOffset = psDBF->nRecordLength * hEntity + psDBF->nHeaderLength; 01209 01210 fseek( psDBF->fp, nRecordOffset, 0 ); 01211 fread( psDBF->pszCurrentRecord, psDBF->nRecordLength, 1, psDBF->fp ); 01212 01213 psDBF->nCurrentRecord = hEntity; 01214 } 01215 01216 pabyRec = (unsigned char *) psDBF->pszCurrentRecord; 01217 01218 /* -------------------------------------------------------------------- */ 01219 /* Assign all the record fields. */ 01220 /* -------------------------------------------------------------------- */ 01221 if( (int)strlen((char *) pValue) > psDBF->panFieldSize[iField] ) 01222 j = psDBF->panFieldSize[iField]; 01223 else 01224 { 01225 memset( pabyRec+psDBF->panFieldOffset[iField], ' ', 01226 psDBF->panFieldSize[iField] ); 01227 j = strlen((char *) pValue); 01228 } 01229 01230 strncpy((char *) (pabyRec+psDBF->panFieldOffset[iField]), 01231 (char *) pValue, j ); 01232 01233 psDBF->bCurrentRecordModified = TRUE; 01234 psDBF->bUpdated = TRUE; 01235 01236 return( TRUE ); 01237 }
| int SHPAPI_CALL DBFWriteDateAttribute | ( | DBFHandle | psDBF, | |
| int | iRecord, | |||
| int | iField, | |||
| const char * | pszValue | |||
| ) |
Definition at line 1290 of file dbfopen.c.
01293 { 01294 return( DBFWriteAttribute( psDBF, iRecord, iField, (void *) pszValue ) ); 01295 }
| int SHPAPI_CALL DBFWriteDoubleAttribute | ( | DBFHandle | psDBF, | |
| int | iRecord, | |||
| int | iField, | |||
| double | dValue | |||
| ) |
Definition at line 1246 of file dbfopen.c.
Referenced by TeExportQuerierToShapefile(), and TeExportShapefile().
01249 { 01250 return( DBFWriteAttribute( psDBF, iRecord, iField, (void *) &dValue ) ); 01251 }
| static void DBFWriteHeader | ( | DBFHandle | psDBF | ) | [static] |
Definition at line 234 of file dbfopen.c.
References DBFInfo::bNoHeader, FALSE, DBFInfo::fp, fseek(), DBFInfo::nFields, DBFInfo::nHeaderLength, DBFInfo::nRecordLength, DBFInfo::pszHeader, and XBASE_FLDHDR_SZ.
Referenced by DBFCloneEmpty(), DBFClose(), DBFWriteAttribute(), DBFWriteAttributeDirectly(), and DBFWriteTuple().
00236 { 00237 unsigned char abyHeader[XBASE_FLDHDR_SZ]; 00238 int i; 00239 00240 if( !psDBF->bNoHeader ) 00241 return; 00242 00243 psDBF->bNoHeader = FALSE; 00244 00245 /* -------------------------------------------------------------------- */ 00246 /* Initialize the file header information. */ 00247 /* -------------------------------------------------------------------- */ 00248 for( i = 0; i < XBASE_FLDHDR_SZ; i++ ) 00249 abyHeader[i] = 0; 00250 00251 abyHeader[0] = 0x03; /* memo field? - just copying */ 00252 00253 /* date updated on close, record count preset at zero */ 00254 00255 abyHeader[8] = psDBF->nHeaderLength % 256; 00256 abyHeader[9] = psDBF->nHeaderLength / 256; 00257 00258 abyHeader[10] = psDBF->nRecordLength % 256; 00259 abyHeader[11] = psDBF->nRecordLength / 256; 00260 00261 /* -------------------------------------------------------------------- */ 00262 /* Write the initial 32 byte file header, and all the field */ 00263 /* descriptions. */ 00264 /* -------------------------------------------------------------------- */ 00265 fseek( psDBF->fp, 0, 0 ); 00266 fwrite( abyHeader, XBASE_FLDHDR_SZ, 1, psDBF->fp ); 00267 fwrite( psDBF->pszHeader, XBASE_FLDHDR_SZ, psDBF->nFields, psDBF->fp ); 00268 00269 /* -------------------------------------------------------------------- */ 00270 /* Write out the newline character if there is room for it. */ 00271 /* -------------------------------------------------------------------- */ 00272 if( psDBF->nHeaderLength > 32*psDBF->nFields + 32 ) 00273 { 00274 char cNewline; 00275 00276 cNewline = 0x0d; 00277 fwrite( &cNewline, 1, 1, psDBF->fp ); 00278 } 00279 }
| int SHPAPI_CALL DBFWriteIntegerAttribute | ( | DBFHandle | psDBF, | |
| int | iRecord, | |||
| int | iField, | |||
| int | nValue | |||
| ) |
Definition at line 1260 of file dbfopen.c.
Referenced by TeExportQuerierToShapefile(), and TeExportShapefile().
01263 { 01264 double dValue = nValue; 01265 01266 return( DBFWriteAttribute( psDBF, iRecord, iField, (void *) &dValue ) ); 01267 }
| int SHPAPI_CALL DBFWriteLogicalAttribute | ( | DBFHandle | psDBF, | |
| int | iRecord, | |||
| int | iField, | |||
| const char | lValue | |||
| ) |
Definition at line 1317 of file dbfopen.c.
01320 { 01321 return( DBFWriteAttribute( psDBF, iRecord, iField, (void *) (&lValue) ) ); 01322 }
| int SHPAPI_CALL DBFWriteNULLAttribute | ( | DBFHandle | psDBF, | |
| int | iRecord, | |||
| int | iField | |||
| ) |
Definition at line 1304 of file dbfopen.c.
01306 { 01307 return( DBFWriteAttribute( psDBF, iRecord, iField, NULL ) ); 01308 }
| int SHPAPI_CALL DBFWriteStringAttribute | ( | DBFHandle | psDBF, | |
| int | iRecord, | |||
| int | iField, | |||
| const char * | pszValue | |||
| ) |
Definition at line 1276 of file dbfopen.c.
Referenced by exportPS2SHP(), TeExportPolygonSet2SHP(), TeExportQuerierToShapefile(), and TeExportShapefile().
01279 { 01280 return( DBFWriteAttribute( psDBF, iRecord, iField, (void *) pszValue ) ); 01281 }
| int SHPAPI_CALL DBFWriteTuple | ( | DBFHandle | psDBF, | |
| int | hEntity, | |||
| void * | pRawTuple | |||
| ) |
Definition at line 1331 of file dbfopen.c.
References DBFInfo::bCurrentRecordModified, DBFInfo::bNoHeader, DBFInfo::bUpdated, DBFFlushRecord(), DBFWriteHeader(), FALSE, DBFInfo::fp, fread(), fseek(), memcpy(), DBFInfo::nCurrentRecord, DBFInfo::nHeaderLength, DBFInfo::nRecordLength, DBFInfo::nRecords, pabyRec, DBFInfo::pszCurrentRecord, and TRUE.
01333 { 01334 int nRecordOffset, i; 01335 unsigned char *pabyRec; 01336 01337 /* -------------------------------------------------------------------- */ 01338 /* Is this a valid record? */ 01339 /* -------------------------------------------------------------------- */ 01340 if( hEntity < 0 || hEntity > psDBF->nRecords ) 01341 return( FALSE ); 01342 01343 if( psDBF->bNoHeader ) 01344 DBFWriteHeader(psDBF); 01345 01346 /* -------------------------------------------------------------------- */ 01347 /* Is this a brand new record? */ 01348 /* -------------------------------------------------------------------- */ 01349 if( hEntity == psDBF->nRecords ) 01350 { 01351 DBFFlushRecord( psDBF ); 01352 01353 psDBF->nRecords++; 01354 for( i = 0; i < psDBF->nRecordLength; i++ ) 01355 psDBF->pszCurrentRecord[i] = ' '; 01356 01357 psDBF->nCurrentRecord = hEntity; 01358 } 01359 01360 /* -------------------------------------------------------------------- */ 01361 /* Is this an existing record, but different than the last one */ 01362 /* we accessed? */ 01363 /* -------------------------------------------------------------------- */ 01364 if( psDBF->nCurrentRecord != hEntity ) 01365 { 01366 DBFFlushRecord( psDBF ); 01367 01368 nRecordOffset = psDBF->nRecordLength * hEntity + psDBF->nHeaderLength; 01369 01370 fseek( psDBF->fp, nRecordOffset, 0 ); 01371 fread( psDBF->pszCurrentRecord, psDBF->nRecordLength, 1, psDBF->fp ); 01372 01373 psDBF->nCurrentRecord = hEntity; 01374 } 01375 01376 pabyRec = (unsigned char *) psDBF->pszCurrentRecord; 01377 01378 memcpy ( pabyRec, pRawTuple, psDBF->nRecordLength ); 01379 01380 psDBF->bCurrentRecordModified = TRUE; 01381 psDBF->bUpdated = TRUE; 01382 01383 return( TRUE ); 01384 }
| if | ( | nTupleLen< psDBF-> | nRecordLength | ) |
Definition at line 1422 of file dbfopen.c.
References SfRealloc().
01422 { 01423 nTupleLen = psDBF->nRecordLength; 01424 pReturnTuple = (char *) SfRealloc(pReturnTuple, psDBF->nRecordLength); 01425 }
| if | ( | psDBF->nCurrentRecord! | = hEntity |
) |
Definition at line 1408 of file dbfopen.c.
References DBFFlushRecord(), fread(), and fseek().
Referenced by TeLayer::addGeometry(), TeLayer::addRasterFileGeometry(), TeLayer::addRasterGeometry(), TeMySQL::columnExist(), TeCategoryPercentageStrategy< Iterator >::compute(), TeOCIOracle::deleteLayer(), TeSqlServer::deleteLayer(), TeOracle::deleteLayer(), ibpp_internals::RowImpl::GetValue(), GLOBAL(), TeDecoderVirtualMemory::loadBlock(), TeQtGrid::mouseReleasedOnVerticalHeaderSlot(), TeQtGrid::scrollToNextPointedObjectSlot(), TeQtGrid::scrollToNextQueriedObjectSlot(), TeQtGrid::scrollToPrevPointedObjectSlot(), TeQtGrid::scrollToPrevQueriedObjectSlot(), and TeQtGrid::update().
01409 { 01410 DBFFlushRecord( psDBF ); 01411 01412 nRecordOffset = psDBF->nRecordLength * hEntity + psDBF->nHeaderLength; 01413 01414 fseek( psDBF->fp, nRecordOffset, 0 ); 01415 fread( psDBF->pszCurrentRecord, psDBF->nRecordLength, 1, psDBF->fp ); 01416 01417 psDBF->nCurrentRecord = hEntity; 01418 }
| memcpy | ( | pReturnTuple | , | |
| pabyRec | , | |||
| psDBF-> | nRecordLength | |||
| ) |
Referenced by accessPayload(), allocateBtreePage(), allocateSpace(), appendText(), assemblePage(), attachFunc(), backupOnePage(), balance_deeper(), balance_nonroot(), buffer2TeRing(), change_target_buffer_size(), codeOneLoopStart(), copyNodeContent(), copyPayload(), createModule(), createTableStmt(), DBFCloneEmpty(), DBFWriteTuple(), decodeCoord(), TeWKBGeometryDecoder::decodePolygon(), defragmentPage(), displayP4(), do_meta_command(), dup8bytes(), TeWKBGeometryDecoder::encodeLine(), TeWKBGeometryDecoder::encodePoint(), TeWKBGeometryDecoder::encodePolygon(), encodeRing(), exprDup(), fillInCell(), find_home_dir(), findCollSeqEntry(), findCreateFileMode(), findInodeInfo(), fkActionTrigger(), freeSpace(), ibpp_internals::RowImpl::Get(), TeSQLitePortal::getBlob(), TeMySQLPortal::getBlob(), TeFirebirdPortal::getBlob(), TeAdoPortal::getBlob(), TePGRecordset::getBytea(), TePGRecordset::getDouble(), TeOCICursor::getFieldValue(), ibpp_internals::BlobImpl::GetId(), ibpp_internals::ArrayImpl::GetId(), TePGRecordset::getInt(), TePGRecordset::getInt8(), TePGRecordset::getPGLine2D(), TeMySQLPortal::getRasterBlock(), TeAdoPortal::getRasterBlock(), TePGRecordset::getTime(), TePGRecordset::getTimeStamp(), getWKBHeader(), TePGRecordset::getWKBHeader(), TePGRecordset::getWKBLinearRing(), TePGRecordset::getWKBPoint(), ibpp_internals::TPB::Grow(), ibpp_internals::SPB::Grow(), ibpp_internals::DPB::Grow(), ibpp_internals::IBS::IBS(), if(), TeAdo::insertBlob(), insertCell(), TePostgreSQL::insertLine(), TePostgreSQL::insertNode(), TePostgreSQL::insertPoint(), TePostgreSQL::insertPolygon(), TeAdo::insertRasterBlock(), TeSqlServer::insertTable(), TeAdo::insertTable(), main(), main_init(), memjrnlRead(), memjrnlWrite(), my_yyinput(), newDatabase(), openDatabase(), TeTime::operator=(), ibpp_internals::RowImpl::operator=(), pager_playback_one_page(), pager_write_pagelist(), TeAdo::PointsToVariant(), process_input(), TeSqlServerSpatial::PutBinaryIntoVariant(), TeOCICursor::readBlob(), readDbPage(), replaceFunc(), resolveAlias(), returnSingleInt(), save_err_msg(), ibpp_internals::BlobImpl::SetId(), ibpp_internals::ArrayImpl::SetId(), ibpp_internals::RowImpl::SetValue(), SHPOpen(), SHPWriteObject(), sqlite3_exec(), sqlite3_get_table_cb(), sqlite3_initialize(), sqlite3AlterBeginAddColumn(), sqlite3BitvecClear(), sqlite3BitvecSet(), sqlite3BtreeInsert(), sqlite3CreateForeignKey(), sqlite3CreateIndex(), sqlite3DbRealloc(), sqlite3DbStrDup(), sqlite3DbStrNDup(), sqlite3ExprAlloc(), sqlite3FindFunction(), sqlite3IsLikeFunction(), sqlite3LoadExtension(), sqlite3MutexInit(), sqlite3NestedParse(), sqlite3PagerOpen(), sqlite3ParseUri(), sqlite3PrngRestoreState(), sqlite3PrngSaveState(), sqlite3ResetInternalSchema(), sqlite3StrAccumAppend(), sqlite3StrAccumFinish(), sqlite3VdbeChangeP4(), sqlite3VdbeExec(), sqlite3VdbeMakeReady(), sqlite3VdbeMemCopy(), sqlite3VdbeMemFinalize(), sqlite3VdbeMemGrow(), sqlite3VdbeMemMove(), sqlite3VdbeMemSetStr(), sqlite3VdbeMemShallowCopy(), sqlite3VdbeSerialGet(), sqlite3VdbeSerialPut(), sqlite3VdbeSorterRowkey(), sqlite3VdbeSorterWrite(), sqlite3VtabOverloadFunction(), sqlite3WalFrames(), sqlite3WalUndo(), sqlite3WhereBegin(), swappd(), SwapUInt(), syncJournal(), synthCollSeq(), TeBoxToPGBinary(), TeConvertToBigEndian(), TeLine2DToPGBinary(), TeLine2DToWKBLineString(), TePGSwapUInt(), TePointToWKBPoint(), TePolygonToWKBPolygon(), TeTime::TeTime(), triggerStepAllocate(), unixRandomness(), TePostgreSQL::updateLine(), TePostgreSQL::updateNode(), TePostgreSQL::updatePoint(), TePostgreSQL::updatePolygon(), walEncodeFrame(), walIndexRecover(), walIndexTryHdr(), walIndexWriteHdr(), walMerge(), whereClauseInsert(), writeJournalHdr(), and yyparse().
| return | ( | pReturnTuple | ) |
| static void* SfRealloc | ( | void * | pMem, | |
| int | nNewSize | |||
| ) | [static] |
Definition at line 216 of file dbfopen.c.
References NULL.
Referenced by DBFAddField(), DBFOpen(), DBFReadAttribute(), if(), and SHPWriteObject().
00218 { 00219 if( pMem == NULL ) 00220 return( (void *) malloc(nNewSize) ); 00221 else 00222 return( (void *) realloc(pMem,nNewSize) ); 00223 }
| static void str_to_upper | ( | char * | string | ) | [static] |
Definition at line 1498 of file dbfopen.c.
Referenced by DBFGetFieldIndex().
01499 { 01500 int len; 01501 short i = -1; 01502 01503 len = strlen (string); 01504 01505 while (++i < len) 01506 if (isalpha(string[i]) && islower(string[i])) 01507 string[i] = toupper ((int)string[i]); 01508 }
int nStringFieldLen = 0 [static] |
| pabyRec = (unsigned char *) psDBF->pszCurrentRecord |
Definition at line 1420 of file dbfopen.c.
Referenced by DBFReadAttribute(), DBFWriteAttribute(), DBFWriteAttributeDirectly(), DBFWriteTuple(), and SHPWriteObject().
char* pszStringField = NULL [static] |
1.5.3