1

I am trying to calculate the distance between some geographic features (point layer) and the capital of the country that they fall in. I have a shapefile of "features" and a shapefile of "world capitals". My current system is to generate a NearTable between the two layers and then use another program (Stata) to keep only the relevant distances (where the country of the feature and city are the same). However, my program takes a while to run when I do this because, due to the size of the countries I'm looking at, I need to calculate the distance between all points and the nearest 20 capital cities.

Is there a faster way to do this?

Here is a snippet of my code:

in_features = gpts
near_features = world_capitals
arcpy.GenerateNearTable_analysis(in_features, near_features, near_world_capitals_tbl, \
closest="ALL", closest_count="20", method="GEODESIC")

I am working in ArcPy, but answer in ArcMap are also helpful.

  • 2
    Add xy to both. Join capital to point using country name. Use hypot(dx,Dy) for each point or convert pairs to lines and calculate geodetic length. – FelixIP Mar 21 at 18:57
  • If your data is in Shapefiles, creating a Spatial Index for each FC might speed up Near. In File geodatabase, the spatial index is automatically created/updated. – klewis Mar 21 at 20:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.