Select to view content in your preferred language

Coordinate conversion

1347
12
04-28-2013 07:31 PM
MarkPaulson
Occasional Contributor
I manually import a CSV to create a table which I use to make an XY event layer during the creat process I can select the coordinate system of my CSV (NAD 27 LL) and the transformation to use for the conversion to the data frame (Web Mercator). I have been reading about the make xy event functionality, but I am missing the transformation part.
Tags (2)
0 Kudos
12 Replies
ChrisSnyder
Honored Contributor
.projectAs(outputSR,"Name_Of_The_Transformation")


I'll have to remember that one...
0 Kudos
MarkPaulson
Occasional Contributor
Is there a reason you're using an event layer in desktop?  The below code could be modified to simply write the geometries into a new feature class rather than printing the values.  It's untested code, but should be pretty close.  It reprojects each row of your csv file into the new coordinate system with the transformation and prints it out.

import arcpy
infile = open("yourfilename.csv","r")
for line in iter(infile):
 aRow = line.split(',')
 point = arcpy.Point()
 point.X = aRow[5] #array position of X value
 point.Y = aRow[6] #array position of Y value
 inputSR = arcpy.SpatialReference("c:/coordsystems/NAD 1983.prj")
 outputSR = arcpy.SpatialReference("c:/coordsystems/NAD 1927.prj")
 pointGeometry = arcpy.PointGeometry(point,inputSR)
 projectedPointGeometry = pointGeometry.projectAs(outputSR,"Name_Of_The_Transformation")
 outputPoint = projectedPointGeomtry.centroid
 print outputPoint.X,outputPoint.Y


The reason I am using the XY event layer is that it the manual process that I use and I have a schema.ini file that I use for the field formatting from my CSV. The bigger reason is that I am a beginner at Python and I barely have an idea what you are doing with the above code. I did try to modify it, but that started sending me down some other rabbit holes. For some reason, one of the fields  causes the position of the X and Y to move on some lines. Trying to figure this out is not a task I'm ready to tackle. Thank you for your input though.

On another note, the project tool will work with the an event layer created with the "Display XY Data" option in desktop, but it will not work with "MakeXYEventLayer_management" in arcpy. I can try and project the feature class in desktop and it always fails.
0 Kudos
MarkPaulson
Occasional Contributor
Hello all, I'm an idiot, I spent hours trying to figure this out and the whole time I had my X & Y reversed. The MakeXYEventLayer_management works perfectly. I'm a dumb a__. Now all I have to do is figure out how to export to the database with the correct coordinate system.
0 Kudos