HOW TO
Instructions provided describe how to use the ArcObjects Project tool in a loop so feature classes can be re-projected all at once.
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
Get help from ArcGIS experts
Download the Esri Support App