Wither the command line

Matthew Perry poses the question: Why is the command line a dying art?. Funny how these things go–I was thinking about posting on this same topic just the other day, although I may be repeating myself.

The efficiencies of the command line cannot be overstated. I too have seen that deer in the headlights look when a GUI-only user is first exposed to a command prompt. I have also seen people spend days on a data conversion project that could easily be accomplished in hours (or less). Once we get over the initial reaction of “Oh no! I have to learn something new”, most people find the command line a powerful tool.

For example, here is a simple shell script to convert shapefiles in a directory from their current (in this case projected) coordinate system to WGS 84:

    for shp in *.shp; do
      ogr2ogr -t_srs EPSG:4326 wgs84_shapes $shp

This simply takes every shapefile in the current directory and converts it to WGS 84 and places it in the wgs84_shapes subdirectory. If you don’t know what an EPSG:4326 is or need help with projections and coordinate systems, check out the Spatial Reference website.

Total runtime for converting 91 shapefiles was about 47 seconds–way faster than you could do it pointing and clicking.

If you are a Linux or a Mac user, you can take that little shell script and use it directly. If you are a Windows user, you can use the batch language to write a similar script, or better yet install MSYS or Cygwin. With MSYS or Cygwin you can run the script above as-is on Windows.

The quickest way to get the GDAL/OGR utilities for Linux and Windows is to install FWTools. For Mac, download the GDAL framework and required dependencies from Kyng Chaos.

Don’t get me wrong–using a GUI is great, however when you have huge quantities of data to convert there is no better way than the command line.