Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm using QSpatialite only. I don't have spatialite-gui neither the shell.

I want to import multiple TXT/CSV at one time. How is it possible to do that ? I found nothing on the internet.

Thanks

share|improve this question

1 Answer 1

You'll definitely want to install the spatialite shell program and run the imports in a loop. You can write a simple sql/sqlite command file (let's call it imports.sql) with lines like:

.separator ',';
.import first.csv first
.import second.csv second
.import third.csv third
....

Now run:

 spatialite -init imports.sql csvfiles.sqlite

=== Edit ===

Here are some more details. I tried on a small set of simple csv files, and it seems to work: First a loop (run on linux) to collect all the files into one "import.sql" command file.

echo ".mode csv" >> imports.sql;    
for f in *.csv; do t=`basename $f .csv`; \
    echo "CREATE TABLE $t (id INTEGER, name text, label text, x double, y double);" >> imports.sql; \
    echo ".import $f $t" >> imports.sql; done

Now I ran:

spatialite -init imports.sql test.sqlite

Tables were created and the data rows imported. You have to make sure your CSV files are identical in structure, and "clean" i.e. no extraneous commas, text should be quoted, etc. And of course you will need design the above "CREATE TABLE statement to match the columns in the CSV files.

share|improve this answer
    
Ok, and if I Have 50 files to import, does the imports.sql looks like : .import first.csv first, .import second.csv second ... .import fiftieth.csv ? Is there no way to do a "for" loop, like a batch ? –  Samy-DT Jul 19 '13 at 12:01
    
I just tried your trick without success. I wrote the imports.sql in Notepad++ and ran the line from the sqlite3.exe. –  Samy-DT Jul 19 '13 at 12:38
    
Have a look at my edit above, Maybe eit will help. –  Micha Jul 19 '13 at 19:33

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.