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
arcpy.overwriteOutputs = True csvfile = r"C:\Users\meiben\Desktop\test\fires.csv" lat_g = "lat_g" long_g = "long_g" outlayer = "xyEventlayer" arcpy.MakeXYEventLayer_management(csvfile, long_g, lat_g, outlayer,arcpy.SpatialReference(4326)) arcpy.CopyFeatures_management(outlayer,"templayer") arcpy.Delete_management(outlayer) arcpy.Project_management("templayer","coord_conv",arcpy.SpatialReference(26771)) arcpy.Delete_management("templayer")
I'm a little unclear on what you're trying to do once you get the file into State Plane, but the process to getting it there could go something like this. Note that here, I'm explicitly converting from WGS84 to State Plane:arcpy.overwriteOutputs = True csvfile = r"C:\Users\meiben\Desktop\test\fires.csv" lat_g = "lat_g" long_g = "long_g" outlayer = "xyEventlayer" arcpy.MakeXYEventLayer_management(csvfile, long_g, lat_g, outlayer,arcpy.SpatialReference(4326)) arcpy.CopyFeatures_management(outlayer,"templayer") arcpy.Delete_management(outlayer) arcpy.Project_management("templayer","coord_conv",arcpy.SpatialReference(26771)) arcpy.Delete_management("templayer")
A couple changes that I made here was using the Spatial Reference method instead of pointing to a file on the system.
outlayer,arcpy.SpatialReference(4326) = GCS WGS 84
arcpy.SpatialReference(26771) = PCS NAD_1927_StatePlane_Illinois_East_FIPS_1201
Check out the following URL for a list of all the codes:
http://resources.arcgis.com/en/help/main/10.1/018z/pdf/projected_coordinate_systems.pdf
At the end of this script, you should have a feature layer to do whatever you like with.
Hope this helps!
Matt
WGS84 = """GEOGCS["GCS_WGS_1984", DATUM["D_WGS_1984", SPHEROID["WGS_1984",6378137.0,298.257223563] ], PRIMEM["Greenwich",0.0], UNIT["Degree",0.0174532925199433] ]""" arcpy.DefineProjection_management("featureClass",WGS84)
coords = [row[0] for row in arcpy.da.SearchCursor("FeatureClass",["SHAPE@XY"])] >>> coords >>> [(-117.54547981299241, 34.17563985328801)]
geom = [row[0] for row in arcpy.da.SearchCursor("FeatureClass",["SHAPE@"])][0] partCount = geom.partCount for n in range(partCount): part = geom.getPart(n) for point in part: print point.X, point.Y