[FWTools] ogr2ogr newbie question, MapInfo to SQLite conversion

Frank Warmerdam warmerdam at pobox.com
Thu Feb 5 09:43:14 EST 2009


Per Åkesson wrote:
> As subject says, bare with a newbie question:
> 
> I'm trying to convert a Mapinfo .TAB table to SQLite.
> I'm issuing the folwing command:
> 
> ogr2ogr  -f "SQLite" test.SQLite mapinfotable.TAB
> 
> but when inspecting the generated test.SQLite file in SQLite,
> 
>  	select * from GEOMETRY_COLUMNS;
> 
> I get no geografic data. (Other attributes seemes to be there)
> 
> Am I missing some command line switch ?
> 
> All relevant MapInfo files exists (.MAP, .IND, .ID, .DAT)

Per,

The geometry will actually be in a table ... likely one called
mapinfotable in the sqlite database in your case.

When I load a polygon set from a mapinfo file called canada.tab I get:


sqlite> select * from geometry_columns;
canada|GEOMETRY|0|2|50000|WKB
sqlite> select * from canada limit 2;
1||AB|Alberta|     2361895|     2545555|     1171935|     1268180| 
1189885|       1277375|  637465|   1677545|  230545|  2068645|   51100| 
72785|   12365|    52635|     288025|      835020|      910390|   40350
2||BC|British Columbia|     2877770|     3282060|     1452635|     1656090| 
   1424915|       1625975|  704910|   2155135|  422015|  2606535|   45265| 
81020|   26440|   140985|     381815|     1085650|     1243895|   39958
sqlite> .schema canada
CREATE TABLE 'canada' (OGC_FID INTEGER PRIMARY KEY,GEOMETRY BLOB, 'province' 
VARCHAR, 'province_name' VARCHAR, 'pop_1990' FLOAT, 'pop_1994' FLOAT, 
'pop_fem_90' FLOAT, 'pop_fem_94' FLOAT, 'pop_male_90' FLOAT, 'pop_male_94' 
FLOAT, 'pop_lt_15' FLOAT, 'pop_16_64' FLOAT, 'pop_65plus' FLOAT, 'pop_english' 
FLOAT, 'pop_french' FLOAT, 'pop_german' FLOAT, 'pop_italian' FLOAT, 
'pop_chinese' FLOAT, 'pop_other' FLOAT, 'num_hh_90' FLOAT, 'num_hh_94' FLOAT, 
'med_inc_90' FLOAT);

So, while the geometry doesn't show up in the select on canada, that
appears to be because it is represented as a WKB BLOB.

sqlite> select length(geometry) from canada limit 2;
749
3576

I pretty much need to use ogrinfo again to see the geometry in a more
readable format.

In previous versions we defaulted to storing the geometry in WKT which was
easier to inspect in sqlite3 but was less efficient.   I believe you can still
force loading in WKT with ogr2ogr by specifying -lco FORMAT=WKT on the
commandline.

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 FWTools mailing list