To add a AGSFeature in AGSFeatureLayer

495
9
Jump to solution
05-07-2018 06:02 AM
MuruganandhamKuppan1
New Contributor III

'AGSFeatureLayer' is loaded using a url from the arcgis server. Now, i would like to add a 'AGSFeature' in 'AGSFeatureLayer'. Is it possible to add a 'AGSFeature' in a 'AGSFeatureLayer' locally or, whether i need to use 'AGSGraphicOverlay' to accomplish that. 

Kindly advice. Also give some example.

#2 Is the following way is right one to create AGSGraphic from a AGSFeature?

    AGSSymbol * symbol = [self.graphic.featureTable.featureLayer.renderer symbolForFeature:self.feature];

    AGSGraphic * graphicObj = [[AGSGraphic alloc] initWithGeometry:self.feature.geometry symbol:symbol  attributes:self.feature.attributes];

 

#3 and i tried the following way to add a feature in feature table, but nothing happens

[layr.featureTable addFeature:data completion:^(NSError * _Nullable error) {

        if(error)

        {

            nlog(@"error: %@",error.localizedFailureReason);

        }   

    }];

0 Kudos
1 Solution

Accepted Solutions
Nicholas-Furness
Esri Regular Contributor

Hi,

You don't need to use an AGSGraphic to create a new feature.

The pattern is:

  1. Create a new feature on the AGSFeatureTable with geometry and attributes using AGSFeatureTable.createFeature().
  2. Add the feature to the AGSFeatureTable using AGSFeatureTable.add().

See Edit features—ArcGIS Runtime SDK for iOS | ArcGIS for Developers.

Since you are working with a server (and not local data), then there is one more call to make to push your add to the server, namely applyEdits. The applyEditsWithCompletion() function is found on AGSServiceFeatureTable (and since you created your feature layer with a URL to a service, the AGSFeatureLayer.featureTable property will be an AGSServiceFeatureTable). See the Edit features (connected) sample, in particular the applyEdits call.

This should get you going.

View solution in original post

9 Replies
Nicholas-Furness
Esri Regular Contributor

Hi,

You don't need to use an AGSGraphic to create a new feature.

The pattern is:

  1. Create a new feature on the AGSFeatureTable with geometry and attributes using AGSFeatureTable.createFeature().
  2. Add the feature to the AGSFeatureTable using AGSFeatureTable.add().

See Edit features—ArcGIS Runtime SDK for iOS | ArcGIS for Developers.

Since you are working with a server (and not local data), then there is one more call to make to push your add to the server, namely applyEdits. The applyEditsWithCompletion() function is found on AGSServiceFeatureTable (and since you created your feature layer with a URL to a service, the AGSFeatureLayer.featureTable property will be an AGSServiceFeatureTable). See the Edit features (connected) sample, in particular the applyEdits call.

This should get you going.

View solution in original post

MuruganandhamKuppan1
New Contributor III

Hello Nick,

Thanks for the reply. I have used as per the pattern. I have checked 'canUpdateFeature()' method before adding into feature layer, it returns 'NO'. So i removed the condition and created, added a feature in a feature layer. The statements are running successfully, but the added feature is not visible in the feature layer. Im facing the problem in some features, but rest of the feature are working great. No idea what is wrong.

0 Kudos
MuruganandhamKuppan1
New Contributor III

Hello  Nick, 

If i used apply edits, the feature is added in server and displays in feature layer. But i don't know why it was not displayed before applying applyedits. FYI, But some feature does.

0 Kudos
Nicholas-Furness
Esri Regular Contributor

For anyone else following the thread…

After some discussion offline it turns out the layer had a definitionExpression on it which the newly added feature didn't match. So, the new feature was being added to the feature service OK, but was not being displayed in the map.

Glad we were able to figure this out, Muruganandham Kuppan!

MuruganandhamKuppan1
New Contributor III

Hi Nick,

The method 

-(AGSFeature *)createFeatureWithAttributes:(NSDictionary<NSString*,id> *)attributes geometry:(nullable AGSGeometry *)geometry;

returns the  OBJECTID as <Null> in attributes of the created feature, but in the previous version it returned as -1, -2, etc., Any suggestions?

Regards,

0 Kudos
Nicholas-Furness
Esri Regular Contributor

Hi Muruganandham Kuppan,

When you call createFeature() you will get an AGSArcGISFeature back. But until you call applyEdits(), that feature just exist locally and does not have an ID that you should use.

Once you call applyEdits() to write the feature to the service, then there will be an ID to use. Call AGSArcGISFeature.refreshObjectID() on your handle to the feature to populate the OBJECTID.

Cheers,

Nick

0 Kudos
Nicholas-Furness
Esri Regular Contributor

Hi,

You should check the canAddFeature property if you're adding rather than canUpdateFeature.

Once you call addFeature:completion: you should see the new feature in the map view. Which version of the Runtime SDK are you using?

0 Kudos
MuruganandhamKuppan1
New Contributor III

Hi, 

The runtime SDK version is 100.1. and i checked 'canAddFeature', its returning true.

May be update of SDK will fix the problem?

0 Kudos
Nicholas-Furness
Esri Regular Contributor

Could you try that please? Try with the current release (100.2.1).

If you still have problems, let's move to DM and investigate your service and your code to try to build a repro case.

0 Kudos