I'm trying to use gdalsrsinfo to get the proj4 string from a .shp and then pass it to ogr2ogr for use in a batch reprojection loop. It's close to working, but the single quotes are getting passed to the ogr2ogr command and I can't figure out how to strip them off:
My script:
#!/bin/bash
for f in *.shp; do
projsrs=$(gdalsrsinfo -o proj4 $f)
ogr2ogr -f "ESRI Shapefile" -s_srs "$projsrs" -t_srs EPSG:3857 ${f%}3857.shp $f
done
running the gdalsrsinfo
command by itself returns:
username:shpfrm username$ gdalsrsinfo -o proj4 filename.shp
'+proj=utm +zone=11 +datum=WGS84 +units=m +no_defs '
When I use bash -x
to test the output, I see that ''\'
is at the beginning of the string and \'''
is on the end.
+ for f in '*.shp'
++ gdalsrsinfo -o proj4 filename.shp
+ projsrs=''\''+proj=utm +zone=11 +datum=WGS84 +units=m +no_defs '\'''
+ ogr2ogr -f 'ESRI Shapefile' -s_srs ''\''+proj=utm +zone=11 +datum=WGS84 +units=m +no_defs '\''' -t_srs EPSG:3857 filename.shp3857.shp PC_Sec05_Frm64.shp
Failed to process SRS definition: '+proj=utm +zone=11 +datum=WGS84 +units=m +no_defs '
what I need is:
ogr2ogr -f 'ESRI Shapefile' -s_srs '+proj=utm +zone=11 +datum=WGS84 +units=m +no_defs ' -t_srs EPSG:3857 filename.shp3857.shp filename.shp