By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,621 Members | 1,074 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,621 IT Pros & Developers. It's quick & easy.

How can I determine the closest point to a given latitude or longitude?

P: n/a
If I have an arc shapefile (polygons) that has centroid coordinates as fields, what type of python code can I use to determine which point is closest to a given latitude or longitude?

Should I export the centroid coordinates and county names and use an if/while statement? Or, can I actually make the calculation and analysis using the "import arcgisscripting" route?

Im having trouble figuring out how to test each location (aka row) versus a given longitude or latitude.
Nov 6 '10 #1
Share this Question
Share on Google+
3 Replies


Expert 100+
P: 621
I'm not quite sure what you want to do from the question, but the automatic response is, can't you use trigonometry in some way?
Nov 7 '10 #2

bvdet
Expert Mod 2.5K+
P: 2,851
ArcGIS is a large program with many capabilities. Unfortunately, I know nothing about it. If I had a list(1) of latitude/longitude points, and I wanted to determine the closest point from a given latitude/longitude point, I would create a function to calculate the distance between two given points, iterate on the list and accumulate the calculated distances in another list(2). The list(2) index of the smallest distance would match the list(1) index of the closest point. The formula to make the distance calculation can be found here.
Nov 7 '10 #3

P: n/a
im trying to figure out how to run a while statement in the arc script that tests each row according to its x coordinate versus a given longitude. the hard part is translating a function, like the one below, into arc script:
Expand|Select|Wrap|Line Numbers
  1. x = (214, 521)
  2. q = [(200, 500),(250, 550),(300, 600)]
  3. t = []
  4. for item in q:    #print item
  5.     b = abs(item[1]-x[1])
  6.     t.append((avg, item))
  7.     print min(item)
  8.     print min(t)[1]
  9.     break
X would equal the given longitude
q would represent the list of attributes/values in the shapefile (e.g. [(County0, xCentroid0), (County1,xCentroid1)]
Nov 7 '10 #4

Post your reply

Sign in to post your reply or Sign up for a free account.