Make XY Event Layer (Data Management)

License Level:BasicStandardAdvanced

Summary

Creates a new point feature layer based on x- and y-coordinates defined in a source table. If the source table contains z-coordinates (elevation values), that field can also be specified in the creation of the event layer. The layer created by this tool is temporary.

Learn more about adding x,y coordinate data to a map

Usage

Syntax

MakeXYEventLayer_management (table, in_x_field, in_y_field, out_layer, {spatial_reference}, {in_z_field})
ParameterExplanationData Type
table

The table containing the X and Y coordinates that define the locations of the point features to create.

Table View
in_x_field

The field in the input table that contains the x-coordinates.

Field
in_y_field

The field in the input table that contains the y-coordinates.

Field
out_layer

The name of the output point event layer.

Feature Layer
spatial_reference
(Optional)

The spatial reference of the coordinates in the X and Y Fields defined above. This will be the output event layer's spatial reference.

Spatial Reference
in_z_field
(Optional)

The field in the input table that contains the z-coordinates.

Field

Code Sample

MakeXYEventLayer example (Python window)

The following Python window script demonstrates how to use the MakeXYEventLayer tool.

import arcpy
arcpy.env.workspace = "C:/data"
arcpy.MakeXYEventLayer_management("firestations.dbf", "POINT_X", "POINT_Y", "firestations_points","", "POINT_Z")
MakeXYEventLayer example (stand-alone script)

The following stand-alone Python script demonstrates how to use the MakeXYEventLayer tool.

# MakeXYLayer.py
# Description: Creates an XY layer and exports it to a layer file

# import system modules 
import arcpy
from arcpy import env

# Set environment settings
env.workspace = "C:/data"
 
try:
    # Set the local variables
    in_Table = "firestations.dbf"
    x_coords = "POINT_X"
    y_coords = "POINT_Y"
    z_coords = "POINT_Z"
    out_Layer = "firestations_layer"
    saved_Layer = r"c:\output\firestations.lyr"
 
    # Set the spatial reference
    spRef = r"Coordinate Systems\Projected Coordinate Systems\Utm\Nad 1983\NAD 1983 UTM Zone 11N.prj"
 
    # Make the XY event layer...
    arcpy.MakeXYEventLayer_management(in_Table, x_coords, y_coords, out_Layer, spRef, z_coords)
 
    # Print the total rows
    print arcpy.GetCount_management(out_Layer)
 
    # Save to a layer file
    arcpy.SaveToLayerFile_management(out_Layer, saved_Layer)
 
except:
    # If an error occurred print the message to the screen
    print arcpy.GetMessages()

Environments

Related Topics

Licensing Information

ArcGIS for Desktop Basic: Yes
ArcGIS for Desktop Standard: Yes
ArcGIS for Desktop Advanced: Yes
5/7/2015