POST
|
Hi, I want to add a graphics layer in Map. But this layer is lack of Spatial Reference. I cannot specify the spatial reference, because it's property is read only(just get is implemented in the API). Here is xaml (It is generated when I create an ESRI SL Application in Visual Studio)
<esri:Map x:Name="Map" Background="White">
....
....
<esri:Map.Layers>
<esri:ArcGISTiledMapServiceLayer ID="BaseLayer"
Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"/>
</esri:Map.Layers>
</esri:Map>
I want to create Graphics Layer with the following code behind C# code
public GraphicsLayer CreatePointGraphicLayer(string ID,
SpatialReference spatial_reference,
List<double> x_list,
List<double> y_list,
List<string> fields,
List<string[]> other_fields_values)
{
GraphicsLayer graphics_layer = new GraphicsLayer();
graphics_layer.ID = ID;
SimpleMarkerSymbol simple_marker_symbol = new SimpleMarkerSymbol();
simple_marker_symbol.Color = new SolidColorBrush(Colors.Red);
for (int i = 0; i < x_list.Count; i++)
{
Graphic graphic = new Graphic()
{
Symbol = simple_marker_symbol,
Geometry = new MapPoint(x_list, y_list, spatial_reference)
};
for (int j = 0; j < fields.Count; j++)
{
graphic.Attributes[fields ] = other_fields_values ;
}
graphics_layer.Graphics.Add(graphic);
}
return graphics_layer;
}
The code above create the graphics layer and when I put it into Map with the following lines of code, I can see the created graphics but lack of spatial reference.
GraphicsLayer g_layer = CreatePointGraphicLayer(....) //I omit this part
Map.Layers.Add(g_layer);
How can I use spatial reference in graphics layer. Thanks in advance. Kerem.
... View more
05-02-2011
04:04 AM
|
0
|
7
|
8793
|
POST
|
Without more specifics on the relationship classes you want to create, I can't really comment on the data model structure. Your examples, while helpful, don't really demonstrate how you'd like to use the relationship classes. The reason for the usage of relationship classes is the following. Thanks to composite relationship classes, when the source data is deleted, the dependency data is also deleted automatically. In example. When I deleted a person, I want all the Friendship to be deleted automatically. So that I want to create multiple composite relationship classes between them. Thanks. Kerem
... View more
05-02-2011
03:44 AM
|
0
|
0
|
1386
|
POST
|
I'm assuming you're working in ArcMap, If so you can add multiple copies of a single table, shapefile, feature class etc.. Why not import "Friendship" and "Person" twice, assigning your unique relates as desired. Unfortunately, I am not working in ArcMap, I will use these tables in ArcSDE and create a server application. Thanks. Kerem.
... View more
05-02-2011
03:40 AM
|
0
|
0
|
1386
|
POST
|
Thanks for your answer. You say that I cannot create multiple composite relationship-classes between tables/featureclasses. But have can I handle the scenario that I explained in the first post? Do you have any suggestions? Thanks. Kerem.
... View more
04-22-2011
02:12 AM
|
0
|
0
|
1386
|
POST
|
Hi, I have a problem creating multiple relationship-classes. Let me explain the problem with an instance. I have two table called Person (with attributes OBJECTID(By default field), Name, X, Y, Z) and Friendship (with attributes Person1Id, Person2Id, A, B, C). I want to create two relationship classes between these two tables called Person_Friendship1_Rel and Person_Friendship2_Rel. The details for relationship classes : Person_Friendship1_Rel (Origin Table : Person, Destination Table : Friendship, Composite relation, Forward, 1-M relation, Origin primary key field : OBJECTID, Destination foreign key field : Person1Id) Person_Friendship2_Rel (Origin Table : Person, Destination Table : Friendship, Composite relation, Forward, 1-M relation, Origin primary key field : OBJECTID, Destination foreign key field : Person2Id) For these settings I can create first relationship-class (Person_Friendship1_Rel) but after that, I cannot create the second relationship class (Person_Friendship2_Rel). It says : "Failed to create the specified relationship class. The relationship class is incompatible with existing relationship class". I am not sure if geodatabase support this kind of relationship classes. Thanks in advance. Kerem.
... View more
04-20-2011
10:58 PM
|
0
|
8
|
6334
|
POST
|
Not sure if you ever got this working but since your code helped me get adding shapefiles... I figured I would post how I did it.
// Variables
string fullpathToShapefile = "C:\Shared\sample\sample.shp"
string shp_path = Path.GetDirectoryName(fullpathToShapefile); // This will be "C:\Shared\sample"
string shp_name = Path.GetFileNameWithoutExtension(fullpathToShapefile); // this will be "sample"
Type factory_type = Type.GetTypeFromProgID("esriDataSourcesFile.ShapefileWorkspaceFactory");
IWorkspaceFactory ShpWksFact = (IWorkspaceFactory)Activator.CreateInstance(factory_type);
IFeatureWorkspace FeatWks = (IFeatureWorkspace)ShpWksFact.OpenFromFile(shp_path, 0);
IFeatureClass FeatClass = FeatWks.OpenFeatureClass(shp_name);
IFeatureLayer FeatLayer = new FeatureLayerClass();
FeatLayer.FeatureClass = FeatClass;
Hope it helps Thanks for your help kashmir772 but the code snippet you provided does not work for me. There is a problem with IFeatureWorkspace's OpenFromFile function. All I know just an error code (COMException was unhandled "Exception from HRESULT: 0x80040228"). Kerem.
... View more
03-01-2011
05:29 AM
|
0
|
0
|
1026
|
POST
|
Which statement throws the exception? What is the exact string value that is being evaluated with your expression System.IO.Path.GetFileName(sample)? Does it include the .shp extension? If so, try without the .shp extension. The below code snippet states to specify the shapefile name without the extension. Try both ways as a test and make sure you are not missing a close parenthesis: http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#/Get_FeatureClass_From_Shapefile_On_Disk_Snippet/00490000008m000000/ The exception is thrown in the line IFeatureWorkspace workspace = (IFeatureWorkspace)workspace_factory.OpenFromFile(@"C:\Shared\sample\", 0); It says : COMException was unhandled "Exception from HRESULT: 0x80040228" Thanks, Kerem.
... View more
03-01-2011
05:22 AM
|
0
|
0
|
1026
|
POST
|
Finally I solved my problem, I am not sure what the problem is but what I did is just create the line feature class again with fields and the problem is solved. Thanks again for your help. Kerem.
... View more
03-01-2011
04:53 AM
|
0
|
0
|
270
|
POST
|
Does your service contain these editable fields (TypeID, Custom1)? If yes, do they match the data type value (TypeID a number, Custom1 a string)? Kindly inspect the Error in the SaveEditsFailed. Also, you might want to run Fiddler with your app to see how the web request is formed when applying these edits. Looking at your code, I would not advice adding the graphics in the UpdateCompleted event. This event is also raised the first time feature service is querried for existing features and every time you call Update() on the layer. Just to clarify, without the attribute change, you are able to see the newly added features in your service? What version of the API are you using? Can you also share code on how FeatureLayer is created? Thanks. Thanks a lot for your quick response. For fields, they are editable, I re-checked and the data type matched with the feature layer. For UpdateCompleted event, I forgot to add the following line to the f_layer_UpdateCompleted event handler, I usually put (sender as FeatureLayer).UpdateCompleted -= f_layer_UpdateCompleted; in the first line. To prevent feature layer to re-call this event when update function called. I can see the feature I added right after I add them, The API version is 2.1 Creation of feature layer is in the server. I have a SDE database and a Line FeatureClass in it. (The table is registered as versioned) I put the featureclass into an mxd file and published in ArcGIS Server Manager. (I have other layers, I can add new features to them, edit existing features, and delete them without any problem) I add feature layer into my Map with the following xaml code (I set the Url in code behind): <esri:FeatureLayer ID="Links" Opacity="1" DisableClientCaching="True" Where="TypeID = 3" Renderer="{StaticResource BlackRenderer}" /> I have another consideration : When I add feature without Geometry and Symbol attribute set, I can edit the existing feature with the code I posted. I think the problem is in the Geometry setting part. But I could not identified. Thanks again. Kerem.
... View more
02-28-2011
11:23 PM
|
0
|
0
|
270
|
POST
|
Hi, I have a problem about editing my line features in feature layer. I can add line features to featurelayer, but cannot edit its properties.
public void AddFeature()
{
FeatureLayer f_layer = (FeatureLayer)Map.Layers["Links"];
f_layer.DisableClientCaching = true;
f_layer.UpdateCompleted += new EventHandler(f_layer_UpdateCompleted);
f_layer.Update();
}
private void f_layer_UpdateCompleted(object sender, EventArgs e)
{
FeatureLayer feature_layer = (FeatureLayer)Map.Layers["Links"];
ESRI.ArcGIS.Client.Geometry.Polyline line = new ESRI.ArcGIS.Client.Geometry.Polyline();
MapPoint point1 = new MapPoint(35,40,feature_layer.SpatialReference);
MapPoint point2 = new MapPoint(36,41,feature_layer.SpatialReference);
ESRI.ArcGIS.Client.Geometry.PointCollection point_collection = new ESRI.ArcGIS.Client.Geometry.PointCollection();
point_collection.Add(point1);
point_collection.Add(point2);
line.Paths.Add(point_collection);
line.SpatialReference = feature_layer.SpatialReference;
Graphic graph = new Graphic();
graph.Geometry = line;
graph.Attributes["TypeID"] = 2;
graph.Attributes["Custom1"] = "Value";
feature_layer.Graphics.Add(graph);
}
public void EditFeature()
{
FeatureLayer f_layer = (FeatureLayer)Map.Layers["Links"];
f_layer.DisableClientCaching = true;
f_layer.UpdateCompleted += new EventHandler(f_layer_UpdateCompleted);
f_layer.EndSaveEdits += new EventHandler<EndEditEventArgs>(f_layer_EndSaveEdits);
f_layer.SaveEditsFailed += new EventHandler<TaskFailedEventArgs>(f_layer_SaveEditsFailed);
f_layer.Update();
}
private void f_layer_UpdateCompleted(object sender, EventArgs e)
{
FeatureLayer feature_layer = (FeatureLayer)Map.Layers["Links"];
feature_layer.Graphics[0].Attributes["TypeID"] = 3;
feature_layer.Graphics[0].Attributes["Custom1"] = "New Value";
}
private void f_layer_EndSaveEdits(object sender, EndEditEventArgs e)
{
MessageBox.Show("Feature Editted");
}
private void f_layer_SaveEditsFailed(object sender, TaskFailedEventArgs e)
{
MessageBox.Show(e.Error.Message);
}
In the code above I can add feature by AddFeature function without any problem. But when I want to edit the feature I added in EditFeature funtion. After f_layer_UpdateCompleted event handler, I receive Unable to complete operation error message in f_layer_SaveEditsFailed event handler. If you have any idea about the problem, please help me. Thanks in advance. Kerem.
... View more
02-28-2011
01:55 AM
|
0
|
3
|
565
|
POST
|
Hi, I really stuck on this problem. I have to solve it somehow. I need to load shape file programmatically, as explained in the thread above. Please help me. Thanks again. Kerem.
... View more
02-27-2011
11:52 PM
|
0
|
0
|
1026
|
POST
|
Hi, I have a problem with opening shape file. I have a shape file in "C:\Shared\sample\sample.shp" (Of course the other files with extension dbf, prj, sbn, sbx, shp.xml and shx are in the same directory.) When I run the code below, I receive the exception called COMException was unhandled "Exception from HRESULT: 0x80040228". I am running this code in Windows 7 Professional 64bit, ArcGIS 10 Engine and Visual Studio project target platform is x86. If you have any idea, about the problem, please help me. Thanks in advance. Kerem Celik.
Type factory_type = Type.GetTypeFromProgID("esriDataSourcesFile.ShapefileWorkspaceFactory");
IWorkspaceFactory workspace_factory = (IWorkspaceFactory)Activator.CreateInstance(factory_type);
IFeatureWorkspace workspace = (IFeatureWorkspace)workspace_factory.OpenFromFile(@"C:\Shared\sample\", 0);
IFeatureClass feature_class = workspace.OpenFeatureClass(System.IO.Path.GetFileName(sample);
ESRI.ArcGIS.Carto.IFeatureLayer feature_layer = new FeatureLayerClass();
feature_layer.FeatureClass = (IFeatureClass)feature_class;
default_map.AddLayer((ILayer)feature_layer);
... View more
02-22-2011
11:58 PM
|
0
|
9
|
3391
|
POST
|
Thank you very much Jennifer. This information helps a lot. I will take a look at FeatureDataForm. Kerem.
... View more
01-19-2011
05:30 PM
|
0
|
0
|
376
|
POST
|
Thanks a lot Jennifer, the problem is solved 99%. What the1% is that I cannot see the changes immediately. After 1-2 second I can see the changes are made. Let me give you the code:
#region Update
private void btn_save_Click(object sender, RoutedEventArgs e)
{
try
{
FeatureLayer feature_layer = (FeatureLayer)main_page.MapInstance.Layers["Table"];
feature_layer.UpdateCompleted += new EventHandler(feature_layer_UpdateCompleted);
feature_layer.Update();
}
catch (Exception exp)
{
MessageBox.Show(exp.Message);
}
}
private void feature_layer_UpdateCompleted(object sender, EventArgs e)
{
FeatureLayer feature_layer = (FeatureLayer)main_page.MapInstance.Layers["Table"];
int selected_index = cb_rows.SelectedIndex;
feature_layer.Graphics[selected_index].Attributes["id"] = int.Parse(tb_id.Text);
feature_layer.Graphics[selected_index].Attributes["name"] = tb_name.Text;
feature_layer.Graphics[selected_index].Attributes["given_date"] = dp_given_date.SelectedDate;
feature_layer.Graphics[selected_index].Attributes["level"] = (double)nud_level.Value;
cb_rows.Items.Insert(selected_index, tb_id.Text + " - " + tb_name.Text);
cb_rows.Items.RemoveAt(selected_index + 1);
cb_rows.SelectedIndex = selected_index;
btn_save.IsEnabled = false;
}
#endregion
#region Query
private void cb_rows_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (cb_rows.SelectedItem == null)
return;
int selected_index = cb_rows.SelectedIndex;
string table_layer_path = main_page.MainMapLayer + "3";
QueryTask querytask_on_table = new QueryTask(table_layer_path);
querytask_on_table.DisableClientCaching = true;
querytask_on_table.ExecuteCompleted += QueryOnTable_ExecuteCompleted;
querytask_on_table.Failed += QueryTask_Failed;
ESRI.ArcGIS.Client.Tasks.Query query_on_table = new ESRI.ArcGIS.Client.Tasks.Query();
query_on_table.Where = "id = '" + cb_rows.SelectedItem.ToString().Split('-')[0].Trim() + "'";
query_on_table.OutFields.Add("*");
querytask_on_table.ExecuteAsync(query_on_table);
}
public void QueryOnTable_ExecuteCompleted(object sender, ESRI.ArcGIS.Client.Tasks.QueryEventArgs args)
{
IList<Graphic> query_results = null;
FeatureSet feature_set = args.FeatureSet;
if (feature_set != null && feature_set.Features.Count > 0)
query_results = feature_set.Features;
if (query_results != null && query_results.Count == 1)
{
tb_id.Text = int.Parse(query_results[0].Attributes["id"].ToString()).ToString();
tb_name.Text = query_results[0].Attributes["name"].ToString();
dp_given_date.SelectedDate = DateTime.Parse(query_results[0].Attributes["given_date"].ToString());
nud_level.Value = double.Parse(query_results[0].Attributes["level"].ToString());
btn_save.IsEnabled = false;
}
}
#endregion
If you see any problem, please help me about it. Thanks again for your very helpful information.
... View more
01-18-2011
10:47 PM
|
0
|
0
|
376
|
POST
|
Thank you very much Jennifer, the second advise solved my problem perfectly. Now for all the time I can see my records. But there is another problem. I am sure that the records are edited by the code fragment I wrote in the first post. But when I query (by Query_Task) on the same layer, I cannot see the changes. But in ArcCatalog or ArcMap I can see the changes I made. Actually when I re-open the application I can see the changes I have made. But in the same session I cannot see the changes. I tried the following ways; I set the AutoSave Attribute of feature layer true I set the DisableClientCaching Attribute of layer to true. Not : I can add new graphics, and remove existing graphics, the problem is just editing a graphic/record's Attribute. I could not identify the problem. Thanks again. Kerem.
... View more
01-17-2011
09:48 PM
|
0
|
0
|
376
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|