kekeje

coordinate conversion, for excel/csv files

Discussion created by kekeje on Apr 30, 2014
Latest reply on May 1, 2014 by eibenm
I have an excel file (or in fact converted to csv for easy use. Arcpy seems to be buggy about excel files...) with some lat/long coordinates that I would need to add corresponding projected coordinates. The way I can think of doing this is to use the MakeXYEvent to create an event layer, then reproject the layer and add the projected X and Y.

Implementation:

import os, arcpy, sys, traceback
from xlrd import open_workbook
import xlwt


arcpy.overwriteOutputs = True

projectionsPath = r"C:\Test\_UtilityScripts\Coordinate Systems_CopiedFromArcMap\Projected Coordinate Systems\State Plane\NAD 1983 (Meters)"
csvfile = r"C:\Test\6_USA_FIPs\excel\latlong_seperated\IL.csv"
lat_g = "lat_g"
long_g = "long_g"
outlayer = "xyEventlayer"
#savedlayer = r"C:\Test\6_USA_FIPs\python\temp\xyOutput.lyr"
#outputSHP = r"C:\Test\6_USA_FIPs\python\temp\xyOutput.shp"


if arcpy.Exists(outlayer):
    arcpy.Delete_management(outlayer)

srGCS = os.path.join(r"C:\Test\_UtilityScripts\Coordinate Systems_CopiedFromArcMap\Geographic Coordinate Systems\North America", "NAD 1983.prj")
srPRJ = os.path.join(projectionsPath, "NAD 1983 StatePlane Illinois East FIPS 1201 (Meters).prj")
arcpy.MakeXYEventLayer_management(csvfile, lat_g, long_g, outlayer, srGCS)

rows = arcpy.SearchCursor(outlayer, "", srPRJ)
row = rows.next()
feat = row.Shape
pnt = feat.getPart()
print pnt.X


I am using SearchCursor above with on the fly projection for coordinate conversion. But I am always getting coordinates of (nan, nan)??? I've tested the syntax with other shapefiles, and it should work... Anything special with this xyevent layer?  Please help, thanks people!

Outcomes