Select to view content in your preferred language

Get difference between two shapefile

12605
14
08-08-2011 02:48 AM
ValeriaAndronaco
Emerging Contributor
Hi forum,

I use ArcMap 9.3 and I would like to create a toolbar that query two shapefiles and get the difference between them.
I think that I need to perform a SelectByLocation but how do this whith c# or vb.net language?
Can you help me please?

Thanks a lot in advance!
0 Kudos
14 Replies
DubravkoAntonic
Occasional Contributor
This is huge code part to answer at once.
Enclose OnClick implementation in try catch.
But there are some lines you should comment or change.
public override void OnClick()
        {
            // i will reuse cursor false-> true
            IFeatureCursor feature1Cursor = pflayer1.FeatureClass.GetFeatures(idList, true);
                      
            while (featureA != null)
            {
                // queryin again with same params makes forever loop
                 // using only first feature from an array
                feature1Cursor = pflayer1.FeatureClass.GetFeatures(idList, true);
                featureA = feature1Cursor.NextFeature();
            }
//At this point it stops and leaves
// because your code is not in try catch block and exception occured
            string elenco = String.Empty;
public string FeaturesEqual(IFeature pFeatureA, IFeature pFeatureB)
        {
            // if value is null you have exception use Convert.ToSring(pFeatureA.get_Value(i));
                string valore1 = pFeatureA.get_Value(i).ToString();
            // I intend to use System.Object.Equals didn't use ESRI's object before
                bool equal = ESRI.ArcGIS.Geodatabase.Object.Equals(pFeatureA.get_Value(i), pFeatureB.get_Value(i));
                
            
            
        }
For now I don't have idea what else is wrong
0 Kudos
ValeriaAndronaco
Emerging Contributor
Ok.
I may have the wrong solution. So do not get the result I need.
I would try to change the method.

How can I do in c #, a "Select by location" between two shapefiles with the condition "are identical to"?
0 Kudos
DubravkoAntonic
Occasional Contributor
Hope this will help

Copy paste functions into your Tool and on MouseDown get some Features and pass them as starting point for comparing.

// searches for intersection in target layer with geometry
public static IFeatureCursor SpatialQuery(IFeatureLayer pTargetFeatureLayer, IGeometry pSearchGeometry, esriSpatialRelEnum spatialRelation)

// Check if features geometry intersects with other features in other target layer
// commentate and do compare by length or area
private static void SelectByShapeAndCheckIfEqual(IFeature searchFeature)

// test if fields have equal value
private static void SelectByShapeAndCheckIfEqual(IFeature searchFeature)

Use debugger and SDK to understand what is going on. I hope you will use it and reuse it.
0 Kudos
ValeriaAndronaco
Emerging Contributor
Thnks!
Your code is perfect, This is exactly the solution I was looking for!
You have been very kind.
However ... I could ask another thing?
How can I use the same code without loading the layers in the toc?

Good evening!!!
0 Kudos
DubravkoAntonic
Occasional Contributor
Please post in another thread maybe someone will answer your question, I'm currently sort of without the time to write complete solutions. 

Wish you luck.
Regards
0 Kudos