Converting Projections for Shapefiles using OGR2OGR
Up to table of contentsWith ogr2ogr of course! ogr2ogr is a powerful utility that will transform the projections of your shapefiles when passed the appropriate parameters. In my case, I was using Mapserver to serve data in RI State Plane Feet. In order to do so, the data had to first be converted to meters. Here is the command I used:
ogr2ogr -t_srs EPSG:32130 output.shp input.shp
Since my data already had a projection defined, I did not need to explicitly state a source projection. This command uses the EPSG definition for NAD83 Rhode Island (32130) and performs the feet to meters conversion.
Now say my data wasn't already projected? Here's how we deal with that:
ogr2ogr -s_srs "+proj=tmerc +lat_0=41.08333333333334 +lon_0=-71.5 +k=0.999994 +x_0=100000 +y_0=0 +ellps=GRS80 +datum=NAD83 +to_meter=0.3408 +no_defs" -t_srs EPSG:32130 output.shp input.shp
Let's examine what is going on here:
The -s_srs parameter explicitly defines a projection for the data. The parameters used here were taken out of the EPSG definition (in this case, 32130) in the epsg file(see the projection FAQ for more details on locating EPSG definitions). The entry for RI in the epsg file is as follows:
# NAD83 / Rhode Island <32130> +proj=tmerc +lat_0=41.08333333333334 +lon_0=-71.5 +k=0.999994 +x_0=100000 +y_0=0 +ellps=GRS80 +datum=NAD83 +units=m +no_defs no_defs <>
You can see how the definition in the initial command is formulated. Notice that the "+units=m" parameter has been changed to “+to_meter=0.3408”. This is important for the conversion. Where did the value of 0.3408 come from you ask? From the EPSG file! It has many goodies buried in it so by simply running 'grep "to_meter" epsg’ you can refresh your memory if you need to.
The next parameter in the command is "-t_srs EPSG:32130". This command tells ogr2ogr to transform the data to the EPSG code of 32130. After this is declared, all you need to do is declare a file name for your new shape file and to set which file is being used as the input (note: make sure you don’t confuse the order of these two).
Hit enter, bombs away, and enjoy your new data in meters!
This FAQ applies to: Any version.
Converting to Alaska Albers Equal Area Conic