0

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
JPD
  • 2,561
  • 5
  • 22
  • 26
  • 1
    Isn't your inner `for`-loop equivalent to just `ogr2ogr $OUTPUT/$line $input/$line.shp`? (I mean, unless you have whitespace or asterisks or whatnot in `$line`, in which case you have bigger problems.) – ruakh Aug 17 '12 at 14:34
  • 2
    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 Aug 17 '12 at 14:37
  • Chepner, you are correct. Thanks for spotting this! – JPD Aug 17 '12 at 14:57

1 Answers1

1

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

Community
  • 1
  • 1
Armali
  • 18,255
  • 14
  • 57
  • 171