I have created a feature class with the code below, but it creates it with an Unknown Spatial Reference. I know you can use other shapefiles/prj files as input to the Create Feature Class geoprocessing tool, but I'm trying to avoid creating a template for every spatial reference I might end up needing. I would rather be able to set the spatial reference from C# code after it's created. I've learned of a QueryDescription, via Database.GetQueryDescription() but the datastore is a FileGeodatabase, not an sde.
public async Task<string> CreateTargetPoint()
{
string tool_path = @"management.CreateFeatureClass";
string outpath = Project.Current.DefaultGeodatabasePath;
var args = Geoprocessing.MakeValueArray(outpath, "target_point", "POINT");
var result = await Geoprocessing.ExecuteToolAsync(tool_path, args);
return result.ReturnValue;
}
var result = await CreateTargetPoint();
var gdbPath = new FileInfo(result).Directory;
var connectionPath = new FileGeodatabaseConnectionPath(new Uri(gdbPath.FullName));
using (var geodatabase = new Geodatabase(connectionPath))
using (var featureClass = geodatabase.OpenDataset<FeatureClass>("target_point"))
{
var fcDef = featureClass.GetDefinition();
var rowBuffer = featureClass.CreateRowBuffer();
rowBuffer[fcDef.GetShapeField()] = centerpoint;
featureClass.CreateRow(rowBuffer);
viewModel.TargetSite = LayerFactory.Instance.CreateFeatureLayer(featureClass, exportMap, 0, "Target Site");
}