Convert .TAB format to .SHP format but maintain .TAB object styles

504 views
Skip to first unread message

Nick

unread,
Sep 15, 2017, 5:15:49 PM9/15/17
to MapInfo-L
Hello.

If I have a .TAB file of say 100 polygons, and the polygons are all different fill colors.  I convert the .TAB file to a .SHP file using either the Universal Translator, or some other conversion 3rd party tool, does anyone know of a way to retain the styles (fill colors) of the polygons when the shape file is created?

Have a good weekend.

Ross Nixon

unread,
Sep 15, 2017, 10:37:33 PM9/15/17
to MapInfo-L
Unfortunately Shape files don't, and can't, have colours.

Ross

Warren Vick

unread,
Sep 16, 2017, 4:25:26 AM9/16/17
to mapi...@googlegroups.com

Hello Nick,

 

As Ross has pointed out, unlike TAB file sets, SHP does not carry any styling information. In the ArcGIS world, all styling is applied like thematic mapping in Pro. You can store these styling rules in a layer file (LYR) which accompanies the Shapefile set.

 

To reproduce your MapInfo TAB styling in ArcGIS, you would need to have an attribute in your data which could be used to apply the styling. E.g. a name or numeric classification. If you don’t have that (i.e. perhaps they were manually applied), there is a way of extracting the brush details (which includes the colour) with a command run in the MapBasic window.  To following this method add, say, a char(20) field called tab_brush to your polygon data, open the MapBasic window and run the following update command:

 

update myTable set tab_brush = objectinfo(obj,3)

(replace myTable with your table name)

 

The result will be that tab_brush will be populated with data such as “Brush (2, 13559507)”. The first number is the fill type (2=solid) and the second is the RGB colour value. In ArcGIS you can style based on this attribute, although it’s a bit tedious working out which is which is you have quite a few colours. Perhaps run Pro and ArcGIS side-by-side to help with that. Save your styles in an ArcGIS layer file, or MXD (sort of the equivalent of a Pro workspace) to retain your work.

 

Regards,

Warren Vick

Europa Technologies Ltd.

--
--
You received this message because you are subscribed to the
Google Groups "MapInfo-L" group.To post a message to this group, send
email to mapi...@googlegroups.com
To unsubscribe from this group, go to:
http://groups.google.com/group/mapinfo-l/subscribe?hl=en
For more options, information and links to MapInfo resources (searching
archives, feature requests, to visit our Wiki, visit the Welcome page at
http://groups.google.com/group/mapinfo-l?hl=en

---
You received this message because you are subscribed to the Google Groups "MapInfo-L" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mapinfo-l+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Nick

unread,
Sep 17, 2017, 1:04:29 PM9/17/17
to MapInfo-L
Warren,

Thank you for the reply.  Unfortunately, I would not be needing these shape files for ArcGIS, and instead of GeoServer.  Currently, I have to end up writing some .SLD format to key off of certain fields to set the color of polygons. However, I was just trying to see if there was some way the shape file could hold the value of the colors.

I am using GeoServer and shape files are the fastest rendering (other than SQL Server spatial) which in the end would still need SLD to properly format the style of the polygons.

Thanks again! Have a good weekend
Nick

Warren Vick

unread,
Sep 18, 2017, 5:35:14 AM9/18/17
to mapi...@googlegroups.com

Hello Nick,

 

If your intention was to go to GeoServer, I don’t think even the build-in styles of the TAB format would help you. As far as I’m aware, GeoServer uses SLDs to create rules for how features are drawn…. just like ArcGIS or Pro’s thematic mapping. The solution is still to make sure that your data has the attributes which will allow you to do that data-driven cartography. So, as I outlined, if you don’t have a name/number classification which drives your colours, just use the method to make a new field with the brush details and create SLD rules using it. How many classifications/styles do you have? Is it just a handful or are you representing a continuous phenomenon and have lots of colours?

Bo Victor Thomsen

unread,
Sep 18, 2017, 7:16:23 AM9/18/17
to mapi...@googlegroups.com

Hello Nick -

You can convert a tab file to shape using the ogr2ogr command-line program from http://gdal.org.

Normally - as noted by Warren - a shape file doesn't contain any information the visual representation of the objects as tab-files  do.

However you can use an relative obscure function in ogr2ogr to obtain colorvalue, linetype etc. and ve these values in a extra field during the conversion.

This is the normal method:

ogr2ogr -f "ESRI Shapefile" rivers.shp rivers.tab

However using this:

ogr2ogr -f "ESRI Shapefile" -sql "select *, CAST(OGR_STYLE AS character(255)) from rivers" rivers.shp rivers.tab
The command will create an extra field "OGR_STYLE" in the shape file containing a style definition text. See: http://www.gdal.org/ogr_feature_style.html for further explanations

Regards
Bo Victor Thomsen
AestasGIS
Denmark

Nick

unread,
Sep 18, 2017, 8:43:16 AM9/18/17
to MapInfo-L
Warren & Bo,

I have  7 total. (listed below) I did exactly what you had mentioned and used the style values (that are coming from SQL server where I've uploaded the .TAB files) to then create which way to display the polygons on the GeoServer layer.

Pen (1,1,0)  Brush (2,15654399,16777215) 
Pen (1,2,11592380)  Brush (2,11592380,16777215) -- parks, ball fields, playgrounds,
Pen (1,1,0)  Brush (2,16772272,16777215) -- stadiums, fairgrounds, public venues
Pen (1,1,0)  Brush (2,16777168,16777215) --malls, shopping centers
Pen (1,2,13100731)  Brush (2,13100731,16777215) 
Pen (1,2,16362674)  Brush (2,16362674,16777215) 
Pen (1,1,0)  Brush (2,16748688,16777215) 

Thanks for the reassurance that there was in fact no way to have those styles be a part of the SHP file.  I did not think there was; however, I wanted to make sure someone could help confirm that for me.

As for the SLD coding, an example of what I did to make it work is below for anyone else that may wonder or need help with this in the future.

      <FeatureTypeStyle>
        <Rule>
          <Name>Public venues (2)</Name>
          <ogc:Filter>
          <ogc:PropertyIsEqualTo>
            <ogc:PropertyName>MI_STYLE</ogc:PropertyName>
            <ogc:Literal>Pen (1,1,0)  Brush (2,16777168,16777215) </ogc:Literal>
          </ogc:PropertyIsEqualTo>
          </ogc:Filter>          

          <MinScaleDenominator>0</MinScaleDenominator>          
          <MaxScaleDenominator>36001</MaxScaleDenominator>

          <TextSymbolizer>
            <Label>
              <ogc:PropertyName>Name</ogc:PropertyName>
            </Label>
            <Font>
              <CssParameter name="font-family">Arial</CssParameter>
              <CssParameter name="font-size">11</CssParameter>
              <CssParameter name="font-style">normal</CssParameter>
              <CssParameter name="font-weight">bold</CssParameter>
            </Font>
            <Fill>
              <CssParameter name="fill">#6d6446</CssParameter>
            </Fill>
            <VendorOption name="autoWrap">60</VendorOption>
            <VendorOption name="maxDisplacement">100</VendorOption>
          </TextSymbolizer>      
          <PolygonSymbolizer>
            <Fill>
              <CssParameter name="fill">#ffecb0</CssParameter>
            </Fill>
          </PolygonSymbolizer>
        </Rule>
      </FeatureTypeStyle>      
      
            
      <FeatureTypeStyle>
        <Rule>
          <Name>Hospitals</Name>
          <ogc:Filter>
          <ogc:PropertyIsEqualTo>
            <ogc:PropertyName>MI_STYLE</ogc:PropertyName>
            <ogc:Literal>Pen (1,1,0)  Brush (2,16748688,16777215) </ogc:Literal>
          </ogc:PropertyIsEqualTo>
          </ogc:Filter>          

          <MinScaleDenominator>0</MinScaleDenominator>          
          <MaxScaleDenominator>36001</MaxScaleDenominator>

          <TextSymbolizer>
            <Label>
              <ogc:PropertyName>Name</ogc:PropertyName>
            </Label>
            <Font>
              <CssParameter name="font-family">Arial</CssParameter>
              <CssParameter name="font-size">11</CssParameter>
              <CssParameter name="font-style">normal</CssParameter>
              <CssParameter name="font-weight">bold</CssParameter>
            </Font>
            <Fill>
              <CssParameter name="fill">#991a1a</CssParameter>
            </Fill>
            <VendorOption name="autoWrap">60</VendorOption>
            <VendorOption name="maxDisplacement">100</VendorOption>
          </TextSymbolizer>      
          <PolygonSymbolizer>
            <Fill>
              <CssParameter name="fill">#ff9090</CssParameter>
            </Fill>
          </PolygonSymbolizer>
        </Rule>
      </FeatureTypeStyle>      
      

Warren Vick

unread,
Sep 18, 2017, 9:48:31 AM9/18/17
to mapi...@googlegroups.com

Hello Nick,

 

Looks like you’re all set. With just 7 style classes, you could simply those pen/brush strings down to a simple number so save any future SLD editor the pain of working out what they are!

 

Regards,

Warren Vick

Europa Technologies Ltd.

 

From: mapi...@googlegroups.com [mailto:mapi...@googlegroups.com] On Behalf Of Nick
Sent: 18 September 2017 13:43
To: MapInfo-L <mapi...@googlegroups.com>
Subject: Re: [MI-L] Convert .TAB format to .SHP format but maintain .TAB object styles

 

Warren & Bo,

--

Peter van Dijk

unread,
Oct 4, 2017, 9:41:30 PM10/4/17
to MapInfo-L
Hi Nick,
You can use this java program to create the SLD files for Geoserver.
 AtlasStyler -1.9

Run the application, load your layers, style your layers and save the sld files with the name of the layer, copy them over to geoserver and use the layer name to select the sld style, done.

Sorry I didn't see this post earlier , I could have saved you a lot of time.

cheers

Grant Boxer

unread,
Nov 7, 2017, 9:50:01 PM11/7/17
to MapInfo-L
I am wondering what the RGB value is that MapInfo is returning? The examples below do not have enough digits to red,green, blue values. I thought it would need to be something like 000000000, which can then be broken up into RRR, GGG and BBB values?

Perhaps I am missing something here. Assistance appreciated.

Cheers Grant

Uffe Kousgaard

unread,
Nov 8, 2017, 1:37:53 AM11/8/17
to mapi...@googlegroups.com
Hi,

Colour is returned as 65536*red + 256*green + blue or
65536*blue + 256*green + red.
Can't remember which one it is.

Key thing is this is the opposite of what windows uses for colour codes.

Regards
Uffe Kousgaard

--

Grant Boxer

unread,
Nov 8, 2017, 3:16:17 AM11/8/17
to MapInfo-L
Thanks Uffe,

can you expand on this? Seems pretty confusing.

Cheers Grant

Uffe Kousgaard

unread,
Nov 8, 2017, 4:15:59 AM11/8/17
to mapi...@googlegroups.com
Hi,

Mapinfo uses BGR, while windows uses RGB. That is the difference.

So red = $FF0000 in one system, but $0000FF in the other system. $ meaning hex numbers.

At least green is the same in both !

Mapbasic doesn't make working with hex numbers easy at all. Not any good functions for that, except combinations of mod and div.

Regards
Uffe Kousgaard
Reply all
Reply to author
Forward
0 new messages