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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Andrew Jackson

    #1

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

    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.
  • dwblas
    Recognized Expert Contributor
    • May 2008
    • 626

    #2
    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?

    Comment

    • bvdet
      Recognized Expert Specialist
      • Oct 2006
      • 2851

      #3
      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.

      Comment

      • Andrew Jackson

        #4
        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:
        Code:
        x = (214, 521)
        q = [(200, 500),(250, 550),(300, 600)]
        t = []
        for item in q:    #print item
            b = abs(item[1]-x[1])
            t.append((avg, item))
            print min(item)
            print min(t)[1]
            break
        X would equal the given longitude
        q would represent the list of attributes/values in the shapefile (e.g. [(County0, xCentroid0), (County1,xCentr oid1)]
        Last edited by bvdet; Nov 8 '10, 03:45 AM. Reason: Add code tags

        Comment

        Working...