Using C# code, convert the XYEvent layer to a shapefile. Add the created shapefile to the map.
I have already created the XY event layer with the following code:
public void XYEvent()
{
//http://edndoc.esri.com/arcobjects/9.0/samples/tables/create_a_layer_based_on_xy_data.htm
IMxDocument mxdoc = ArcMap.Application.Document as IMxDocument;
IMap map = mxdoc.FocusMap;
// Get the table named XYSample.txt
IStandaloneTableCollection stTableCollection = map as IStandaloneTableCollection;
IStandaloneTable standaloneTable = null;
ITable table = null;
//Error check to make sure the table has been added before the event is created
for (int i = 0; i < stTableCollection.StandaloneTableCount; i++)
{
standaloneTable = stTableCollection.StandaloneTable[i];
if (standaloneTable.Name == "ONT_Stations")
{
table = standaloneTable.Table;
break;
}
}
if (table == null)
{
MessageBox.Show("ONT_Stations table was not found in this map.");
return;
}
// Get the table name object
IDataset dataset = table as IDataset;
IName tableName = dataset.FullName;
// Specify the X and Y fields
IXYEvent2FieldsProperties xyEvent2FieldsProperties = new XYEvent2FieldsProperties() as IXYEvent2FieldsProperties;
xyEvent2FieldsProperties.XFieldName = "LATITUDE_DECIMAL_DEGREES";
xyEvent2FieldsProperties.YFieldName = "LONGITUDE_DECIMAL_DEGREES";
xyEvent2FieldsProperties.ZFieldName = "ELEVATION";
// Specify the projection
//Projection found at: http://edndoc.esri.com/arcobjects/9.1/ComponentHelp/esriGeometry/esriSRGeoCSType.htm
ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironment() as ISpatialReferenceFactory;
IGeographicCoordinateSystem geographicCoordinateSystem = spatialReferenceFactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_NAD1983);
// Create the XY name object as set it's properties
IXYEventSourceName xyEventSourceName = new XYEventSourceName() as IXYEventSourceName;
xyEventSourceName.EventProperties = xyEvent2FieldsProperties;
xyEventSourceName.SpatialReference = geographicCoordinateSystem;
xyEventSourceName.EventTableName = tableName;
IName xyName = xyEventSourceName as IName;
IXYEventSource xyEventSource = xyName.Open() as IXYEventSource;
IFeatureLayer featureLayer = new FeatureLayer() as IFeatureLayer;
featureLayer.FeatureClass = xyEventSource as IFeatureClass;
featureLayer.Name = "ONT_Stations_Events";
//Add layer to map
map.AddLayer(featureLayer);
mxdoc.ActiveView.Refresh();
}