Select to view content in your preferred language

Problem selecting features from a Feature Layer

3823
6
12-05-2010 12:55 PM
GrantCarroll
Deactivated User
Hi All

What I'm trying to do is link to feature from a database, so I search for features using a query task and get returned a feature set. What I need to do then is select the returned feature,(there should only be one), and then start editing its vertices.

I have an Editor object and i should be able to use Editor.EditVertices.Execute("myGraphic"). However I get an argument exception when I do this. It seems that when I select the feature, I'm not selecting the feature on the layer, just a copy of it. So my question is, what is the best way to programmatically select a feature based on an attribute, from a feature layer, so that I can then pass that feature to the edit vertices method ? Any suggestions would be greatly appreciated, I'm probably missing something obvious ??

Thanks

Grant
0 Kudos
6 Replies
JenniferNery
Esri Regular Contributor
When you edit a feature returned by QueryTask, you are not affecting the same instance contained in your FeatureLayer. You need to edit features from your FeatureLayer.Graphics. Maybe make a comparison (LINQ query?) in the ExecuteCompleted event to get the actual graphic.

Also, if you have to call EditVertices in code, know that this is only supported for Polyline and Polygon geometries.
string objId = MyFeatureLayer.LayerInfo.ObjectIdField;
Graphic graphic = from MyFeatureLayer.Graphics
                        where g.Attributes[objId] == e.FeatureSet.Attributes[objId]
                        select g;     
if(Editor.EditVertices.CanExecute(graphic))
           Editor.EditVertices.Execute(graphic)


To know if the edit is applied on your FeatureLayer, you can subscribe to the following events:
http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.FeatureLay...
http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.FeatureLay...

If edits seem to complete and save properly but you are not able to see the changes, set DisableClientCaching to true.
http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.FeatureLay...
0 Kudos
GrantCarroll
Deactivated User
Hi Jennifer

Thanks for the code, I was getting and invalid cast error when trying to return the result to the a Graphic. I can get around this by assigning the result to an IEnumerable(Of Graphic) (Which works). However it looks as though the number of features being returned is being limited to 1000. I can prove this by running through the graphics on the layer and watching it exit at the loop after 1000 iterations. The feature I have been testing against has an ObjectID of 1406 so it seems its not being pulled through, as the count on the IEnumerable is 0. When I hard code the ObjectID to 1, it works though and pulls back a Graphic.

So I guess the next question is, how do I ensure I'm selecting over all features rather than just the first 1000 in a layer. I have tried increasing the OnDemandCache size but it doesn't seem to help. Any further help would be greatly appreciated.

Again thanks for the code, I was sure there would be a way to do it with something like LINQ, but I'm not the skilled with it.

Cheers
0 Kudos
JenniferNery
Esri Regular Contributor
Oh sorry I missed that. You are right the LINQ query will return an IEnumerable<Graphics>.

So the QueryTask must return one graphic and you want to get the graphic with the same ID from the FeatureLayer, is that right? If this is the case the same code applies with slight modification:
string objId = MyFeatureLayer.LayerInfo.ObjectIdField;
object id = e.FeatureSet.Attributes[objId];
Graphic graphic = (from MyFeatureLayer.Graphics
                        where g.Attributes[objId] == id
                        select g).First();     
if(Editor.EditVertices.CanExecute(graphic))
           Editor.EditVertices.Execute(graphic)


While in debug mode, check if "id" has the expected value. Make sure that the Query OutFields include the ObjectIdField.

Your FeatureLayer is OnDemand Mode? You can refer to this help doc to find which QueryMode to use: http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.FeatureLay...
0 Kudos
GrantCarroll
Deactivated User
Thanks for the updated Code. It works nicely, however I still have the issue where it looks like the Feature Layer is not searching over all features, only the first 1000. Am I missing a parameter or something here ? When I look at the layer in ArcMap it has 2119 features, but when I look at Count field of GraphicsCollection associated with the Feature Layer, its only 1000. It almost seems like its being limited to this. I have set the mode to snapshot also, so it should be grabbing all the features ?? Also I am returning all fields and as I said when I hard code an objectid of "1" the LINQ query works, it just seems like it won't return anythign with an ObjectID over 1000.

Again thanks for all the help.

Cheers
0 Kudos
AliMirzabeigi
Emerging Contributor
This is because you have hit the maximum number of records that could be returned by your service (default is 1000 in version 10). You can either increase this value using Server Manager (under "Parameters" tab look for "Maximum Number of Records Returned by Server" at the end of the panel) or use the OnDemand mode for your FeatureLayer (see SDK sample here: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#FeatureLayerOnDemand).
0 Kudos
GrantCarroll
Deactivated User
Perfect !!

Thank you both so much, you have saved me a lot of head banging.

Cheers and have a good xmas.
0 Kudos