Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I work in GIS with VBA. I have 2 Points layer.One of them is City points and another is hydro station points.I want write code in vba for selecting one point from station layer and finding closest city to this selected point.On the other hand I should find nearest point to a selected point. Please help me.

share|improve this question
How are the points stored? If they are simply pairs of (X, Y), just sort using the Pythagorean theorem and take the one with the shortest distance. – Adam Matan Aug 29 '10 at 10:02
up vote 1 down vote accepted

Id advise searching the archvied ESRI forums as this will have been asked before.

eg1 eg2 = You should be able to pinch some code from the snippets found there to at least get you started.

share|improve this answer
Tanks problem is solved with using this sample code. – Nima Aug 30 '10 at 7:13
Cool. Can you mark this as resolved please. You also failed to mark a previous Question I answered for you… - Can you mark that one as resolved as well please. – Simon Aug 30 '10 at 10:43
Sorry,But I click the green button next to your name.Should I do other work? – Nima Aug 30 '10 at 12:53
this would be a better answer if it included one such example snippet or conversation. We can't rely on links to external sites to remain intact, and if/when it does change this answer will become wrong. – matt wilkie Aug 30 '10 at 19:04
@Nima, click in the grey outline of a checkmark to mark an answer accepted: – matt wilkie Aug 30 '10 at 19:20

Take a look at the IProximityOperator or the IIndexQuery.

share|improve this answer

Assuming you have an ArcInfo license, have you tried calling the Near tool within your script? It sounds a lot like what you're after.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.