[Gdal-dev] DBF-Column type boolen and date?

Frank Warmerdam warmerdam at pobox.com
Mon Jun 19 08:50:11 EDT 2006


Markus Neteler wrote:
> Frank,
> 
> I was thinking moreover about the DATE support in the
> GRASS DBF driver:
> 
>  http://freegis.org/cgi-bin/viewcvs.cgi/grass6/db/drivers/dbf/globals.h?rev=HEAD&content-type=text/vnd.viewcvs-markup
> 
> Currently only FTString, FTInteger, FTDouble are used and
> date is mapped to char since FTDate isn't there (but was proposed
> by strk). That's why I brought up the issue here.
> 
> I am not sure how to change the GRASS DBF driver to better implement
> date support (mayeb there is nothing to change?). See line 313 in
> http://freegis.org/cgi-bin/viewcvs.cgi/grass6/db/drivers/dbf/dbfexe.c?annotate=1.36

Markus,

Some roughly comparable code is in ogrshapelayer.cpp.  As you can
see OFTDate is transferred using DBFAddNativeFieldType() instead of
the DBFAddField() so the specialized date type can be created.


/************************************************************************/
/*                            CreateField()                             */
/************************************************************************/

OGRErr OGRShapeLayer::CreateField( OGRFieldDefn *poField, int bApproxOK )

{
     int         iNewField;
     if( GetFeatureCount(TRUE) != 0 )
     {
         CPLError( CE_Failure, CPLE_NotSupported,
                   "Can't create fields on a Shapefile layer with features.\n");
         return OGRERR_FAILURE;
     }

     if( !bUpdateAccess )
     {
         CPLError( CE_Failure, CPLE_NotSupported,
                   "Can't create fields on a read-only shapefile layer.\n");
         return OGRERR_FAILURE;
     }

     if( poField->GetType() == OFTInteger )
     {
         if( poField->GetWidth() == 0 )
             iNewField =
                 DBFAddField( hDBF, poField->GetNameRef(), FTInteger, 11, 0 );
         else
             iNewField = DBFAddField( hDBF, poField->GetNameRef(), FTInteger,
                                      poField->GetWidth(), 0 );

         if( iNewField != -1 )
             poFeatureDefn->AddFieldDefn( poField );
     }
     else if( poField->GetType() == OFTReal )
     {
         if( poField->GetWidth() == 0 )
             iNewField =
                 DBFAddField( hDBF, poField->GetNameRef(), FTDouble, 24, 15 );
         else
             iNewField =
                 DBFAddField( hDBF, poField->GetNameRef(), FTDouble,
                              poField->GetWidth(), poField->GetPrecision() );

         if( iNewField != -1 )
             poFeatureDefn->AddFieldDefn( poField );
     }
     else if( poField->GetType() == OFTString )
     {
         if( poField->GetWidth() < 1 )
             iNewField =
                 DBFAddField( hDBF, poField->GetNameRef(), FTString, 80, 0 );
         else
             iNewField = DBFAddField( hDBF, poField->GetNameRef(), FTString,
                                      poField->GetWidth(), 0 );

         if( iNewField != -1 )
             poFeatureDefn->AddFieldDefn( poField );
     }
     else if( poField->GetType() == OFTDate )
     {
         iNewField =
             DBFAddNativeFieldType( hDBF, poField->GetNameRef(), 'D', 8, 0 );

         if( iNewField != -1 )
             poFeatureDefn->AddFieldDefn( poField );
     }
     else if( poField->GetType() == OFTDateTime )
     {
         CPLError( CE_Warning, CPLE_NotSupported,
                   "Field %s create as date field, though DateTime requested.\n",
                   poField->GetNameRef() );

         iNewField =
             DBFAddNativeFieldType( hDBF, poField->GetNameRef(), 'D', 8, 0 );

         if( iNewField != -1 )
             poFeatureDefn->AddFieldDefn( poField );
     }
     else
     {
         CPLError( CE_Failure, CPLE_NotSupported,
                   "Can't create fields of type %s on shapefile layers.\n",
                   OGRFieldDefn::GetFieldTypeName(poField->GetType()) );

         return OGRERR_FAILURE;
     }

     if( iNewField != -1 )
         return OGRERR_NONE;
     else
     {
         CPLError( CE_Failure, CPLE_AppDefined,
                   "Can't create field %s in Shape DBF file, reason unknown.\n",
                   poField->GetNameRef() );

         return OGRERR_FAILURE;
     }
}


-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | President OSGF, http://osgeo.org




More information about the Gdal-dev mailing list