11

I've got a .csv file that contains a long list of latitude and longitude points. Is there an efficient way to batch convert the list into a projected UTM coordinate system?

10 Answers 10

8

Perhaps the simplest way is using something like QGIS and its delimited text plugin to import and then export the data. If you're looking for something commandline and scalable, then the VRT approach Sasa mentioned is a good one.

You can also do it with file inputs and outputs using gdaltransform:

gdaltransform -s_srs epsg:4326 -t_srs epsg:25832 < space-delimited-coordinates.txt

And if you need more programmatic access to the results, check out geographika's answer using pyroj for a related question.

  • Can you be more specific about how I should export the data in QGIS? I tried to right click on the imported layer with the points, click Save As..., and specified UTM 16N as my projected coordinate system. But the resulting file was not changed! – hpy Apr 5 '11 at 23:03
  • I can.after you load the CSV just point on the layer ruler then do save as>selected crs> select the system to transform to>and save. if you then want to go back to CSV dfsfsd – yair suari Jan 9 '13 at 9:20
  • some editing problems. if want to go back to csv use the attributes calculator and calculate the $x and $y values on the geometry functionsd to get the location on the nes crs the save again as csv – yair suari Jan 9 '13 at 9:27
9

With arcmap,
add the csv and use the lat longs to create an event table. (right click layer> "Display XY Data")

This creates an event layer with the table and a point layer (not a real point layer, it needs to be exported later)

display xy

set the document projection (data frame properties) to the desired output of the file. (right click layers "in the TOC">properties> coordinate system tab).

Doc prop

desired projection

right click the layer in TOC > Export Data

export

Use the option to "use the same coordinate system as: the data frame"

export

7

ogr2ogr should be able to handle this (you can download FWTools for a quick install).

This thread illustrates how to reproject CSV data. To summarize, you'll need to create a VRT file that contains references to the CSV columns:

<OGRVRTDataSource>
    <OGRVRTLayer name="test">
        <SrcDataSource>test.csv</SrcDataSource>
        <GeometryType>wkbPoint</GeometryType>
        <GeometryField encoding="PointFromColumns" x="RW" y="HW"/>
    </OGRVRTLayer>
</OGRVRTDataSource>

And then run ogr2ogr for reprojection:

ogr2ogr -s_srs "epsg:31466" -t_srs "epsg:25832" -f "CSV" -lco GEOMETRY=AS_XY -sql "SELECT PNR FROM test" temp_dir test.vrt

You'll need to replace epsg:31466 with the appropriate EPSG code for your UTM coordinate system.

4

Corpscon, a free tool from the US Army Corps of Engineers will allow you to batch convert lat/long to/from UTM. Note that it is limited to the United States, and may work in Canada.

3

There are working spreadsheets and other source code (Fortran, C++, etc.) at http://www.gpsy.com/gpsinfo/geotoutm/ Great resource for 1996 (and still works)!

3

We have a commercial (but affordable) standalone desktop application that will allow you to batch convert your coordinates. More information can be found at: http://geomaticsolutions.com/products/geo-suite/geo-calc

You can also use our free online service to perform single point transformations. http://georepository.com/home.html

3

As I understand it, you do not want to simply reproject a file, you want to convert the coordinates themselves and have a new file with the new coordinates. If you Google "convert lat/lon to utm" you should find excel spreadsheets that will do this conversion (e.g. at the University of Wisconsin Green Bay or in whuber's answer above). Or, you can purchase software like AllTrans or Franson Coordtrans, which batch convert to and from many different coordinate systems.

Or, less simple but more educational, is to learn syntax for gdal or FWTools.

3

For a scripting solution, you could use pyproj:

import sys
import csv
import pyproj

# example invocation
# ./reproj.py ./file.csv 32619 4326

if (len(sys.argv) != 4):
    print '%s <csvfile> <epsg_code_in> <epsg_code_out>' % sys.argv[0]
    sys.exit(1)
else:
    p1 = pyproj.Proj(init='epsg:%s' % sys.argv[2])
    p2 = pyproj.Proj(init='epsg:%s' % sys.argv[3])

    f = open(sys.argv[1], 'r')
    table = csv.reader(f)
    for row in table:
        print '%s %s' % (row[1], row[2])
        newxy = pyproj.transform(p1, p2, row[1], row[2])
        print '%s %s' % (row[0], newxy[0], newxy[1])
    f.close()
  • Thank you, fellow programmer! NB: this will work if your CSV file has 3+ columns, with your xy data being the second & third columns. I just had to adjust the indexes a bit since my input x/y are in the first two columns. So clear, extensible, and reusable! – Ahmed Fasih Nov 22 '13 at 3:28
2

The following new site converts files online. (It uses pyproj)

It also generates KML and the input file can often be left 'as is' and not reformatted to suite the conversion program.

Sorry i cant post a numeric domain so have to wrap it in a code block!
http://54.251.49.75/XYZ_tools

Please cut and paste the link to follow it.

  • Removed it. Costing me $120 per year + admin time with too few users. Sorry. – Ninga Oct 15 '16 at 4:10
1

I would not go for ARC solution; for these common conversions there are many online tools such as http://www.hamstermap.com - just copy and paste a list of coordinates and you will get them instantly converted.

  • A better online batch converter for Lon/Lat to UTM is at < zonums.com/online/coords/cotrans.php?module=13 > The hamstermap tool seems to change the input coordinates, whereas the zonums tool doesn't mess up the input data, and also the zonums one works for worldwide data - only in WGS84, but it does allow you to set the zone. Just watch out you select the right option from lat/lon or lon/lat. The Zonums tool gives correct results, and is certainly easier to use than messing around with scripts or whatever. – IanS Feb 13 '16 at 11:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.