AnsweredAssumed Answered

Unable to add a new feature into a Layer which has Join to other table

Question asked by naresh.nagandla on Jul 11, 2019
Latest reply on Jul 23, 2019 by sean_jones-esristaff

Hi,

 

Below code works if my Featureclass is not joined with any other Table. 

 

If I add a join to other Table, then it throws an "DataSet does not have a valid definition" expection in featureClass.GetDefinition() line. 

 

I believe it is not able to get the FeatureClassdefinition when it is joined with other table.

 

If it is not joined then it can get the FeatureClassDefinition and no problem in adding a new record.

 

Does anyone else have this scenario??  Can you please let me know how to resolve this??

 

 

Below is the code used to insert a record into a FeatureClass.

 

// Check for an active mapview
if (MapView.Active == null)
{
ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("No MapView currently active. Exiting...", "Info");
return;
}

QueuedTask.Run(() =>
{

// Get the layer selected in the Contents pane, and prompt if there is none:
if (MapView.Active.GetSelectedLayers().Count == 0)
{
ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("No feature layer selected in Contents pane. Exiting...", "Info");
return;
}
// Check to see if there is a selected feature layer
var featLayer = MapView.Active.GetSelectedLayers().First() as FeatureLayer;
if (featLayer == null)
{
ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("A feature layer must be selected. Exiting...", "Info");
return;
}

 

try
{

 

//Create the edit operation
var createOperation = new ArcGIS.Desktop.Editing.EditOperation();
createOperation.Name = "Generate points";
createOperation.SelectNewFeatures = false;

 

// get the feature class associated with the layer
var featureClass = featLayer.GetFeatureClass() as FeatureClass;

 

// retrieve the class definition of the point feature class
var classDefinition = featureClass.GetDefinition() as FeatureClassDefinition;

 

// store the spatial reference as its own variable
var spatialReference = classDefinition.GetSpatialReference();

 

 

// determine the shape field name - it may not be 'Shape'
string shapeField = featLayer.GetFeatureClass().GetDefinition().GetShapeField();

 

var mpbuilder = new MapPointBuilder();

mpbuilder.X = Convert.ToDouble(_dblLong);
mpbuilder.Y = Convert.ToDouble(_dblLat);

 

//Create the point geometry
ArcGIS.Core.Geometry.MapPoint newMapPoint = ArcGIS.Core.Geometry.MapPointBuilder.CreateMapPoint(mpbuilder.X, mpbuilder.Y, spatialReference.Wkid);

 

// include the attributes via a dictionary
var atts = new Dictionary<string, object>();
atts.Add("SITE", _txtSiteNumber);
atts.Add("SEQ", _txtSeqNumber);
atts.Add("LATITUDE", _dblLat);
atts.Add("LONGITUDE", _dblLong);
atts.Add(shapeField, newMapPoint);

 

// queue feature creation
createOperation.Create(featLayer, atts);
createOperation.Execute();

 

}
catch (Exception exc)
{
// Catch any exception found and display a message box.
ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Exception caught while trying to create Feature: " + exc.Message);
return;
}

});

Outcomes