1

I am pretty new to the open-source GIS software. I am trying to clip and project data layers using GDAL and ogr in my MAC terminal. I can get the data to clip when I am just clipping but when I try and combine the two (clip and project), I am getting a syntax error. The syntax I have was written for Command Line and I'm thinking I may need to tweak it for terminal. Any help would be greatly appreciated! If someone is willing to help, I will try and provide more information if necessary.

Here is my line of code:

$for %X in (*.shp) do ogr2ogr -skipfailures -clipsrc
~/Desktop/PhiladelphiaBaseLayers/clipFeature/city_limits.shp
~/Desktop/PhiladelphiaBaseLayers/clipped/%X
~/Desktop/PhiladelphiaBaseLayers/%X

When I run the code, I receive this error message:

-bash: syntax error near unexpected token `('
Zero Piraeus
  • 56,143
  • 27
  • 150
  • 160
Ash
  • 81
  • 1
  • 9

2 Answers2

1

Switcher from windows to mac? ;)

If I understand right your intent is run the ogr2ogr with 3 file arguments

try the next

for shpfile in *.shp
do
    echo ogr2ogr -skipfailures -clipsrc \
       ~/Desktop/PhiladelphiaBaseLayers/clipFeature/city_limits.shp \
       ~/Desktop/PhiladelphiaBaseLayers/clipped/"$shpfile" \
       ~/Desktop/PhiladelphiaBaseLayers/"$shpfile"
done

when you satisfied, remove the echo

clt60
  • 62,119
  • 17
  • 107
  • 194
  • Thank you! Actually, I've used a MAC most of my life. I've just recently started a technology degree (I have a Biology background), and I'm still getting used to terminal. :) So I ran the new code and came up with this error FAILURE: Couldn't fetch requested layer '/Users/ashleyhaynes/Desktop/PhiladelphiaBaseLayers/atms.shp'! – Ash Sep 13 '14 at 17:11
  • Also, when I type ogrinfo I am receiving this $ ogrinfo Usage: ogrinfo [--help-general] [-ro] [-q] [-where restricted_where] [-spat xmin ymin xmax ymax] [-geomfield field] [-fid fid] [-sql statement] [-dialect sql_dialect] [-al] [-so] [-fields={YES/NO}] [-geom={YES/NO/SUMMARY}][--formats] datasource_name [layer [layer ...]] FAILURE: No datasource specified. – Ash Sep 13 '14 at 17:25
  • Thank you for your help!! I ended up getting it to work!! So I would use something like "$shpfile" in place of %X? correct? Thanks again!!! – Ash Sep 13 '14 at 17:45
  • @AshleyHanes search google for "basic bash" and you will find many guides... [like this](http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html) good luck with bash programming. – clt60 Sep 13 '14 at 18:52
1

This is what ultimately worked for me. Take out the quotations around the variable call. All one line.

for f in *.shp; do ogr2ogr -skipfailures -clipsrc ~/documents/PhiladelphiaBaseLayers/clipFeature/city_limits.shp ~/documents/PhiladelphiaBaseLayers/clipped/$f ~/documents/PhiladelphiaBaseLayers/$f; done