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/
------------------------------------
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/mitab/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/mitab/join
(Yahoo! ID required)
<*> To change settings via email:
[email protected]
[email protected]
<*> To unsubscribe from this group, send an email to:
[email protected]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/