Skip to content
Permalink
Browse files

Shapelib: add a FTDate type to DBFFieldType (patch by Jerry Faust, fixes

 #308) + use it in the OGR Shapefile driver

git-svn-id: https://svn.osgeo.org/gdal/trunk@41554 f0d54148-0727-0410-94bb-9a71ac55c965
  • Loading branch information...
rouault committed Feb 24, 2018
1 parent 1077ec8 commit d2688e4fac19b91906d2f4b3f2ff35432b55721a
@@ -898,6 +898,8 @@ DBFAddField(DBFHandle psDBF, const char * pszFieldName,

if( eType == FTLogical )
chNativeType = 'L';
else if( eType == FTDate )
chNativeType = 'D';
else if( eType == FTString )
chNativeType = 'C';
else
@@ -1390,7 +1392,10 @@ DBFGetFieldInfo( DBFHandle psDBF, int iField, char * pszFieldName,
}

if ( psDBF->pachFieldType[iField] == 'L' )
return( FTLogical);
return( FTLogical );

else if( psDBF->pachFieldType[iField] == 'D' )
return( FTDate );

else if( psDBF->pachFieldType[iField] == 'N'
|| psDBF->pachFieldType[iField] == 'F' )
@@ -2289,7 +2294,7 @@ DBFAlterFieldDefn( DBFHandle psDBF, int iField, const char * pszFieldName,

if (nWidth != nOldWidth)
{
if ((chOldType == 'N' || chOldType == 'F') && pszOldField[0] == ' ')
if ((chOldType == 'N' || chOldType == 'F' || chOldType == 'D') && pszOldField[0] == ' ')
{
/* Strip leading spaces when truncating a numeric field */
memmove( pszRecord + nOffset,
@@ -1035,19 +1035,13 @@ OGRFeatureDefn *SHPReadOGRFeatureDefn( const char * pszName,
oField.SetWidth( nWidth );
oField.SetPrecision( nPrecision );

const char chNativeType = DBFGetNativeFieldType( hDBF, iField );
if( chNativeType == 'D' )
if( eDBFType == FTDate )
{
// TODO(mloskot): Shapefile date has following 8-chars long format:
// Shapefile date has following 8-chars long format:
//
// 20060101.
//
// Split as YYYY/MM/DD, so 2 additional characters are required.
//
// Is this a correct assumption? What about time part of date?
// Should this format look as datetime: YYYY/MM/DD HH:MM:SS with 4
// additional characters?

oField.SetWidth( nWidth + 2 );
oField.SetType( OFTDate );
}
@@ -501,6 +501,7 @@ typedef enum {
FTInteger,
FTDouble,
FTLogical,
FTDate,
FTInvalid
} DBFFieldType;

0 comments on commit d2688e4

Please sign in to comment.
You can’t perform that action at this time.