Batch SHP to CSV Conversion with Reprojection

The following Shell script performs a conversion and reprojection of a folder full of Shapefiles to CSVs:

for f in `ls *.shp`; do
ogr2ogr -s_srs EPSG:4326 -t_srs EPSG:3035 -f CSV $f.csv $f -lco GEOMETRY=AS_XYZ

Thanks OGR!

  1. pvanb said:

    Works like a charm, nice

  2. I think the first line can be
    for f in *.shp; do
    which will work even if the user has aliased ls to something odd.

  3. In addition to Ian’s comment, rather than having two extensions (“prefix.shp.csv”), you can rename it to have only one (“prefix.csv”):

    replace: $f.csv
    with: `basename $f .shp`.csv

    • underdark said:

      Thanks for the tips! I’m new to Shell scripting.

%d bloggers like this: