AnsweredAssumed Answered

How to set Spatial Reference of Feature Class - ArcGIS Pro SDK

Question asked by devonc1301 on Jun 4, 2018
Latest reply on Jun 8, 2018 by devonc1301

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;
    viewModel.TargetSite = LayerFactory.Instance.CreateFeatureLayer(featureClass, exportMap, 0, "Target Site");