Select to view content in your preferred language

How to save the feature in featurelayer back to geometry service?

752
3
12-02-2010 07:10 AM
DanDong
Deactivated User
Hi all,

Right now I have a feature in the featurelayer (the feature is stored in the Graphics collection), I want to save this feature into geometry service. Any suggestions on how to do this part? Thank you so much 🙂
0 Kudos
3 Replies
JenniferNery
Esri Regular Contributor
I'm not sure I understand your question.

Geometry Service do not have features and therefore do not have a concept of saving features.

Maybe there's confusion here. You can look at the following documentation: http://help.arcgis.com/en/arcgisserver/10.0/help/arcgis_server_dotnet_help/index.html#//009300000027...
0 Kudos
DanDong
Deactivated User
I'm not sure I understand your question.

Geometry Service do not have features and therefore do not have a concept of saving features.

Maybe there's confusion here. You can look at the following documentation: http://help.arcgis.com/en/arcgisserver/10.0/help/arcgis_server_dotnet_help/index.html#//009300000027...


Thanks Jennifer! I think I got you point. I made a mistake here.

Actually, since I still can't find out how to save the data in a collection(featureset) into SDE, My friends suggested that:
1. Create a layer in the mxd file, which serves as the layer to which drawn polygons will be inserted and have it published in the service.
2. create a new polygon, copy all points of the drawn polygon to the newly created polygon. Create a Graphic object, assign the newly polygon to the graphic's geometry property, assign values to the graphic's attributes, which can be known from the feature layer's LayerInfo attribute, and add the graphic object to the Graphics collection of the feature layer.
3. Call the feature layer's save function to save the feature back to the geometry service.

He thinks once a feature has been written to the service, it is also written to the SDE. So I did according to what he said.

ESRI.ArcGIS.Client.Geometry.Polygon insertPolygon = new ESRI.ArcGIS.Client.Geometry.Polygon();  //create a new polygon
insertPolygon.Rings.Add(pPointCollection);  //copy all points of the drawn polygon to the newly created polygon
ESRI.ArcGIS.Client.FeatureLayer myFeatureLayer = MyMap.Layers["MyFeatureLayer"] as FeatureLayer; //declear a featurelayer

ESRI.ArcGIS.Client.Graphic insertGraphic = new ESRI.ArcGIS.Client.Graphic() //Create a Graphic object
      {
            Geometry = insertPolygon,   //assign the newly polygon to the graphic's geometry property
            Attributes = myFeatureLayer.LayerInfo    //assign values to the graphic's attributes, which can be known from the feature layer's LayerInfo attribute  
       };

myFeatureLayer.Graphics.Add(insertGraphic); //add the graphic object to the Graphics collection of the feature layer


In the last line of the codes, I think I have add this polygon and it's attribute to the featurelayer that I published in the service. So that should mean I have saved this polygon. I am not sure whether I am correct. What do you think? Thank you!
0 Kudos
JenniferNery
Esri Regular Contributor
I don't think this code will compile
  Attributes = myFeatureLayer.LayerInfo


Attributes is read-only you cannot change this instance but you can modify it's contents by
graphic.Attributes["fieldname"] = value;
Also the types do not match. Attributes is of type IDictionary<string, object> http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.Graphic~At... and LayerInfo is of type FeatureLayerInfo http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.FeatureSer....

Post #10 in this thread might help http://forums.arcgis.com/threads/15718-failed-to-show-attribute-window-when-add-new-feature-by-selec.... Note that this will only work if the field is nullable. I think it's best to know the type of the field and default value for the type. http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.Field_memb...

foreach (var field in Layer.LayerInfo.Fields)
{
            // check field properties here (Editable / Nullable/ Type) 
            //so you can decide what value to give each attribute
}


By the way, how are you getting "pPointCollection" ?

Since you already have a feature layer that updates features in your feature service. Would it not be easier to use TemplatePicker to draw and add the features?
0 Kudos