Hello Daniel,

Many thanks for your reply. The code change works beautifully.  I will
paste at the bottom of this message the new code I am using.

I have a general question about compiling mitab, but it may not be
answerable. I was using cygwin originally to run mitab because I
couldn't get it to work with visual c++ express 2008, but when I needed
to use the debugger I couldn't get it (DDD) to run stable so I had to go
back to trying to use visual c++ express (which is why it has taken me
so long to test the new code).

I can get mitab to compile from the vc++ express command line but I
can't get it to compile in the ide. While trying to compile tabdump from
the command line I noticed I was getting the same error messages that I
was getting when trying to compile mitab in the ide. I get the following
error messages:

Note: ~1 = path to mitab folder on my computer

tabdump.cpp
tabdump.cpp(343) : error C2039: 'Dump' : is not a member of
'TABRawBinBlock'
         c:\~1\mitab-1.7.0_1\mitab-1.
7.0\mitab\mitab_priv.h(784) : see declaration of 'TABRawBinBlock'
tabdump.cpp(383) : error C2039: 'Dump' : is not a member of 'TABMAPFile'
         c:\~1\mitab-1.7.0_1\mitab-1.
7.0\mitab\mitab_priv.h(1305) : see declaration of 'TABMAPFile'
tabdump.cpp(458) : error C2039: 'DumpSpatialIndexToMIF' : is not a
member of 'TA
BMAPFile'
         c:\~1\mitab-1.7.0_1\mitab-1.
7.0\mitab\mitab_priv.h(1305) : see declaration of 'TABMAPFile'
tabdump.cpp(502) : error C2039: 'Dump' : is not a member of
'TABMAPObjectBlock'
         c:\~1\mitab-1.7.0_1\mitab-1.
7.0\mitab\mitab_priv.h(1062) : see declaration of 'TABMAPObjectBlock'
tabdump.cpp(505) : error C2039: 'Dump' : is not a member of
'TABRawBinBlock'
         c:\~1\mitab-1.7.0_1\mitab-1.
7.0\mitab\mitab_priv.h(784) : see declaration of 'TABRawBinBlock'
tabdump.cpp(541) : error C2039: 'Dump' : is not a member of
'IMapInfoFile'
         c:\~1\mitab-1.7.0_1\mitab-1.
7.0\mitab\mitab.h(234) : see declaration of 'IMapInfoFile'
tabdump.cpp(600) : error C2039: 'Dump' : is not a member of 'TABINDFile'
         c:\~1\mitab-1.7.0_1\mitab-1.
7.0\mitab\mitab_priv.h(1533) : see declaration of 'TABINDFile'
tabdump.cpp(864) : error C2039: 'Dump' : is not a member of
'IMapInfoFile'
         c:\~1\mitab-1.7.0_1\mitab-1.
7.0\mitab\mitab.h(234) : see declaration of 'IMapInfoFile'


I currently have all the programs running in visual c++ but I have to
switch to cygwin to run tabdump on files. Can you or anyone else tell me
if you know what might be causing the error messages when compiling
tabdump.exe ?

many thanks,

Anthony


NEW CODE

For anyone who is interested, this is the code I  added to have the new
field and update the features:

The test program is a modified tab2tab.cpp file, and the changes in red
are the new code.. the code in black is to show where in the original
tab2tab.cpp file I inserted the new code:

  for(iField=0; iField< poDefn->GetFieldCount(); iField++)
     {
         OGRFieldDefn *poFieldDefn = poDefn->GetFieldDefn(iField);

         poDstFile->AddFieldNative(poFieldDefn->GetNameRef(),
                                   poSrcFile->GetNativeFieldType(iField),
                                   poFieldDefn->GetWidth(),
                                   poFieldDefn->GetPrecision(),
                                   poSrcFile->IsFieldIndexed(iField),
                                   poSrcFile->IsFieldUnique(iField));
     }



     OGRFieldDefn *newfieldDefn = new OGRFieldDefn("Test", OFTReal);
     newfieldDefn->SetWidth(14);
     if(poDstFile->CreateField(newfieldDefn)!= OGRERR_NONE)
       {
     printf("Failed making new field");
     return -1;
       }


    
/*---------------------------------------------------------------------
      * Copy objects until EOF is reached
     
*--------------------------------------------------------------------*/
     nFeatureId = -1;
     while ( (nFeatureId = poSrcFile->GetNextFeatureId(nFeatureId)) != -1
&&
             (nMaxFeatures < 1 || numFeatures++ < nMaxFeatures ))
     {
         poFeature = poSrcFile->GetFeatureRef(nFeatureId);
     TABFeature *poDestFeature =
poFeature->CloneTABFeature(poDstFile->GetLayerDefn());
     for( int i = 0; i < poFeature->GetDefnRef()->GetFieldCount(); i++ )
       {
         poDestFeature->SetField( i, poFeature->GetRawFieldRef( i ) );
       }
     poDestFeature->SetField(3,888.777888);




         if (poDestFeature)
         {
             poDstFile->SetFeature(poDestFeature);
         }
         else
         {
             printf( "Failed to read feature %d.\n",
                     nFeatureId );
             return -1;      // GetFeatureRef() failed: Error
         }
     }














--- In [email protected], Daniel Morissette <dmorissette@...> wrote:
>
> Hi Anthony,
>
> That's a very good question. The reason for the error you got is (as I
> think you had figured out already) that the field definitions in the
> poFeature that comes from the source dataset do not match those of the
> output file so it is not possible to write the poFeature to it
directly.
>
> Ideally, we'd need a way to assign a new OGRFeatureDefn on the
poFeature
> and set the value of the additional fields on the poFeature before
> passing it to the target file, but I don't think the underlying OGR
> classes would allow us to do that in a clean way.
>
> I think the safest way to go will be to use
TABFeature::CloneTABFeature():
>
>   TABFeature *poDestFeature =
> poFeature->CloneTABFeature(poDstFile->GetLayerDefn())
>
> this will make a copy of the source (poFeature) geometry and all
> MapInfo-specific attributes except for the field values since it
> will detect that the source and target field definitions are not
identical.
>
> You should then copy the field values from poFeature to poDestFeature
> yourself with a loop like the following:
>
>      for( int i = 0; i < poFeature->GetDefnRef()->GetFieldCount(); i++
)
>      {
>          poDestFeature->SetField( i, poFeature->GetRawFieldRef( i ) );
>      }
>
> ... and then assign the field values for the additional fields using
> additional calls to poDestFeature->SetField().
>
> I should warn you that I wrote this without testing myself, but I am
> confident that it should do what you need. Please give it a try and
let
> us know how it goes.
>
> Daniel
>
>
> On 11-01-04 12:37 PM, Frosty wrote:
> > Hello Everyone,
> >
> > I am trying to add data to an existing .tab file in MapInfo. I know
that it isn't possible to write directly to the file so I have been
trying to modify tab2tab to copy the base file and add the new field and
features that I need.
> >
> > I wait until tab2tab.cpp has copied the existing fields information
from the base file and then I add a new field.
> >
> > The new field gets created but then when tab2tab trys to copy the
features/objects from the base file to the new file the program crashes
with the following message:
> >
> > ERROR 7: Assertion `poDATFile->GetFieldType(iField) == TABFInteger&&
iField ==
> > 0' failed
> > in file `mitab_feature.cpp', line 489
> >
> > I think the problem is that I need to increase the number of fields
the program sees when I create the new one.
> >
> > I would be grateful if someone could tell me where I am going wrong
or make any suggestions as to what I should try to get around this
problem.
> >
> > Many thanks,
> >
> > Anthony
> >
>
>
> --
> Daniel Morissette
> http://www.mapgears.com/
>

Reply via email to