I will do my best to explain my problem. I have two feature datasets. One set has about 100 points that are "city centers." The other dataset has points for each census tract in each of these 100 cities. THere is a row of data per census tract as well as an identifier number for each city (which is also in the city center feature dataset).

I need to measure the distance between each city center and each point/census tract in that city and then have these distances in a table with the census tracts numbers....I was hoping there was some way to use python (I'm a beginner at python!) to loop through each point and measure the distance to the city center.

ANY suggestions on how to best approach this would be great and the more detailed your response, the better! I've used point distance tool before when I only had 5 cities so I could just run each one manually to get the distances (each city was also a separate file)....

2 Answers 2


I think you want to do something like Generate Near Table or just Near which will allow you to join attributes between the points for each census tract and the near table to find the distance to the city centres.

If you use closest only on the near table you will only get the closest feature, Near will always return just the nearest feature and distance from one feature class to another, in addition it should add Near_FID to the input points so you can identify which one by joining Near_FID to the FID on the city centeres.


To find the distance between census tracts and the matching code number:

Generate near table using tracts as input and city centres as near features with all distances and a very large or not entered tolerance; the documentation says If no value is specified, all near features will be candidates which should mean that every census tract to every city will be represented in the table should no tolerance be entred, if it is not the case then use a very large tolerance.

From here there are many ways to trim that down, but this is the method I use as it's less confusing (for me anyway):

Add two fields to the near table, let's call them TractCode and CityCode. Load up the table in ArcMap (you will need to use add data as tables don't want to drag 'n drop), add the census tracts and city centres as well.

Open the attribute table for the near table and Add a join from the near table to the city centres using NEAR_FID to FID/OBJECTID (depending on data type). Using field calculator calculate the value of the CityCode in the near table from the code field in the city centres data. Now remove that join and add another one to the census tracts and calculate the TractCode from the census tracts and then remove that join too.

Now your near table has the codes from the census tracts and city centres. Select by attributes on the near table where CityCode = TractCode which will select the rows where the code is the same on city centre and census tract, export that to a new table for simplicity.

This newly exported table will contain the distances between census tracts and city centres where the code matches.

  • Hi Michael - I've tried doing this in various ways, but I haven't gotten it to work yet. I don't know how to make each set of census tracts only calculate the distance to the city center with the matching code number....This is very similar to what I have been trying to do: gis.stackexchange.com/questions/95216/…
    – user32636
    Jun 23, 2014 at 16:15
  • @user32636, I have included instructions as an addendum to the answer. Jun 23, 2014 at 22:01

For every census tract, you want the distance to the city center for the city that the tract is part of? You don't need python, you can do it in ArcMap.

Do ADDXY on both point layers.

Add a field to the census tract centers to store the distance in.

Join the attribute table of the city center points onto the tract centers using the city ID attribute field.

Use field calculator to calculate the distance = sqr((tract.x - city.x)^2 + (tract.y - city.y)^2).

  • Don't you need to take the square root of that?
    – ianbroad
    Jun 20, 2014 at 19:03
  • In case it isn't clear, the direction of the join matters a lot. Right click the census tract points and do the join from there, so you wind up with a city center record joined to every census tract record, one to many. Jun 20, 2014 at 20:56
  • Thank you! I got it to work perfectly! I can't believe it was that simple!
    – user32636
    Jun 23, 2014 at 17:41
  • Hi Jersey - for one of my shapefiles, I can't get the xy data to display in meters instead of decimal degrees (I need meters to use the equation). What am I doing wrong? I know this is a projection issue, but I am unsure how to resolve it. Thank you.
    – user32636
    Jun 29, 2014 at 4:45
  • In ArcToolbox is a tool called "Project" resources.arcgis.com/en/help/main/10.2/index.html#//… that will make a new shapefile in whatever projection you want. It's in the data management toolset. Jul 8, 2014 at 19:52

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.