Search code examples
bashloopsshapefileogr

Why is bash/ogr outputting shapefiles into individual folders within the output directory?


I'm new to bash/ogr and can't seem to figure out why this loop outputs shapefiles into individual folders within the output directory. Here is my code:

BASE=/home/user/J/cacti_mexico
INPUT=/home/user/J/cacti_mexico/shps
OUTPUT=/home/user/J/cacti_mexico/mexshps
SCRIPT=/home/user/J/cacti_mexico/scripts

cd $INPUT

while read line; do 
  echo $line 
  for file in $INPUT/$line.shp ; do 
    ogr2ogr $OUTPUT/$line $file
  done
done < $SCRIPT/cacti_mexico_names.txt

The cacti_mexico_names.txt file contains a list of species names which are picked up from the input directory once .shp has been concatenated onto the end of it. If anyone can tell me how to get all the shapefiles from ogr2ogr to output into $OUTPUT directly, that would be great.

Update:

ogr2ogr treats its first argument as the name of a directory so the fixed code reads as:

ogr2ogr $OUTPUT $file

Solution

  • Since feature requests to mark a comment as an answer remain declined, I copy the above solution here.

    It appears that ogr2ogr treats its first argument as the name of a directory, not the name of a file. Would ogr2ogr $OUTPUT $file work? – chepner