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.

Is ist possible to import multiple textfiles (csv, tsv etc.) as layers in one step or do i have to do it file by file?

share|improve this question
1  
What software are you using? –  KevinMayall Aug 28 '12 at 16:31
    
do the delimited text files have the same separator, the same structure, etc.? –  Giovanni Manghi Aug 28 '12 at 22:01

1 Answer 1

You can use the tool ogr2ogr and a little one-liner script to import a bunch of csv files together. It will help if you are trying to automate the process or have large number of files.

If you have QGIS installed, you should already have ogr2ogr. (on windows, open the MSYS terminal ). Otherwise grab FWTools for your platform and try the following.

  • Create a plain text file called .vrt file for each of csv files. See http://www.gdal.org/ogr/drv_csv.html for example syntax. This is a one-time thing. If your source files change after that, you don't need to change the vrt files as long as the path and structure remains the same
  • Assuming you have a folder with your vrt files at /data/csv/ Run the following:

    for x in /data/csv/*.vrt; do ogr2ogr -f "ESRI Shapefile" /data/${x%.*}.shp $x;done

You'll get your shapefiles in /data/ folder.

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.