spatial difference between 2 polygon layers with VBA

1088
7
05-31-2013 01:24 AM
arct
by
New Contributor
Hi,

I have 2 polygon layers. PolyOldLayer has some old data and based on the new records, PolyOldLayer had been edited  and saved as polyNewLayer.

I would like to have the count of all the polygons I edited with reference to PolyOldLayer.
i.e The spatial difference between PolyOldLayer and PolyNewLayer with VBA.

How can it be achieved.

Thanks.
0 Kudos
7 Replies
WeifengHe
Esri Contributor
Let me try.

'First get the feature class from the 2 layers.
    Set featClsOld = PolyOldLayer.FeatureClass
    Set featClsNew = PolyNewLayer.FeatureClass

'Use cursors for looping through featClsOld
    Set featCursorOld = featClsOld.Search(Nothing, true)
    Set featureOld = featCursorOld.NextFeature
    While Not featureOld Is Nothing
        'loop here
        ... ...

        Set featureOld = featCursorOld.NextFeature

    Wend

'Inside the loop, find the feature in featClsNew with the same ObjectID as featureOld
'using IQueryFilter and the WhereClause specify the query condition of ObjectID
    featCursorNew = featClsNew.Search(queryFilter, true)
    featureNew = featCursorNew.NextFeature

'Use IClone method IsEqual to compare the geometries of the two features.
    Set cloneOld = featureOld.ShapeCopy
    Set cloneNew = featureNew.ShapeCopy
    If cloneOld.IsEqual(cloneNew) = False Then
        count++
   End If

'Here count is the number of polygons edited.
0 Kudos
arct
by
New Contributor
hi,

I am quite new to arcObjects. I got the logic behind this, but get struck in 'IQueryFilter'

  Dim pQueryFilter As IQueryFilter
  Set pQueryFilter = New QueryFilter

  ' Set the where clause
  pQueryFilter.WhereClause = "ObjectID = 'ToWhatand HOW'"


hope you can help me resolve this issue.
'Inside the loop, find the feature in featClsNew with the same ObjectID as featureOld 'using IQueryFilter and the WhereClause specify the query condition of ObjectID

Thanks.
0 Kudos
WeifengHe
Esri Contributor
If you edit a featue, the OBJECTID value won't change, so you can get the Object ID of the feature in old feature class, featureOld.OID and assign it to some string variable, say s.  You can then search the new feature class for the feature with the same Object ID with

pQueryFilter.WhereClause = "OBJECTID = " & "s"
0 Kudos
arct
by
New Contributor
Hi,

Thanks, got the answer to my query.

But I have one more query,

The output from this script(cloneOld.IsEqual(cloneNew) = True ) and select by location --> 'Target layer features are identical to the source layer features' output should be same?

But I get different count.
I need to do "select by location --> 'Target layer features are identical to the source layer features'" in VBA. Is this the right approach.
the feature count from my VBA script and from "select by location --> 'Target layer features are identical to the source layer features'" should be same.

Thanks.
0 Kudos
WeifengHe
Esri Contributor
Hm.  Were you able to identify which features causing the inconsistence between these two approaches?  Can you tell which approach works better in those cases?
0 Kudos
arct
by
New Contributor
"select by location --> 'Target layer features are identical to the source layer features'" gives the best results. some features which did overlap exactly were also displayed by the script.

hence the count was greater than "select by location --> 'Target layer features are identical to the source layer features'" option.

Thanks.
0 Kudos
WeifengHe
Esri Contributor
So, if you look into the one that identified by the script as equal but not selected by the tool, can you tell whether or not they are the same in both layers?  As I know the method of IClone::IsEqual is reliable.  I am not clear about the statement "some features which did overlap exactly were also displayed by the script", I suppose they are not selected by the tool.  Do you think they should be equal or not?
0 Kudos