Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 2 down vote accepted

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.

share|improve this answer
    
could you give an example of the command? – Matthew Finlay Aug 18 '11 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.. – Darren Cope Aug 18 '11 at 19:21

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
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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