Distance between related points

3231
15
12-05-2012 07:55 AM
SamuelFonseca
New Contributor
Here is the thing, I have two point shapes, one containing ???proposed??? sampling stations and the second one with the ???real??? coordinates where the samples were taken. The proposed and real points are linked together by a common code (5K_ID). What I need is to calculate the distance from all points in the ???proposed??? dataset to the corresponding point (by 5K_ID) in the ???real??? dataset. Any help would be much appreciated ???
0 Kudos
15 Replies
DanLee
by Esri Regular Contributor
Esri Regular Contributor
If the 5K_ID for related points in two files don't match, are there any other criteria or conditions (spatial or attribute information) that can be used to "match" them? If not, you may need to step back and look into the processes that have caused the unmatched IDs. Sometimes the problem occurs in early processes and may be solved more easily.
0 Kudos
SamuelFonseca
New Contributor
If the 5K_ID for related points in two files don't match, are there any other criteria or conditions (spatial or attribute information) that can be used to "match" them? If not, you may need to step back and look into the processes that have caused the unmatched IDs. Sometimes the problem occurs in early processes and may be solved more easily.


The thing is that it is not a problem in the data. I´ll try to give you some more background:
The points come from two sources of somewhere around 6500 moving sampling points each one. Each data set is created by a different company and they were supposed to be almost identical, but they are not. And we must check on a daily basis how far apart are the two companies taking the â??relatedâ?� measurements.
In the beginning the two companies were using the same codes (5_K) to identify the sites, but now they have different ID´s (5_K and 6_K) and one of them is not doing a good job managing their ID´s so equivalence between 5_K ID and 6_K ID is not always the same but they do provide what I call a Link table telling me which points on the daily results are supposed to be equivalent
Are the 5k_ID values unique for each of the point feature classes? 

If possible, could you please share your data (keeping only the 5k_ID field)? You can send the data to my email as well:   nahmed@esri.com

It will be easier if you use Python script - do you want that?


A Python script will be just fine!!... and yes, I can share a little data... I´ll attach a excel file with 3 pages, the first one is a subset of my 5_k data, the second page contains the coordinates from what Iâ??ll call the 6_K points and the third page is the link table.
Please note than in the file I´m giving you, the points are in the same (correct) order, but that is not the way it normally is, thats why I need to use the link table.

Any other ideas are still quite welcome!! And before anyone askâ?¦ NO we can not kick any of the two bad companies causing me so much troubleâ?¦ lol
0 Kudos
DanLee
by Esri Regular Contributor
Esri Regular Contributor
That is an important piece of information.

I would think you can use the link table to assign the equivalent 5_k IDs to the points with 6_K IDs; and then use the 5_k IDs in both point sets to do what you need to do.

If that's the case, try Join Field tool to transfer the equivalent 5_K IDs to the points through the common 6_K IDs.
0 Kudos
NobbirAhmed
Esri Regular Contributor
In case you do not find a way to get a solution using the system tool, here is a python script you can try on.

import arcpy

proposed = r'D:\data\f.gdb\points_A'
original = r'D:\data\f.gdb\points_B'

# create an empty dictionary to store shapes
proposed_points = {}  
with arcpy.da.SearchCursor(proposed, ("5k_ID", "Shape@")) as cursor:
    
    for row in cursor:
        # populate the dictionary
        # use 5k_ID field value as the key of the dictionary
        proposed_points[row[0]] = row[1]  
        
# create another dictionary
original_points = {}
with arcpy.da.SearchCursor(original, ("5k_ID", "Shape@")) as cursor:
    
    for row in cursor:
        # populate the dictionary
        # use 5k_ID field value as the key of the dictionary
        original_points[row[0]] = row[1]  

    
# iterate one of the dictionaries with ID values
for id_5k in proposed_points:
    
    # get proposed and original points with same ID
    orig = original_points[id_5k]
    prop = proposed_points[id_5k]
    
    # now find the distance
    dist = prop.distanceTo(orig)
    
    print dist
0 Kudos
SamuelFonseca
New Contributor
That is an important piece of information.

I would think you can use the link table to assign the equivalent 5_k IDs to the points with 6_K IDs; and then use the 5_k IDs in both point sets to do what you need to do.

If that's the case, try Join Field tool to transfer the equivalent 5_K IDs to the points through the common 6_K IDs.



hmm... sorry but I don�??t get it ... I do the join and then what? I can´t find a way to calculate distance between the two related points, a near analysis will give me the closest point but that point may not be the one I´m interested on. Using distance tools I´ll get the huge distance matrix again...



In case you do not find a way to get a solution using the system tool, here is a python script you can try on.

import arcpy

proposed = r'D:\data\f.gdb\points_A'
original = r'D:\data\f.gdb\points_B'

# create an empty dictionary to store shapes
proposed_points = {}  
with arcpy.da.SearchCursor(proposed, ("5k_ID", "Shape@")) as cursor:
    
    for row in cursor:
        # populate the dictionary
        # use 5k_ID field value as the key of the dictionary
        proposed_points[row[0]] = row[1]  
        
# create another dictionary
original_points = {}
with arcpy.da.SearchCursor(original, ("5k_ID", "Shape@")) as cursor:
    
    for row in cursor:
        # populate the dictionary
        # use 5k_ID field value as the key of the dictionary
        original_points[row[0]] = row[1]  

    
# iterate one of the dictionaries with ID values
for id_5k in proposed_points:
    
    # get proposed and original points with same ID
    orig = original_points[id_5k]
    prop = proposed_points[id_5k]
    
    # now find the distance
    dist = prop.distanceTo(orig)
    
    print dist


That script looks good... i´ll try to look intoit and let you know how it goes... THX a lot!!
0 Kudos
TOMKONG
Occasional Contributor II
hmm... sorry but I don�??t get it ... I do the join and then what? I can´t find a way to calculate distance between the two related points, a near analysis will give me the closest point but that point may not be the one I´m interested on. Using distance tools I´ll get the huge distance matrix again...





That script looks good... i´ll try to look intoit and let you know how it goes... THX a lot!!


The 5# post is correct:
1.Add X, Y fields for each feature class, then calculate to add X,Y values for each point.
2.Join two point feature classes by using sampling location ID, export the joined layer.
3.In the joined layer, add one new field (distance), calculate the distance for each pair point by using field calculator based on their X&Y.
If using spatial join, the result may have some errors for some sampling locations.

If points X&Y are same(convert to string value and put X, Y to one field, then summarize this field to find duplicates), they should be duplicate.----it's an another useful application by calculating geometry.
0 Kudos