FIND DISTANCES BETWEEN POWER POLES

9247
14
11-30-2016 10:42 AM
nimitz
by
Occasional Contributor

Hi all,

I have a Personal GEODB that contains Point FC (POLES), Line FC (OVERHEAD TRANSMISSION LINE). I'm trying to use the Point-Distance tool in Toolbox, but it's giving me funky results. I'm on 10.2.1 and Pro. 

Ideally I'd like to have a new column(or a new table if that won't work) that shows the distance between 2 power poles, ie. POLE205-POLE206 - 250'. Or something along those lines. 

When I run the tool, it's giving me 54,000 records, a lot more than I'd imagine for 854 transmission poles!

Many thanks,

Tags (1)
0 Kudos
14 Replies
DanPatterson_Retired
MVP Emeritus

funky normally means that you aren't using projected data and are getting values returned in decimal degrees.  So you have several options including setting your data frame to a projected coordinate system and returning geometry measures in he coordinate system of the data frame... or physically projecting your data to a new file and doing all your work in the planar world... or funky may mean you are expecting one unit and getting another (ie feet versus meters etc)  Of course an example of what you got and what your expect would provide the final clue to the possible solutions.

0 Kudos
BlakeTerhune
MVP Regular Contributor

When using the Point Distance tool, are you specifying the search_radius parameter? If you don't, it gives you the distance to all other points; which seems like it's not what you're after. It sounds like maybe you only want to look at other poles that are connected by a segment of transmission line. What are the rules by which you name your poles and how do your transmission line features connect them?

nimitz
by
Occasional Contributor

NAD83 CA STATE PLANE ZNII US SURVEY FOOT. 

I just realized it's probably calculating the distances from EACH POLE TO EVERY OTHER POLE. sheesh!

0 Kudos
nimitz
by
Occasional Contributor

Ok, it looks like after I put in a radius of 500', it's more "normal" now. The question is, "What fields can I use from the derived table to spatially join to my existing POWER POLE FC? It seems like the OBJECTID, INPUT_FID, NEAR_FID are random numbers, right?

0 Kudos
DanPatterson_Retired
MVP Emeritus

Look at the visual in the lin that Blake sent Point Distance—Help | ArcGIS for Desktop it shows what the relationship is between the features and the near feature

0 Kudos
BlakeTerhune
MVP Regular Contributor

ObjectID is not random; it's a unique, sequential number automatically assigned by a ArcGIS to create a primary key field. the FID in the tool's output is referring to the ObjectID field.

If you want have it show one of your key fields instead, you'll have to do a table join on ObjectID. I got tired of doing this so I made a script that will generate a near table that automatically includes a key field of my choice. *Disclaimer: I made some adjustments to the code just now to make it more generic and have not tested*

import arcpy
import os

try:
    # Set local variables
    working_gdb = r"C:\temp\TEMP.gdb"
    ## IN and NEAR features can be the same
    in_fc = "FirstFeatureClass"
    in_fc_key = "MyKeyFieldName"  ## Assumes Long Integer data type
    in_fc_path = os.path.join(working_gdb, in_fc)
    near_fc = "SecondFeatureClass"
    near_fc_key = "MyKeyFieldName"  ## Assumes Long Integer data type
    near_fc_path = os.path.join(working_gdb, near_fc)
    search_radius = "25 Feet"

    # Create near table and make as TableView
    neartable_inmem = os.path.join("in_memory", "neartable_inmem")
    arcpy.GenerateNearTable_analysis(
        in_fc_path,  ## in_features
        near_fc_path,  ## near_features
        neartable_inmem,  ## out_table
        search_radius,  ## search_radius
        "NO_LOCATION",  ## location
        "NO_ANGLE",  ## angle
        "ALL",  ## closest
        "0",  ## closest_count
        "PLANAR"  ## method
    )
    if arcpy.GetMessages(1):
        print arcpy.GetMessages(1)  ## Write arcpy warning
    arcpy.MakeTableView_management(neartable_inmem, "neartable_view")
    print "Near table created"

    # Add key fields to near table
    in_key = "IN_{}".format(near_fc_key)
    arcpy.AddField_management(
        "neartable_view",  ## in_table
        in_key,  ## field_name
        "LONG",  ## field_type
    )
    if arcpy.GetMessages(1):
        print arcpy.GetMessages(1)  ## Write arcpy warning
    near_key = "NEAR_{}".format(near_fc_key)
    arcpy.AddField_management(
        "neartable_view",  ## in_table
        near_key,  ## field_name
        "LONG",  ## field_type
    )
    if arcpy.GetMessages(1):
        print arcpy.GetMessages(1)  ## Write arcpy warning
    print "New key fields added"

    # Join and calc in_key field
    arcpy.AddJoin_management(
        "neartable_view",  ## in_layer_or_view
        "IN_FID",  ## in_field
        in_fc_path,  ## join_table
        "OBJECTID",  ## join_field
        "KEEP_COMMON"  ## join_type
    )
    if arcpy.GetMessages(1):
        print arcpy.GetMessages(1)  ## Write arcpy warning
    arcpy.CalculateField_management(
        "neartable_view",  ## in_table
        in_key,  ## field
        "!{}!".format(in_fc_key),  ## expression
        "PYTHON_9.3"  ## expression_type
    )
    if arcpy.GetMessages(1):
        print arcpy.GetMessages(1)  ## Write arcpy warning
    arcpy.RemoveJoin_management("neartable_view")
    if arcpy.GetMessages(1):
        print arcpy.GetMessages(1)  ## Write arcpy warning
    print "{} field populated".format(in_key)

    # Join and calc near_key
    arcpy.AddJoin_management(
        "neartable_view",  ## in_layer_or_view
        "NEAR_FID",  ## in_field
        near_fc_path,  ## join_table
        "OBJECTID",  ## join_field
        "KEEP_COMMON"  ## join_type
    )
    if arcpy.GetMessages(1):
        print arcpy.GetMessages(1)  ## Write arcpy warning
    arcpy.CalculateField_management(
        "neartable_view",  ## in_table
        near_key,  ## field
        "!{}!".format(near_fc_key),  ## expression
        "PYTHON_9.3"  ## expression_type
    )
    if arcpy.GetMessages(1):
        print arcpy.GetMessages(1)  ## Write arcpy warning
    arcpy.RemoveJoin_management("neartable_view")
    if arcpy.GetMessages(1):
        print arcpy.GetMessages(1)  ## Write arcpy warning
    print "{} field populated".format(near_key)

    # Export final near table
    out_near_table_path = os.path.join(
        working_gdb,
        "{}_nearKey".format(arcpy.ValidateTableName(in_fc, working_gdb))
    )
    arcpy.CopyRows_management(
        "neartable_view",  ## in_rows
        out_near_table_path  ## out_table
    )
    if arcpy.GetMessages(1):
        print arcpy.GetMessages(1)  ## Write arcpy warning

    print "Near table output at {}".format(out_near_table_path)

except Exception as err:
    print err
    ## If there was an ArcPy error, write all of the messages returned by the last tool
    if arcpy.GetMessages(2):
        print arcpy.GetMessages()

finally:
    # Cleanup
    arcpy.Delete_management("in_memory")‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
nimitz
by
Occasional Contributor

I've looked at the help for point distance. I'm afraid that those OBJECTID's that were generated in the new table DON'T correspond to the ORIGINAL OBJECTID's from my POLE file. I did a join based on the OBJECTID's, and the calculated distances are different (by a 100' or so) from what I actually measure.

hmmm...maybe I have to refine the radius to something a little smaller? 400' or so?

0 Kudos
DarrenWiens2
MVP Honored Contributor

Look at the picture in Dan's link:

Point Distance illustration

and read the description:

  • INPUT_FID: The feature ID of the input features
  • NEAR_FID: The feature ID of the near features

OBJECTID is the autonumber ID for the output table - it doesn't necessarily match with anything in the poles feature class.

BlakeTerhune
MVP Regular Contributor

If there is a specific rule about how you want to measure the distance to a feature other than "if it's nearby", then you might need to do some extra logic to filter out the unnecessary measurements.