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

2314
2
Jump to solution
06-04-2018 01:36 PM
DevonCanady
New Contributor II

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");
}
Tags (1)
0 Kudos
1 Solution

Accepted Solutions
RichRuh
Esri Regular Contributor

Hi Devon,

No, you cannot change the spatial reference of a feature class with the C# SDK.  All DDL (data definition language) takes place through Python or geoprocessing.  

The QueryDescription class is used for exposing spatial data as a temporary in-memory table, not for changing what is stored in the geodatabase.

--Rich

View solution in original post

0 Kudos
2 Replies
RichRuh
Esri Regular Contributor

Hi Devon,

No, you cannot change the spatial reference of a feature class with the C# SDK.  All DDL (data definition language) takes place through Python or geoprocessing.  

The QueryDescription class is used for exposing spatial data as a temporary in-memory table, not for changing what is stored in the geodatabase.

--Rich

0 Kudos
DevonCanady
New Contributor II

Ok thanks for your response.

0 Kudos