Hi Antonic,I have tried to write code using your suggestion but I can not get any results.Thisi is the code that I have used to the click event of the command tool:
public override void OnClick()
{
IFeatureLayer pflayer1;
IFeatureLayer pflayer2;
IFeature featureA;
IFeature featureB;
pflayer1 = GetLayerByName("Shape1");
IFeatureSelection p1FlSelection = pflayer1 as IFeatureSelection;
int[] idList = GetFidList(@"D:\ShapeFile1").ToArray();
IFeatureCursor feature1Cursor = pflayer1.FeatureClass.GetFeatures(idList, false);
featureA = feature1Cursor.NextFeature();
pflayer2 = GetLayerByName("Shape2");
int[] oidList = GetFidList(@"D:\ShapeFile1").ToArray();
IFeatureCursor feature2Cursor = pflayer2.FeatureClass.GetFeatures(oidList, false);
featureB = feature2Cursor.NextFeature();
List<int> fidList = new List<int>();
while (featureA != null)
{
while (featureB != null)
{
string risultato = FeaturesEqual(featureA, featureB);
if (!String.IsNullOrEmpty(risultato))
fidList.Add(Convert.ToInt32(risultato));
featureB = feature2Cursor.NextFeature();
}
feature2Cursor = pflayer2.FeatureClass.GetFeatures(oidList, false);
featureB = feature2Cursor.NextFeature();
feature1Cursor = pflayer1.FeatureClass.GetFeatures(idList, false);
featureA = feature1Cursor.NextFeature();
}
//At this point it stops and leaves
string elenco = String.Empty;
foreach (int numero in fidList)
{
elenco += numero + ",";
}
elenco = elenco.Trim(',');
IMap pMap = m_hookHelper.FocusMap;
IActiveView pActiveView = (IActiveView)m_hookHelper.FocusMap;
string where = "FID IN (" + elenco + ")";
SelectMapFeaturesByAttributeQuery(pActiveView, pflayer1, where);
}
At the point commented in blue color the procedure stops and leaves.This is the red function:
//Compare Features
//temporarily I consider only attribute compare and not geometry
public string FeaturesEqual(IFeature pFeatureA, IFeature pFeatureB)
{
// attribute equal test
int diffCount = 0;
for (int i = 2; i < pFeatureA.Fields.FieldCount; i++)
{
string valore1 = pFeatureA.get_Value(i).ToString();
string valore2 = pFeatureB.get_Value(i).ToString();
bool equal = ESRI.ArcGIS.Geodatabase.Object.Equals(pFeatureA.get_Value(i), pFeatureB.get_Value(i));
if (!equal)
{
diffCount++;
}
if (diffCount > 0)
return pFeatureA.OID.ToString();
}
return String.Empty;
//// geometry equal test
//IArea pAreaA = pFeatureA.Shape as IArea;
//IArea pAreaB = pFeatureB.Shape as IArea;
//if (pAreaA.Area != pAreaB.Area)
//{
// diffCount++;
//}
//if (diffCount > 0)
//{
// return false;
//}
//return true;
}
public static List<int> GetFidList(string path)
{
List<int> fidList = new List<int>();
String shapefileStringTemplate =
"Provider=ESRI.GeoDB.OleDB.1;Data Source={0};" +
"Extended Properties=workspacetype=esriDataSourcesFile.ShapefileWorkspaceFactory.1;Geometry={1}";
String connectionString = String.Format(shapefileStringTemplate, path,
"Fabbricati");
OleDbConnection myOleDbConnection = new OleDbConnection(connectionString);
OleDbCommand command = myOleDbConnection.CreateCommand();
command.CommandType = CommandType.Text;
command.CommandText = String.Format(@"SELECT FID FROM FABBRICATI");
try
{
myOleDbConnection.Open();
OleDbDataReader reader = command.ExecuteReader();
while (reader.Read() == true)
{
fidList.Add(
Convert.IsDBNull(reader["FID"]) ? 0 : Convert.ToInt32(reader["FID"])
);
}
reader.Close();
return fidList;
}
catch (Exception)
{
throw;
}
finally
{
if (myOleDbConnection.State != ConnectionState.Closed)
myOleDbConnection.Close();
}
}
Can you see the error?I trust in your help!!!