# How to compute the distance between centroids and polygons?

Suppose I have an Excel spreadsheet with the latitude and longitude of the centroid of every county in the U.S. I want to know the shortest distance from each county to any part of Oklahoma (presumably, somewhere along the border). I then want this distance in this Excel spreadsheet as a new column.

Is this possible to do and how? I know next to nothing about GIS

-
What tools do you have at hand? There are n ways to skin this cat. Let us know what tools you have, skills (GIS, Programming, etc), and we'll give you a good start. – OptimizePrime May 24 '12 at 19:55
@OptimizePrime Thank you for your quick response! Would that be easier to hash out over a chat forum here? – J G May 24 '12 at 20:06
Have you checked gis.stackexchange.com/questions/2/… – underdark May 24 '12 at 20:41
I understand how to do the distance between 2 coordinates. The problem -- as I wrote below -- is that I don't know how to do the distance between a county whose coordinates I know and the boundary of Oklahoma, whose coordinates I do not know. Perhaps it is possible to get those coordinates. – J G May 24 '12 at 20:51

## 1 Answer

If you know the coordinates of the point in OK, the haversine formula should be pretty easy to implement in Excel. This will give you the approximate as-the-crow-flies distance between the points.

-
My problem is that I do not know how to get the coordinates for the state of Oklahoma. Do you know how to do this? – J G May 24 '12 at 20:49
If you only have a couple points, you can get the coordinates by hand from Google Earth. For example, OK City is 35.467588 and -97.516426. If you have lots of addresses, you can geocode them as a batch. There are some free options if you don't have too many (like webgis.usc.edu/Services/Geocode/BatchProcess/Default.aspx). – Dimitriy V. Masterov May 24 '12 at 21:00
Could any of this be done through GIS? – J G May 24 '12 at 21:02
This answer seems to miss the thrust of the question, which inquires about a way to compute distances between centroids (points) and a polygon (representing the state of Oklahoma). I'm afraid that will not be resolved only by knowing the Haversine formula. – whuber May 24 '12 at 21:06
@DimitriyV.Masterov I want the shortest distance between the centroid and any point along the OK boundary. – J G May 24 '12 at 21:18