Escolar Documentos
Profissional Documentos
Cultura Documentos
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using ESRI.ArcGIS.ADF.BaseClasses;
using ESRI.ArcGIS.ADF.CATIDs;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Framework;
using ESRI.ArcGIS.ArcMapUI;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geodatabase;
using System.Windows.Forms;
namespace RemoveDuplicates
{
/// <summary>
/// Command that works in ArcMap/Map/PageLayout
/// </summary>
[Guid("255d7b9a-c53b-4d04-b2ed-653c2f7896cb")]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("RemoveDuplicates.DeleteDuplicates")]
public sealed class DeleteDuplicates : BaseCommand
{
#region COM Registration Function(s)
[ComRegisterFunction()]
[ComVisible(false)]
static void RegisterFunction(Type registerType)
{
// Required for ArcGIS Component Category Registrar support
ArcGISCategoryRegistration(registerType);
//
// TODO: Add any COM registration code here
//
}
[ComUnregisterFunction()]
[ComVisible(false)]
static void UnregisterFunction(Type registerType)
{
// Required for ArcGIS Component Category Registrar support
ArcGISCategoryUnregistration(registerType);
//
// TODO: Add any COM unregistration code here
//
}
#endregion
#endregion
try
{
//
// TODO: change bitmap name if necessary
//
string bitmapResourceName = GetType().Name + ".bmp";
base.m_bitmap = new Bitmap(GetType(),
bitmapResourceName);
}
catch (Exception ex)
{
System.Diagnostics.Trace.WriteLine(ex.Message, "Invalid
Bitmap");
}
}
/// <summary>
/// Occurs when this command is created
/// </summary>
/// <param name="hook">Instance of the application</param>
public override void OnCreate(object hook)
{
if (hook == null)
return;
if (pApp == null)
return;
/// <summary>
/// Occurs when this command is clicked
/// </summary>
public override void OnClick()
{
// TODO: Add DeleteDuplicates.OnClick implementation
int flag = 0;
IRelationalOperator pRop;
IFeatureLayer pFeatLayer;
IFeatureClass pFeatClass;
IFeatureCursor pFeatCursor;
IFeatureCursor pFeatCursor1;
IFeature pFeature;
IFeature pFeature1;
int j = 0;
pFeatLayer =
(IFeatureLayer)pMxDoc.FocusMap.get_Layer(0);
pFeatClass = pFeatLayer.FeatureClass;
j =pFeatClass.FeatureCount(null);
pFeature = pFeatCursor.NextFeature();
while (pFeature!=null)
{
pRop = (IRelationalOperator)pFeature.Shape;
pFeatCursor1 =
(IFeatureCursor)pFeatClass.Update(null, false);
pFeature1 = pFeatCursor1.NextFeature();
while(pFeature1!=null)
{
if (pRop.Equals(pFeature1.Shape))
{
if(pFeature.OID != pFeature1.OID)
{
flag = 1;
pFeature.Delete();
//------- Comment it if There are more than
two duplicated shapes
break; // TODO: might not be correct.
Was : Exit Do
}
}
pFeature1 = pFeatCursor1.NextFeature();
}
pFeature = pFeatCursor.NextFeature();
if (flag == 1)
{
MessageBox.Show("There were " + (j -
pFeatClass.FeatureCount(null)) + " Features duplicated / " + j + "
Features in this Layer ");
}
else{
MessageBox.Show( "This Layer is out of any
duplicated Features");
}
pMxDoc.ActivatedView.Refresh();
#endregion
}
}