[Gdal-dev] Problem writing to MapInfo files
Woon Wei Lee
wlwoon at must.edu.my
Sun Jul 11 12:50:01 EDT 2004
Dear all,
It turns out that the problem seems to be that the pen style isn't transferred across by
simply doing a "setstylestring()" command -> this is a member of class TABFeature but
what really matters when writing to a file seems to be class ITABFeature (class
TABPolyline is derived from both these classes).
Somehow there is some kind of problem with synching the pen styles between the two
so it is possible to appear to get the correct settings when executing a "setstylestring()"
(and checking the outcome using getstylestring()) on the feature object, but
TABPolyline->GetPenColor() still returns a zero...
I was able to get the pen colors to transfer correctly by adding something like this to the
function CreateFeature() in file mitab_imapinfofile.cpp:
// Declaring utility pointers
TABPolyline *mod_poTABFeature,*mod_poFeature;
// Cast as pointers to TABPolyline object so that we can call the class functions
// GetPenColor() and GetPenPattern()
mod_poFeature=(TABPolyline*) poFeature;
mod_poTABFeature=(TABPolyline*) poTABFeature;
// Set the Pen Colors and Pen Patterns
mod_poTABFeature->SetPenColor(mod_poFeature->GetPenColor());
mod_poTABFeature->SetPenPattern(mod_poFeature->GetPenPattern());
I'm afraid it's a bit of a hack and only works for Polylines (plus it doesn't address the
underlying problem of how the two styles came to be different in the first place) - I
haven't had time to really understand the full class structure or to figure out how to
devise a proper fix yet but I hope this sheds some light on the problem which some of
us have encountered..
Best Regards
Wei Lee
On 7 Jul 2004 at 16:50, Frank Warmerdam wrote:
> Woon Wei Lee wrote:
> > Hi all
> >
> > I have been trying to put together a little program to re-write data
> > from an existing *.TAB file to a new layer but with different
> > colours for the features (I am working on an app to process traffic
> > data then return a colour-coded congestion map) but the ogr library
> > refuses to transfer the stylestring info over to the new layer.
> >
> > I noticed from a previous posting that this is a known bug (
> > http://xserve.flids.com/pipermail/gdal-dev/2004-July/006558.html )
> > so I thought I could have a short at debugging it but I can't seem
> > to find the relevant part of the ogr source.
> >
> > My program uses the function OGR_L_CreateFeature() from the c api
> > which is a wrapper for OGRLayer::CreateFeature() but the closest I
> > can find is this bit of code from ogrlayer.cpp:
> >
> > OGRErr OGRLayer::CreateFeature( OGRFeature * )
> >
> > {
> > return OGRERR_UNSUPPORTED_OPERATION;
> > }
> >
> > which presumably is a stub for some driver specific version which is
> > contained in another file.. however I just can't find where the
> > "real" function is. Could anyone help me out please??
>
> Wei Lee,
>
> The MITAB driver overrides the CreateFeature in the IMapInfoFile class
> found in gdal/ogr/ogrsf_frmts/mitab/mitab_imapinfofile.cpp. Looking
> at this method, I see it makes no effort to transfer the style string
> to the internal feature. I am suspecting this is responsible for the
> problems generating proper styling results. Try adding something like
> this down just before the SetFeature() call to apply the passed in
> style string to the real MapInfo feature object used for writing and
> see if that helps.
>
> if( poFeature->GetStyleString() != NULL )
> poTABFeature->SetStyleString( poFeature->GetStyleString() );
>
> Best regards,
>
> --
> ---------------------------------------+------------------------------
> -------- 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 |
> Geospatial Programmer for Rent
>
>
More information about the Gdal-dev
mailing list