POST
|
MDruzgala, Thanks for the tips! Those little things I'm still learning.
... View more
02-15-2013
06:29 AM
|
0
|
0
|
643
|
POST
|
No worries! I think I figured it out. It might not be the most efficient coding but here is what I came up with! public IFeatureLayer GetFeatureLayer(string layerName) { try { IMap map = ArcMap.Document.FocusMap; //Bail if map has no layers. if (map.LayerCount == 0) { MessageBox.Show("There are no layers importerd. Please add Layers and try again"); IFeatureLayer layer = null; return layer; } //Fetch all the feauture layers in the focus map //to determine if at least one is selectable IUID uid = new UIDClass(); uid.Value = "{40A9E885-5533-11D0-98BE-00805F7CED21}"; IEnumLayer enumLayer = map.get_Layers((UID)uid, true); enumLayer.Reset(); IFeatureLayer featureLayer = (IFeatureLayer)enumLayer.Next(); while (featureLayer != null) { if (featureLayer.Name.ToString() == layerName) { return featureLayer; } else { featureLayer = (IFeatureLayer)enumLayer.Next(); } } IFeatureLayer layer2 = null; return layer2; } catch (Exception ex) { MessageBox.Show(ex.StackTrace); IFeatureLayer layer = null; return layer; } }
... View more
02-14-2013
11:02 AM
|
0
|
0
|
643
|
POST
|
Perfect thank you! I am getting errors involving the if statement, if (map.getLayer(i).getName().equalsIgnoreCase(layerName)). I am getting errors: 'ESRI.ArcGIS.Carto.ILayer.Name.get': cannot explicitly call operator or accessor error 'ESRI.ArcGIS.Carto.IMap' does not contain a definition for 'getLayer" and no extension method 'getLayer' accepting a first argument of type 'ESRI.ArcGIS.Carto.IMap' could be found. I can get map.get_Layer(i).Name.Equals(layerName); but I am still getting the error 'ESRI.ArcGIS.Carto.ILayer.Name.get': cannot explicitly call operator or accessor. I was wondering how to get around this? Also, I was wondering what reference you use for AutomationException. I have been looking around on the internet but am failing to find it.
... View more
02-14-2013
09:11 AM
|
0
|
0
|
643
|
POST
|
I am trying to create a method where I am able to select a specific layer and return the IFeatureClass of that layer. I used a return type double and it returns the correct value: 50. I would normally have return featureclass; but I am using the double to test the logic. I am unsure of when I would normally return 0, how I return an IFeatureClass. I am going to use this method to select two different featureclasses for spatial queries. Any suggestions from how to solve this problem to critiques on my coding techniques will be greatly appreciated! Below is the code I currently have: public double GetFeatureLayer(string layerName) { try { IMap map = ArcMap.Document.FocusMap; //Bail if map has no layers. if (map.LayerCount == 0) { MessageBox.Show("There are no layers importerd. Please add Layers and try again"); return 0; } //Fetch all the feauture layers in the focus map //to determine if at least one is selectable IUID uid = new UIDClass(); uid.Value = "{40A9E885-5533-11D0-98BE-00805F7CED21}"; IEnumLayer enumLayer = map.get_Layers((UID)uid, true); enumLayer.Reset(); IFeatureLayer featureLayer = (IFeatureLayer)enumLayer.Next(); while (featureLayer != null) { if (featureLayer.Name.ToString() == "Structure") { IFeatureClass featureClass = featureLayer.FeatureClass; return 50; } else { featureLayer = (IFeatureLayer)enumLayer.Next(); } } return 0; } catch (Exception ex) { MessageBox.Show(ex.StackTrace); return 0; } }
... View more
02-14-2013
06:42 AM
|
0
|
6
|
1809
|
POST
|
Thank you both for the responses! I really appreciate critiquing my code, I am learning c# on the fly and am missing some basic concepts so I really appreciate that. The code you provided has allowed me to do exactly what I asked!
... View more
02-08-2013
08:21 AM
|
0
|
0
|
283
|
POST
|
I am able to get the ObjectID for the features only in the layer selected in the table of contents when I click the StartButton. I would like to be able to gather the selected items for multiple layers. This is because there are multiple layers that have selected features and need to grab information for each. Below I have added the code I used to put the ObjectID into 3 comboboxes. I realize the line IFeatureLayer featureLayer = (IFeatureLayer)mapDoc.SelectedLayer; is selecting the layer in the table of contents that is selected. I am wondering how others would solve this. I have tried to find a way to use code to select a different layer by its layer name but I could not find any information on it. If I can select a layer by name then I can merely change the layer before the IFeatureLayer featureLayer = (IFeatureLayer)mapDoc.SelectedLayer; line and run the method GetSelectedValues for each layer I would like. Any suggestions will be greatly appreciated! public void StartButton_Click(object sender, EventArgs e) { IApplication app = (IApplication)this.Hook; IMxDocument mapDoc = (IMxDocument)app.Document; IFeatureLayer featureLayer = (IFeatureLayer)mapDoc.SelectedLayer; GetSelectedValues(featureLayer); } public void GetSelectedValues(IFeatureLayer featureLayer) { try { IFeatureSelection featureSelection = (IFeatureSelection)featureLayer; ISelectionSet selectionSet = featureSelection.SelectionSet; ICursor cursor; selectionSet.Search(null, false, out cursor); IRow row = cursor.NextRow(); //IFeatureCursor featureCursor = (IFeatureCursor)cursor; IFeatureClass featureClass = featureLayer.FeatureClass; // Gets the feature from the OID found from row IFeature feature = featureClass.GetFeature(row.OID); while (row != null) { feature = featureClass.GetFeature(row.OID); //Adds the selected object ID's to the drop down menus middlePole.Items.Add(feature.get_Value(featureClass.FindField("OBJECTID")).ToString()); leftPole.Items.Add(feature.get_Value(featureClass.FindField("OBJECTID")).ToString()); rightPole.Items.Add(feature.get_Value(featureClass.FindField("OBJECTID")).ToString()); //textBox3.Text = feature.get_Value(featureClass.FindField("LASTUPDATESESSIONID")).ToString(); //Goes to the NextRow so that the while loop can catch if the next row is a Null. row = cursor.NextRow(); } } catch (Exception ex) { MessageBox.Show(ex.StackTrace); } }
... View more
02-07-2013
12:28 PM
|
0
|
3
|
2051
|
POST
|
I finally realized the while loop was looping for a null for the previous Row. The error was caused by the row.OID not existing. Here is how I fixed this: row = cursor.NextRow(); while (row != null) { System.Diagnostics.Debug.WriteLine(row.OID.ToString()); comboBox1.Items.Add(row.OID.ToString()); row = cursor.NextRow(); } Thank you for all your help!
... View more
02-06-2013
07:51 AM
|
0
|
0
|
568
|
POST
|
I have added row.HasOID == true to the while condition but still get the popup. I have tried an If statement surround everything below selectionSet.Search(null, false, out cursor); as well and that didnt work either. Am I placing it in the wrong spot? try { IFeatureSelection featureSelection = (IFeatureSelection)featureLayer; ISelectionSet selectionSet = featureSelection.SelectionSet; ICursor cursor; selectionSet.Search(null, false, out cursor); IRow row = cursor.NextRow(); comboBox1.Items.Add(row.OID.ToString()); textBox2.Text = row.OID.ToString(); while (cursor != null && row.HasOID == true) { System.Diagnostics.Debug.WriteLine(row.OID.ToString()); row = cursor.NextRow(); comboBox1.Items.Add(row.OID.ToString()); } } catch (Exception ex) { MessageBox.Show(ex.StackTrace); }
... View more
02-05-2013
07:56 AM
|
0
|
0
|
568
|
POST
|
Thank you for your responses! I really need to start utilizing try catch statements to find problems. It will find the OID's correctly. I did not have a using System.Diagnostics. I added a try catch for GetSelectedValues and am getting a pop up window saying that the botton line of the while is erroring out. For this case, it is row = cursor.NextRow();. This is after I added System.Diagnostics. I added below the previous line textBox3.Text = row.OID.ToString(); and that is where it is having an error. The while loop looks like this now: while (cursor != null) { System.Diagnostics.Debug.WriteLine(row.OID.ToString()); row = cursor.NextRow(); - Previous location of error after adding using System.Diagnostics textBox3.Text = row.OID.ToString(); -This is where the error is now } I am thinking this is a basic concept error that I am having due to my adolescence in programming.
... View more
02-05-2013
07:11 AM
|
0
|
0
|
568
|
POST
|
I am trying to get the OID of the selected feature to display in textBox2. I am getting an error that says ArcGIS Desktop has encountered a serious application error and is unable to continue. It was strange I got it to work once but I had to continue through an error screen and havent been able to reenact the scenario since. Now it merely crashes everytime. I have made sure a feature is selected as well. I had copied the code in GetSelectedValues() so I am guessing it is how I am initializing the featurelayer. I am new to developing so any suggestions will be greatly appreciated! public void StartButton_Click(object sender, EventArgs e) { IApplication app = (IApplication)this.Hook; IMxDocument mapDoc = (IMxDocument)app.Document; IFeatureLayer featureLayer = (IFeatureLayer)mapDoc.SelectedLayer; GetSelectedValues(featureLayer); } private void GetSelectedValues(IFeatureLayer featureLayer) { IFeatureSelection featureSelection = featureLayer as IFeatureSelection; ISelectionSet selectionSet = featureSelection.SelectionSet; ICursor cursor; selectionSet.Search(null, false, out cursor); IRow row = cursor.NextRow(); textBox2.Text = row.OID.ToString(); while (cursor != null) { System.Diagnostics.Debug.WriteLine(row.OID.ToString()); row = cursor.NextRow(); } }
... View more
02-04-2013
02:32 PM
|
0
|
7
|
1133
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:24 AM
|