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
done

Thanks OGR!

About these ads
4 comments
  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.

Follow

Get every new post delivered to your Inbox.

Join 3,002 other followers

%d bloggers like this: