HOW TO

Use the Project tool with ArcObjects

Last Published: April 25, 2020

Summary

Instructions provided describe how to use the ArcObjects Project tool in a loop so feature classes can be re-projected all at once.

Procedure

The code below can be used to convert all feature classes in an SDE Geodatabase (of the same projection). The converted feature classes output to a file geodatabase with a different projection.


Code:
public void ReprojectSDE()
{
Geoprocessor gp = new Geoprocessor();
gp.SetEnvironmentValue("workspace", @"Database Connections\StringTreeSQLExpress.sde");

IGpEnumList files = gp.ListFeatureClasses("*", "", "");
string file = files.Next();

IGpEnumList dfiles = gp.ListDatasets("*", "");
string dfile = dfiles.Next();

while (file != "")
{


Debug.WriteLine(file);

string f_in = file;
//clean up the fc file name so it does not include the chinadoll.sde part
string f_prep = doSplit(file);
string f_out = @"C:\temp\test.gdb\" + f_prep + "_projected";
string sys_out = @"C:\Program Files\ArcGIS\Coordinate Systems\Projected Coordinate Systems\UTM\NAD 1983\NAD 1983 UTM Zone 11N.prj";
string geo = "NAD_1983_To_WGS_1984_1";
Project project = new Project();
project.in_dataset = file;
project.out_coor_system = sys_out;
project.out_dataset = f_out;
project.transform_method = geo;

IGeoProcessorResult gpresult = gp.Execute(project, null) as IGeoProcessorResult;

if (gpresult.MessageCount > 0)
{

for (int Count = 0; Count <= gpresult.MessageCount - 1; Count++)
{

Console.WriteLine(gpresult.GetMessage(Count));

}

}
file = files.Next();
}

while (dfile != "")
{
Debug.WriteLine(dfile);
dfile = dfiles.Next();
}
}

public string doSplit(string str)
{
string[] ar = new string[3];
char[] val = { '.' };
ar = str.Split(val);
string name = ar[2].ToString();
return name;
}

}

Article ID:000010852

Software:
  • ArcMap 9 x

Receive notifications and find solutions for new or common issues

Get summarized answers and video solutions from our new AI chatbot.

Download the Esri Support App

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options