3

I have a set of point features and I wish to find the points that have common coordinates. Now I changed the code as shwon bewlo by using the IPoint and the compare method through a function. I have 2 loops with cursors. The first one should read the first point while the second loop the second point etc. How can I force the cursor of the second loop to go to the second point? I addedd another NextFeature but it did not work.The result is that all the points are the same between the 2 loops. Thanks Demetris

Set pFeature = pFCursor.NextFeature
Do Until pFeature Is Nothing
Set pPointA = pFeature.Shape
Set pFeature2 = pFCursor2.NextFeature
Do Until pFeature2 Is Nothing
'Set pFeature2 = pFCursor2.NextFeature
Set pPointB = pFeature2.Shape
CommonPoints = ComparePoints(pPointA, pPointB)
If CommonPoints = True Then
MsgBox "Yes"
End If
Set pFeature2 = pFCursor2.NextFeature
Loop
Function ComparePoints(pointA As IPoint, pointB As IPoint) As Boolean
If pointA.Compare(pointB) Then
 ComparePoints = True
Else
 ComparePoints = False
End If
End Function
asked Oct 17, 2011 at 16:08
10
  • In addition to my answer below, I noticed that you're not setting a variable called "pFCursor2", but are trying to call "pFCursor2.NextFeature". Commented Oct 17, 2011 at 17:00
  • @Demetris - on which line does it crash? Commented Oct 17, 2011 at 17:22
  • Also, If GetX(pFeature)= GetX(pFeature2) Then will always evaluate to true (0 = 0) since you are not setting the GetX function to a value. You might need to replace the last line in the GetX function with GetX = Round(pPoint.x, 2). As for the error itself, we might need to see how you set both cursors and exactly which line raises the error. Commented Oct 17, 2011 at 17:31
  • Also, do not use recycling cursors when storing references to the features. That is, the second parameter to IFeatureClass.Search should be False instead of True. Commented Oct 17, 2011 at 18:05
  • I added above all the code before creating the array. I also changed the pFCursor2 and usued the same pFCursor. While I had to get a result given the IF-THEN condition I added in the loop (that is the Msgbox), the program run now without stopping but without also giving a right result.What do you think? Commented Oct 17, 2011 at 18:06

2 Answers 2

2

Okay, based on the additional information in the comments, I am proposing another way to go about reaching the actual goal which is identifying the coincident points in a point feature class. I will now perform this feat with zero programming (cue Europe's "The Final Countdown").

  1. In ArcMap, add the point feature class in question as a layer.
  2. Use Find Identical (Data Management) on the feature layer containing the coincident points. Select the SHAPE field since we are only interested in comparing the geometry. Enter appropriate XY and Z tolerances or accept the defaults. This will produce a standalone table containing a record for each feature in the input feature class, with columns for each feature's original ObjectID (IN_FID), and a sequential value (FEAT_SEQ) that will be the same for all features that were determined to be identical.
  3. Use Frequency (Analysis) on the resulting Find Identical table. Select the FEAT_SEQ field as the frequency field. This will create another standalone table with the a field containing the count of the number of times each sequential value occured.
  4. Join the Find Identical table to the point feature layer on the OBJECTID field in the points layer and FID field in the table.
  5. Join the Frequency table to the point feature layer on the FEAT_SEQ field in the joined Find Identical table, and the FEAT_SEQ field in the Frequency table.
  6. Select by Attributes on the point feature layer all those records where FREQUENCY> 1. Congratulations, you have now identified all the coincident points! Now do something with them.

Tips: You might use the in-memory workspace ("in_memory\someData") for the two stand-alone tables since they are only needed temporarily and the number of features is small. You could also script this easily with Python!

answered Oct 18, 2011 at 7:44
1
  • 1
    +1 Great solution that is fairly versatile for other applications. Commented Oct 18, 2011 at 15:21
1

If you're using points you might consider implementing IPointCollection instead of an array. You can use the built in methods to accomplish what you're asking and it should be a bit more efficient since you won't require an external method to get your IPoint.

Your steps would be:

1) Add each feature (point) to the IPointCollection using ".Add".

2) Compare yourPoint.X and/or yourPoint.Y.

answered Oct 17, 2011 at 16:32
10
  • Could you give me some more details please? Commented Oct 17, 2011 at 16:35
  • I've added a couple simple steps to my answer. What you essentially want to do is add each point to the collection(think of it like a custom array for handling points). Once you have all your points in the collection you can loop over each one using a cursor and compare the coordinate values using point.X and/or point.Y. Commented Oct 17, 2011 at 16:38
  • Here is an AddPoint example in VBA - edndoc.esri.com/arcobjects/9.1/ComponentHelp/esriGeometry/… Commented Oct 17, 2011 at 16:40
  • The first step is clear. Regarding the second I cannot understand how can I compare the X,Y of the point that the cursor is with all the other points of the dataset (i.e. the first point with the rest points, the secod point with the rest points etc.). Could you explain me please? Commented Oct 17, 2011 at 17:00
  • IPoint has a .Compare method than can be adapted to sort or match points. Aside from there are a number of ways to handle this comparison, but it will come down to programming preference since it's not specifically related to GIS - what you're asking is "how can I compare one item in a collection to all other items in the collection". The collection type (IPointCollection, array) doesn't really matter for this step, it just simplifies your storage of the data (in this case, points). Commented Oct 17, 2011 at 17:10

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.