Select to view content in your preferred language

How to obtain feature ID

4859
27
11-16-2010 10:18 AM
DonFreeman
Emerging Contributor
Is there a sample around that shows how to obtain the feature ID (place it into a variable) when the user clicks on a point feature?
Silverlight 4

Thanks
0 Kudos
27 Replies
JenniferNery
Esri Regular Contributor
Kindly refer to this documentation: http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.FeatureSer...

If LayerInfo is retrieved after the layer has initialized so be sure to check that layer.LayerInfo is not null.

The following code retrieves the feature ID:
var id = graphic.Attributes[layer.LayerInfo.ObjectIdField];
0 Kudos
DonFreeman
Emerging Contributor
Kindly refer to this documentation: http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.FeatureSer...

If LayerInfo is retrieved after the layer has initialized so be sure to check that layer.LayerInfo is not null.

The following code retrieves the feature ID:
var id = graphic.Attributes[layer.LayerInfo.ObjectIdField];


Thanks Jenn. I'm afraid that as a beginner I need a little more help than that provides. Working in VB the line
Public ReadOnly Property ObjectIdField As String
 
doesn't tell me anything about how to make the assignment. Something like this is needed.

myVariable = ????
messagebox.show("myVarable = " + myVariable.tostring)

Allso it tells me nothing about the requirements of the service (if there are any). My features are shapefile based.

Thanks
0 Kudos
JenniferNery
Esri Regular Contributor
Oh, the code snippet and documentation I provided is for FeatureLayer, where ObjectIDField will be known after the layer is Initialized and LayerInfo is retrieved.

How are you saving the graphic to your database? How is the object ID created? Do you save the object id as part of the attributes? If yes, then however you named this field, is also the key you used in getting the attribute value.

Same code snippet as my previous post, except you replace the key "layer.LayerInfo.ObjectIdField" with your own name for your object id.
0 Kudos
DonFreeman
Emerging Contributor
Hmmm. . .
I'm not sure I can answer those questions. (Still a very basic beginner here.)
The layer is based on a shapefile ( we absolutely are not ready to deal with geodatabase yet).
The purpose of the project is to allow the user to select a point and edit some (but not all) of the data associated with the point. The data will not be in the attribute table, but will instead be in a related child table (1 to many relationship). So, my thought was to simply obtain the FID of the point and then programmatically construct a query to the related table that will display the records to be edited in some sort of datagrid. The fields to be displayed and edited will be dynamic, hence the need to control it with code rather than a standard tool.

The application is basically a volunteer signup form where users will signup to monitor an intersection for one of the available timeslots during the day. Once a timeslot has been taken it will not be available to other users.

This is my first attempt to work with data in Silverlight so even that is a daunting challenge. Have you a sample that works anything like this?
0 Kudos
JenniferNery
Esri Regular Contributor
I'm sorry I have more questions than answers. I wanted to know how you load shapefiles to your map?  Does it have a corresponding .dbf that holds the attributes of the feature?  I imagine that this is where you'd keep record of the object ID. 

How you create and save the object ID is important to know because it also dictates how you can retrieve them. You can use the graphic's Attributes to hold this information (http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.Graphic~At...).

It says that this is read-only property meaning you cannot create a new instance, but you can update the existing instance. You can do something like:
Graphic g = new Graphic()
{
// set Geometry property from ShapeFile.
}
var objectId; // retrieve from DBF file (?)
g.Attributes["objectid"] = objectId; // to save object id onto an attribute field
var oid = g.Attributes["objectid']; // to retrieve the object id from an attribute field.

Note that in this example, I just used "objectid" as my key for the field. You can name this as you wish but be mindful that the key you used to save is the same key you need to use to retrieve.

Shapefile is actually an unfamiliar territory for me but I found some links that might be useful for your project.
http://esrislcontrib.codeplex.com/
http://forums.arcgis.com/threads/6425-Export-to-shapefile-other-format
http://forums.arcgis.com/threads/13680-Download-Shapefiles-Similar-to-the-Extract-Service-in-ArcIMS

Other developers are welcome to provide additional help 🙂
0 Kudos
DonFreeman
Emerging Contributor
I'm sorry I have more questions than answers. I wanted to know how you load shapefiles to your map?  Does it have a corresponding .dbf that holds the attributes of the feature?  I imagine that this is where you'd keep record of the object ID. 

How you create and save the object ID is important to know because it also dictates how you can retrieve them. You can use the graphic's Attributes to hold this information (http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.Graphic~At...).

It says that this is read-only property meaning you cannot create a new instance, but you can update the existing instance. You can do something like:
Graphic g = new Graphic()
{
// set Geometry property from ShapeFile.
}
var objectId; // retrieve from DBF file (?)
g.Attributes["objectid"] = objectId; // to save object id onto an attribute field
var oid = g.Attributes["objectid']; // to retrieve the object id from an attribute field.

Note that in this example, I just used "objectid" as my key for the field. You can name this as you wish but be mindful that the key you used to save is the same key you need to use to retrieve.

Shapefile is actually an unfamiliar territory for me but I found some links that might be useful for your project.
http://esrislcontrib.codeplex.com/
http://forums.arcgis.com/threads/6425-Export-to-shapefile-other-format
http://forums.arcgis.com/threads/13680-Download-Shapefiles-Similar-to-the-Extract-Service-in-ArcIMS

Other developers are welcome to provide additional help 🙂


Jenn - I'm just getting back to this. The "shapefile" is actually a group of files that contain the feature geometry, projection, metadata, and other info. The attributes are contained in a traditional *.dbf file with a field 'FID' (FeatureID) as the unique identifier that links the feature to the attributes. The shapefile or layer is placed on the map via the service with code like this:
   <!--<esri:Map x:Name="MyMap" Grid.RowSpan="2" >
    <esri:Map.Layers>
     <esri:ArcGISDynamicMapServiceLayer ID="Intersections" 
      Url="http://198.182.104.173/ArcGIS/rest/services/Intersection_Test/MapServer" />
    </esri:Map.Layers>
   </esri:Map> -->
In this case its a point layer. What I want to do is click a point and capture the FID for that point so I can use it to query a separate but related table.
Does that help?
Thanks
0 Kudos
dotMorten_esri
Esri Notable Contributor
Just to be clear: The Client APIs does not support working with Shapefiles. You will need to publish your data to ArcGIS Server first. After that, it doesn't' really matter how the data is stored as long as it is server out using ArcGIS Server. When you are at that point, you will be using a FeatureLayer as Jennifer was getting at.
0 Kudos
DonFreeman
Emerging Contributor
Just to be clear: The Client APIs does not support working with Shapefiles. You will need to publish your data to ArcGIS Server first. After that, it doesn't' really matter how the data is stored as long as it is server out using ArcGIS Server. When you are at that point, you will be using a FeatureLayer as Jennifer was getting at.


Morton -
Yes, I understand that the map needs to be delivered as a service from the server. That is what I have. (See the markup in my previous post.) What I don't understand (very much a beginner) is how or where to go from here. I can click the map point and obtain the datagrid but how can I pick out the FID from it? (and preferrably not display it)
Thanks
0 Kudos
JenniferNery
Esri Regular Contributor
Since you already have a map service, can you use FeatureLayer instead? http://help.arcgis.com/en/webapi/silverlight/help/Creating_featurelayer.htm

There is a MouseLeftButtonDown you can subscribe to, on the Feature Layer itself, this has GraphicMouseButtonEventArgs and you can easily use e.Graphic to identify the feature that was clicked.
0 Kudos