# scAPG10pointsMMRPMakeXYlayer.px [X,Y-coodinates in the Access 2007 accdb for 10 points of boring locations] # Description: Creates an XY layer and uses CopyFeatures to save it to a layer file (Used ArcGIS 10.1) # Author: ESRI - modified by Scott Chang per Arkadiusz Matoszka & Wayne Whitley # ******* This script was created and executed in ArcGIS 10.1 by Scott Chang on 1 Feb 2013 ****** # import system modules import arcpy from arcpy import env try: # Set the local variables # in_Table = "firestations.csv" tb = r"C:\TEMP\APG10pointsMMRP.accdb\Table1" xc = "X" yc = "Y" zc = "Z" out_Layer = "Pointlocations_layer" saved_Layer = r"c:\TEMP\APG10pointsMMRPaccdb.shp" # not .layer!!! # Set the spatial reference # spRef = r"Coordinate Systems\Projected Coordinate Systems\Utm\Nad 1983\NAD 1983 UTM Zone 11N.prj" spRef = r"Coordinate Systems\Geographic Coordinate System\World\WGS 1984" # Make the XY event layer... arcpy.MakeXYEventLayer_management(tb, xc, yc, out_Layer, spRef) # Print the total rows print arcpy.GetCount_management(out_Layer) # Save to a layer file # arcpy.SaveToLayerFile_management(out_Layer, saved_Layer) arcpy.CopyFeatures_management(out_Layer, saved_Layer) # New!!! except: # If an error occurred print the message to the screen print arcpy.GetMessages()
# scAPG10pointsTable1OLEDB.py (drafted by Scott Chang on 5 Feb 2013) # Tips from Wayne Whitley tbl = r"Database Connections\Table1" xc = "X" yc = "Y" zc = "Z" # import system modules import arcpy from arcpy import env out_Layer = "PointLocatiopns_layers" saved_Layer = r"C:\Temp\APF10pointsTable1accdb.shp" # Set the spatial reference spRef = r"Coordinate System\Geographic Coordinate System\World\WGS 1984" # Make the XY Event Layer... arcpy.MakeXYEventLayer_management(tbl, xc, yc, out_Layer, spRef) # Print the total rows print arcpy.GetCount_management(out_Layer) # Save to a layer file arcpy.CopyFeatures_management(out_Layer, saved_Layer) # If an error occurred, print the messgae to the screen print arcpy.GetMessages()
IDLE 2.6.5 >>> import arcpy >>> # my pathname connection via my Catalog defined OLE DB connection to my 2007 Access db: >>> tbl = r'Database Connections\test OLE DB connect 2007 Access.odc\LWRandMIDDLE' >>> # the xc and yc variables for X and Y coords: >>> xc = 'X' >>> yc = 'Y' >>> # the lyr output event >>> out_Layer = r'someTestLayer' >>> # the gdb copy of the lyr >>> saved_fc = r'C:\Documents and Settings\whitley-wayne\Desktop\stage.gdb\FcToDeleteLater' >>> >>> # didn't bother this spRef >>> # ...for now, let's see how input reads >>> arcpy.MakeXYEventLayer_management(tbl, xc, yc, out_Layer) <Result 'someTestLayer'> >>> >>> # apparently that produced a result... >>> # does the layer contain anything? >>> arcpy.GetCount_management(out_Layer) <Result '41'> >>> >>> # Let's copy the result... >>> arcpy.CopyFeatures_management(out_Layer, saved_fc) <Result 'C:\\Documents and Settings\\whitley-wayne\\Desktop\\stage.gdb\\FcToDeleteLater'> >>> >>> # well, that worked too...
>>> # the corrected pathname for the WGS84 prj file >>> spRef = r'Coordinate Systems\Geographic Coordinate Systems\World\WGS 1984.prj' >>> # deleting the out_Layer, from previous execution (see other code window) >>> arcpy.Delete_management(out_Layer) <Result 'true'> >>> # adding the corrected spRef variable parameter >>> arcpy.MakeXYEventLayer_management(tbl, xc, yc, out_Layer, spRef) <Result 'someTestLayer'> >>> # deleting the output fc copy, pre-existing from prior execution >>> arcpy.Delete_management(saved_fc) <Result 'true'> >>> # creating the new fc output, with the spatial ref written to the fc >>> arcpy.CopyFeatures_management(out_Layer, saved_fc) <Result 'C:\\Documents and Settings\\whitley-wayne\\Desktop\\stage.gdb\\FcToDeleteLater'> >>> >>> # success, no missing projection info, no data frame manipulation required!