The Esri Community
GeoNet Resource Hub
to create and rate content, and to follow, bookmark, and share content with other members.
Convert from text file to shape file
Discussion created by
on Aug 4, 2013
on Oct 30, 2013 by FGibson-esristaff
Show 0 Likes
Hi, can anybody help me to write a C# program which converts text file(it is having X,Y coordinates) to shape file using arcobjects
This content has been marked as final.
Show 2 comments
(Required, will not be published)
Aug 5, 2013 6:54 AM
You could do the following:
- First, you create a layer based on your xy data:
- Then, you export your layer to a shapefile:
Does this help?
Show 0 Likes
Oct 30, 2013 9:57 AM
The programmatic workflow for this would be the same as when using ArcGIS Desktop. You'll want to 1) Convert the text file to an XY Event Layer and 2) export the Event Layer to a valid feature class format. The hardest part will be part one, as such I've written a quick example of how I'm able to accomplish this with a text file.
The below code will show you how to create the XY event layer and get a reference to IFeatureClass. After doing this you'll want to decide on if you want to use pure ArcObjects or the Geoprocessing framework to export the feature class to your needed format. For example, you could use IFeatureDataConvertor or you use use Geoprocessing tools like FeatureClassToFeatureClass_conversion or CopyFeatures_management. I have pasted links that discuss this workflows below the code.
private static void Main()
ISpatialReference pSpatialReference = CreateSpatialReference(esriSRGeoCSType.esriSRGeoCS_WGS1984);
ITable pTable = OpenTextTable(TxtFile);
IFeatureClass pFeatureClass = CreateXyEventFeature(pTable, "LONGITUDE_X", "LATITUDE_Y", pSpatialReference);
private static ITable OpenTextTable(string txtPath)
string tablePath = System.IO.Path.GetDirectoryName(txtPath);
string tableName = System.IO.Path.GetFileName(txtPath);
IWorkspaceFactory pWorkspaceFactory = new TextFileWorkspaceFactoryClass();
IFeatureWorkspace pFeatureWorkspace = (IFeatureWorkspace) pWorkspaceFactory.OpenFromFile(tablePath, 0);
private static IFeatureClass CreateXyEventFeature(ITable table, String xField, String yField, ISpatialReference spatialReference)
IXYEvent2FieldsProperties pXyEvent2FieldsProperties = new XYEvent2FieldsPropertiesClass()
XFieldName = xField,
YFieldName = yField
IName pName = ((IDataset) table).FullName;
IXYEventSourceName pXyEventSourceName = new XYEventSourceNameClass()
EventProperties = pXyEvent2FieldsProperties,
EventTableName = pName,
SpatialReference = spatialReference
pName = (IName) pXyEventSourceName;
IXYEventSource pXyEventSource = (IXYEventSource) pName.Open();
IFeatureClass pFeatureClass = (IFeatureClass) pXyEventSource;
private static ISpatialReference CreateSpatialReference(esriSRGeoCSType coordSystem)
ISpatialReferenceFactory pSpatialReferenceFactory = new SpatialReferenceEnvironmentClass();
ISpatialReferenceResolution pSpatialReferenceResolution =
pSpatialReferenceFactory.CreateGeographicCoordinateSystem(Convert.ToInt32(coordSystem)) as ISpatialReferenceResolution;
ISpatialReferenceTolerance pSpatialReferenceTolerance =
pSpatialReferenceResolution as ISpatialReferenceTolerance;
ISpatialReference pSpatialReference = pSpatialReferenceResolution as ISpatialReference;
*** Additional Resources ***
Converting simple data
How to run a geoprocessing tool
Show 0 Likes
Retrieving data ...
ArcGIS Pro RasterCalc Tool Map Algebra Expression Proper Syntax through code
Best Solution for old tool to be used in ArcPro
Collector - The Aurora Project
Is it possible to specify fields to create feature class with?
ArcGIS is the worst software I currently use...