Search code examples
bashgisgdalogr

Using GDAL and ogr utilities in MAC terminal in conjunction with QGIS


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 `('

Solution

  • 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