Using GDAL to export Mapinfo Symbology to database and then writing back to new Mapinfo TAB files using python

449 views
Skip to first unread message

David Crisp

unread,
Jan 5, 2015, 10:53:46 PM1/5/15
to australian-qg...@googlegroups.com
Hi All,

This one is probably aimed at NathanW  because I know he has done some work on this exporting symbology from MapINFO to QGIS in the past.  It is more related to GDAL and MapINFO rather than QGIS but I thought I would start asking questions locally before spreading further out.

I have written some python code that allow me to read in a mapinfo TAB file and then write it into various external file formats and from those create on the fly TAB files.  This is mostly for working with style sheets for our data collection app.   The idea is that a user can log into the web interface and select layer symbology for their styles and then write themselves a new TAB file with the styles in it.

Anyway;    I can read in TAB files, store them as text and then write them out to TAB files and I can write them such that the geometry I want to display is being displayed (Lines, points and Polygons).
 Point Symbology is giving me a headache though.   I can read the style string in, in this case something like the following string;

SYMBOL(a:0,c:#ff0000,s:36pt,id:"mapinfo-sym-196,ogr-sym-1",o:#000000)

I can write this string to a new TAB file AND read it out of the new tab file and it looks the same BUT when I open the TAB file in MapINFO only symbols with the ID string of mapinfo-sym-{0 to 67} actually show up as a styled symbol.  Everything else shows up as a square.   As you can see, I read a symbol with a number of 196 in.  Surly if I read that in and write it out EXACTLY as I read it,  the symbology should be applied appropriately?  

How did you get them to work when you write your Mapinfo to QGIS style converter?

Hopeing you can add some light to my problem and point me in the appropriate direction!

This module is pretty much almost written exactly how i want it to work EXCEPT for the symbology application issues.

Regards,
David Crisp

Alex

unread,
Jan 13, 2015, 11:10:04 PM1/13/15
to australian-qg...@googlegroups.com
Hi David

I haven't used GDAL to read/write TAB, but I have used FME, and store and retrieve styles from TAB to SQL Server and back.

Here's what one of my strings looks like: Symbol (64,65280,10,"MapInfo Miscellaneous",0,0)

and that stuff then gets regexed out with this: Symbol \((.*),(.*),(.*),\"(.*)\",(.*),(.*)\)

and stuck into MI bits like this:


Not sure if that helps, but thought I'd throw it out there just in case...

Cheers,

Alex

David Crisp

unread,
Jan 13, 2015, 11:21:46 PM1/13/15
to australian-qg...@googlegroups.com
Hi Alex,
Thanks for the response.  It  Doesn't really Help though, I'm afraid.   

The part where all the components are split out into an individual usable format works great.  I had not thought of using regexs to split the style instead I wrote my own little parser loop  that's iterated over the string and dealt with the commas etc. in odd spots. Getting that part to work took me a few days but they work.   

The problem is to do with the style itself.   When I read the symbol style from a TAB file (such as mapinfo-sym-196,ogr-sym-1) and then write it out to a TAB file as exactly the same string,  the symbology is generally not applied to the point.

The exception is IF the number is between 0 and 67.   For instance mapinfo-sym-10 will give me a different symbol to mapinfo-sym-20 BUT mapinfo-sym-69 will be a generic square box.  Even though when the original TAB file is viewed in mapinfo the symbol is something different to a square box.

I haven't been able to resolve that problem and haven't found much of an answer Googling the problem either.

Regards,
David Crisp


--
You received this message because you are subscribed to the Google Groups "Australian and New Zealand QGIS User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to australian-qgis-use...@googlegroups.com.
To post to this group, send email to australian-qg...@googlegroups.com.
Visit this group at http://groups.google.com/group/australian-qgis-user-group.
To view this discussion on the web, visit https://groups.google.com/d/msgid/australian-qgis-user-group/6ed66e5a-b62b-45f7-8109-a1fc01e61fa1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

David Collins

unread,
Jun 27, 2018, 6:56:02 PM6/27/18
to QGIS Australia User Group
Hello, David.

I need to determine the background colour of geology polygons in Mapinfo files, and match each colour to one of the attribute values.  (eg. for attribute with name SYMBOL having value 'Qa', use background colour #rrggbb)

Could I adapt your Python code to do this?  If so, could you pass the relevant part of  your Python code available to me? (ie. the code that reads the attribute values and the style string for each feature - reading the geometry is not necessary)

Regards,
David Collins
Reply all
Reply to author
Forward
0 new messages