2

I have many folders, each with a collection of MapInfo tab files (each folder has the same table names). For each folder I want to merge the tab files into one spatialite DB.

My current method is to use ogr2ogr to convert the tab files into shapefiles, and then use .loadshp to load each one into the DB. This truncates my column names, which is irritating.

Is there a way to avoid the shapefile part of this process? ogr2ogr can convert to spatialite, but I do not know how to go about merging multiple spatialite files.

2 Answers 2

2

You should be able to go directly from .tab to spatialite using OGR. See the spatialite format page for more details. You also don't have to create multiple dbs and merge them, just 'append' them all together from the start.

2
  • could you give an example of the command? Aug 18, 2011 at 6:47
  • 1
    Hi Matthew. Using the -append flag in ogr2ogr (see gdal.org/ogr2ogr.html), it would look something like: mkdir merged for %f in (*.tab) do ( if not exist merged\merged.sqlite ( ogr2ogr -f "SQLite" merged\merged.sqlite %f) else ( ogr2ogr -f "SQLite" -update -append merged\merged.sqlite %f -nln Merged ) ) - note that I haven't tried this, but it should be pretty close.. Aug 18, 2011 at 19:21
1

The Windows command was useful to help to port to Linux Bash. You will find this Bash version below:

for file in *.tab; do
    if [[ ! -f "merged.sqlite" ]]; then
        ogr2ogr -f "SQLite" "merged.sqlite" $file -nln merged -nlt PROMOTE_TO_MULTI -dsco SPATIALITE=YES;
    else
        ogr2ogr -f "SQLite" -update -append "merged.sqlite" $file -nln merged -nlt PROMOTE_TO_MULTI;
    fi
done

Some options tips explained below:

  • -nln merged is the name of the table we want
  • -dsco SPATIALITE=YES indicates that we want to use Spatialite geometry storage
  • -nlt PROMOTE_TO_MULTI indicates that we want to change polygons to multipolygons if any present

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.