我试图将以下Windows .bat代码转换为MAC的.sh代码

时间:2014-09-13 19:41:56

标签: windows macos batch-file

我目前正在参加GIS编程课程。使用GDAL和ogr操作数据的说明是为Windows PC编写的。我目前正在研究MAC。我希望能够深入了解如何将.bat代码转换为.sh代码。谢谢!!

Windows .bat代码:

cd /d c:\data\PhiladelphiaBaseLayers
set ogr2ogrPath="c:\program files\QGIS Dufour\bin\ogr2ogr.exe"
for %%X in (*.shp) do %ogr2ogrPath% -skipfailures -clipsrc c:\data\PhiladelphiaBaseLayers\clipFeature\city_limits.shp c:\data\PhiladelphiaBaseLayers\clipped\%%X c:\data\PhiladelphiaBaseLayers\%%X
for %%X in (*.shp) do %ogr2ogrPath% -skipfailures -s_srs EPSG:4326 -t_srs EPSG:3857  c:\data\PhiladelphiaBaseLayers\clippedAndProjected\%%X c:\data\PhiladelphiaBaseLayers\clipped\%%X

我的mac .sh代码:

cd ~/Desktop/PhiladelphiaBaseLayers

set ogr2ogrPath="/Applications/QGIS.app/Contents/Resources/python/plugins/processing/algs/gdal/ogr2ogr.py" \

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

for shpfile in *.shp 
do $ogr2ogrPath$ -skipfailures -s_srs EPSG:4326 -t_srs EPSG:3857 \
~/Desktop/PhiladelphiaBaseLayers/clipped/"shpfile2""shpfile"
done

2 个答案:

答案 0 :(得分:0)

好的,我已经尝试弄清楚你在尝试什么。我认为这会更接近,但我不知道你的脚本中有shpfile2 - 现在应该修复所有其他问题。

#!/bin/bash
cd ~/Desktop/PhiladelphiaBaseLayers

ogr2ogrPath="/Applications/QGIS.app/Contents/Resources/python/plugins/processing/algs/gdal/ogr2ogr.py"

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

for shpfile in *.shp 
do 
   $ogr2ogrPath -skipfailures -s_srs EPSG:4326 -t_srs EPSG:3857 \
      ~/Desktop/PhiladelphiaBaseLayers/clipped/"$shpfile"
done

答案 1 :(得分:0)

虽然它产生了一些关于拓扑异常的奇怪错误,但这是对我有用的代码。

#!/bin/bash
#this is a bash file for conducting operations through ogr2ogr

cd ~/documents/PhiladelphiaBaseLayers

ogr2ogrPath="/library/frameworks/GDAL.framework/versions/1.11/programs/ogr2ogr"

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

for f in *.shp; do $ogr2ogrPath -skipfailures -s_srs EPSG:4326 -t_srs EPSG:3857 ~/documents/PhiladelphiaBaseLayers/clippedandprojected/$f ~/documents/PhiladelphiaBaseLayers/clipped/$f; done