Need help with ArcGIS developer tools in Visual Studio

1236
14
12-03-2012 05:53 AM
VidmantasAskinis
New Contributor
Hi,

i need help with ArcMap developer tools. I'm trying to make an ArcMap command with Visual Studio 2010 in C# which deletes selected (could be all) points from point set.

I believe it should be a ArcMap basecommand.

I think i need to create an envelope to cover all the points in the layer. Then it should start editing and delete those points. But i'm a newbie at c# and Visual Studio. Could anyone give me code examples of using Ienvelope this way? Or something similar to learn from?
0 Kudos
14 Replies
MarcinDruzgala
Occasional Contributor
There might be a better solution for this but i would do it like that:
private IEditor editor;
private IWorkspace workspace;
private IFeatureLayer featLayer;

private void DeleteFeatures(IFeatureLayer featLayer)
{
      //if there is already a selection on feature layer you can get all selected features
      IFeatureSelection featureSelection = featLayer as IFeatureSelection; 
      ISelectionSet selectionSet = featureSelection.SelectionSet;
      
      ICursor cursor;
      //in search method you can use QueryFilter to query features or you can use 'null' and you will get all features in layer
      selectionSet.Search(null, false, out cursor);
      IRow row = cursor.NextRow();
      editor.StartEditing(workspace);

      while (row != null)
      {
            row.Delete();
            row = cursor.NextRow();
            
      }
      editor.StopEditing(true);
}


Now to obtain editor from ArcMap:

private void GetEditor()
{
      UID uidEditor = new UIDClass();
      uidEditor.Value = "esriEditor.Editor";
      editor = ArcMap.Application.FindExtensionByCLSID(uidEditor) as IEditor;
}


To get workspace I would do sth like this:

private void GetFileWorkspace(IFeatureLayer featLayer)
{
      IFeatureDataset featDataset = featLayer.FeatureClass.FeatureDataset;
      IFeatureWorkspace featWorkspace = (IFeatureWorkspace)featDataset.Workspace;
      workspace = (IWorkspace)featWorkspace;
}


Now you need feature layer:

private void GetMapLayers()
{
 uid.Value = "{40A9E885-5533-11D0-98BE-00805F7CED21}";
 IEnumLayer enumLayerByName = map.get_Layers((UID)uid, true);
 enumLayerByName.Reset();
 ILayer iLayer = enumLayerByName.Next();

 while (!(iLayer == null))
 {
  switch (iLayer.Name)
  {
   case "YourLayerName":
    featLayer = (IFeatureLayer)iLayer;
    break;
                        .........(more cases)
   default:
    break;
                 }
         }
}


Good luck!
MDruzgala
0 Kudos
VidmantasAskinis
New Contributor
Thank you for a great response.

But i'm still wondering about using Ienvelope. Maybe you or somebody else could give me just an example how to use envelope. Just to learn more about Visual Studio.
0 Kudos
MarcinDruzgala
Occasional Contributor
Thank you for a great response.

But i'm still wondering about using Ienvelope. Maybe you or somebody else could give me just an example how to use envelope. Just to learn more about Visual Studio.


Well honestly don't know why you are so attached to IEnvelope... Here I give you the documentation for this interface: ESRI DOC IEnvelope, there is a lot of .net samples in there, just look for what you are looking for.

Good luck
MDruzgala
0 Kudos
NeilClemmons
Regular Contributor III
What exactly are you trying to do?  Are you wanting the user to sketch an envelope on the map that indicates which features they want to delete?  If so, you need a tool not a command.  If you want to simply delete all of the features in a layer then you just need to call ITable.DeleteSearchedRows and pass in null.

DirectCast(featureLayer.FeatureClass, ITable).DeleteSearchedRows(Nothing)

If you want to delete a subset of the features in the layer then create a query filter and pass it into the method.
0 Kudos
VidmantasAskinis
New Contributor
Yes, I believe I need "users to sketch an envelope on the map that indicates which features they want to delete." So yes, i need a tool. I've seen all samples in here > http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#/SelectFeatures/004800000..., but couldn't find exact envelope and feature selection sample.
0 Kudos
MarcinDruzgala
Occasional Contributor
Yes, I believe I need "users to sketch an envelope on the map that indicates which features they want to delete." So yes, i need a tool.


So why is arcmap's selection bad for your needs? This is like a basic functionality for ArcMap...(Select [features] by rectangle/polygon/lasso/circle/line you pick).

MDruzgala
0 Kudos
VidmantasAskinis
New Contributor
That's because i'm trying to make it to select points before user started editing. I think only envelope can do that. Please correct me if i'm wrong.
0 Kudos
MarcinDruzgala
Occasional Contributor
Ok maybe i don't understand what you have to do in your project. But sure, you can select features without starting editing. See atachments.
To make it clear you want a tool for selecting features (without starting the edit session)? - you have it in arcmap.
You want to delete selected features? - it's like the most basic functionality in all gis programs. So where is the case?
I'm just trying to understand what do you want to achieve:)

Regards
MDruzgala
0 Kudos
VidmantasAskinis
New Contributor
The thing is that points should be selected automatically (for example, all points in active view). And then deleted. It seems i forgot to mention it the beginning of this thread 🙂
0 Kudos