add a feature to my feature class

07-20-2017 08:01 AM
New Contributor III

Hello every one ,

I'm trying to add a 2D feature (polygon) to my feature layer using ServiceFeatureTable  so i tried to  let the user to click the map   to specify a new feature's location by listening to a click event on your map view, which in turn will call a function for adding a new feature. but my method doesn't seems good enough to work here's my code 

  public MainWindow()
MyMapView.Map = new Map(Basemap.CreateTopographic());
MyMapView.GeoViewTapped += MymapView_GeoViewTapped;


private async void MymapView_GeoViewTapped(object sender, Esri.ArcGISRuntime.UI.Controls.GeoViewInputEventArgs e)
//get the click point in geographic coordinates
var mapClickPoint = e.Location;
var pointCollection = new Esri.ArcGISRuntime.Geometry.PointCollection(SpatialReferences.Wgs84);
pointCollection.Add(-109.048, 40.998);
pointCollection.Add(-102.047, 40.998);
pointCollection.Add(-102.037, 36.989);
pointCollection.Add(-109.048, 36.998);

//create a new polygon from the point collection

var polygon = new Esri.ArcGISRuntime.Geometry.Polygon(pointCollection);

var mapService = new LocalFeatureService(@"C:\Users\lolo\Documents\ArcGIS\3Dservitude.mpk");
await mapService.StartAsync();
var featureTable2DUri = new System.Uri($"{mapService.Url}/1");
var featureTable = new ServiceFeatureTable(featureTable2DUri);
await featureTable.LoadAsync();
//call the function that will add the new feature at this location
AddNewFeature(featureTable, mapClickPoint, 2018, polygon, 7000, 70000);


private async void AddNewFeature( ServiceFeatureTable featureTable,MapPoint location ,int servitude , Esri.ArcGISRuntime.Geometry.Polygon poly,int area , int lenght)

var attributes = new Dictionary<string, object>();
attributes.Add("servitude", servitude);
attributes.Add("polygone", poly);
attributes.Add("area", area);
attributes.Add("lenght", lenght);

//create a new feature in the GEOM2DServitudeGabarit table , pass in the attributes and geometry

var template = featureTable.FeatureTemplates.FirstOrDefault() ?? featureTable.FeatureTypes.FirstOrDefault(t => t.Templates.Any())?.Templates?.FirstOrDefault();
var newFeature = featureTable.CreateFeature(attributes, location);
await featureTable.AddFeatureAsync(newFeature);
var layer = new FeatureLayer(featureTable);

//push this update (apply edit) to the feature service
IReadOnlyList<EditResult> editResults = await featureTable.ApplyEditsAsync();
// check the results for errors
foreach (var r in editResults)
if (r.CompletedWithErrors)
Console.WriteLine("Edit to Object '" + r.ObjectId + "' failed: " + r.Error.Message);


i have a problem with (var newFeature = featureTable.CreateFeature(attributes, location);) looks doesn't support it although i have the right type parameters .and my code doesn't do any thing i join my mpk file .Any one can help please

thanks in advanced


0 Kudos
4 Replies
Occasional Contributor III

Hi Manel,

I don't think LocalFeatureService yet has the capability of editing the feature from mpk. If you capture the url of the local feature service, only supported operation is the "Query". So it doesn't have the editing capabilities. 



New Contributor III

Hello Yasmin;

Thanks for your answer , i realy need to add feature to my featureLayers using serviceFeatureTables (from .mpk file) , and i don't know why ArcMap guives me only the query support when i generate .MPK ?help please

Thanks in advanced


0 Kudos
New Contributor III

hi Yasmin ,

Okay now i understand , it's because of my basic licence of ArcMap  that i use to generate my .mpk  do you think that if i change the licence to standard will give me the ability to edit the features ? thanks in advance


0 Kudos
New Contributor III

Hello ,

i want to know with what i can replace  (.mpk) to access to my geodatabase and edit features , knowing that i don't have arcGis pro so i can't use (.mmpk) 


0 Kudos