How can I evaluate the longitudinal and the lateral differences between two points from the Northing and Easting values?

1205
4
03-28-2018 02:26 AM
SanhitaDas
New Contributor

This is in reference to an experimental work which we have conducted for evaluating the positional difference between two vehicles, data being collected using Video VBox. We have the latitude/longitude and therefore, the corresponding Northing/Easting values of both the vehicles at the same time instant. For the purpose of my work, I want to know the longitudinal distance between A1 and B1 (Y in the attached figure) and the lateral distance (X) at each time step. The trajectories of both the vehicles at different time steps are also depicted in the figure. In addition, the details of the northing/easting values of both the vehicles are also attached in the excel file.

Is there any toolbox in ArcGis which can directly give the positional differences (both X and Y)? Or, can you help me in providing a way by which these X and Y values can be obtained?

Thanks, 

Sanhita

0 Kudos
4 Replies
XanderBakker
Esri Esteemed Contributor

As far as I can see from the data, there is a slight difference in the angle of the path traveled by car A and car B. Which angle should be used to determine the values for X and Y? In this simple case you have both cars traveling in the rather straight line. What happens at a curve or when a car changes direction?

Let's assume that car A defines the direction and the direction is based on the current and next point. In that case you could solve it using the following script.

def main():
    import arcpy

    # imput data
    tbl = r'C:\GeoNet\CarChase\data.gdb\cars'
    fld_XA = 'EastingA'
    fld_YA = 'NorthingA'
    fld_XB = 'EastingB'
    fld_YB = 'NorthingB'
    sr = arcpy.SpatialReference(32643) # define the correct sr

    # output fields
    fld_londist = 'LonDistY' # longitudinal distance (Y)
    fld_latdist = 'LatDistX' # lateral distance (X)

    # some vars
    distance_ahead = 1000.0

    # get data
    flds = ('OID@', fld_XA, fld_YA, fld_XB, fld_YB)
    dct_data = {r[0]: [r[1], r[2], r[3], r[4]] for r in arcpy.da.SearchCursor(tbl, flds)}

    dct_result = {}
    lst_oid = sorted(dct_data.keys())
    for i in range(len(lst_oid)-1):
        oid_cur = lst_oid[i]
        oid_next = lst_oid[i+1]
        data_cur = dct_data[oid_cur]
        data_next = dct_data[oid_next]
        pntg_a = arcpy.PointGeometry(arcpy.Point(data_cur[0], data_cur[1]), sr)
        pntg_a_next = arcpy.PointGeometry(arcpy.Point(data_next[0], data_next[1]), sr)
        pntg_b = arcpy.PointGeometry(arcpy.Point(data_cur[2], data_cur[3]), sr)
        angle = GetAngle(pntg_a, pntg_a_next)

        pntg_b_proj = pntg_b.pointFromAngleAndDistance(angle, distance_ahead, "PLANAR")
        polyline = arcpy.Polyline(arcpy.Array([pntg_b.firstPoint, pntg_b_proj.firstPoint]), sr)
        tpl_qpd = polyline.queryPointAndDistance(pntg_a, False)
        dist_long = tpl_qpd[1]
        dist_lat = tpl_qpd[2]
        dct_result[oid_cur] = [dist_long, dist_lat]

    # add last record too, asume same angle
    pntg_b = arcpy.PointGeometry(arcpy.Point(data_next[2], data_next[3]), sr)
    pntg_b_proj = pntg_b.pointFromAngleAndDistance(angle, distance_ahead, "PLANAR")
    polyline = arcpy.Polyline(arcpy.Array([pntg_b.firstPoint, pntg_b_proj.firstPoint]), sr)
    tpl_qpd = polyline.queryPointAndDistance(pntg_a_next, False)
    dist_long = tpl_qpd[1]
    dist_lat = tpl_qpd[2]
    dct_result[oid_next] = [dist_long, dist_lat]

    # update tbl with results
    flds = ('OID@', fld_londist, fld_latdist)
    with arcpy.da.UpdateCursor(tbl, flds) as curs:
        for row in curs:
            oid = row[0]
            if oid in dct_result:
                result = dct_result[oid]
                row[1] = result[0]
                row[2] = result[1]
                curs.updateRow(row)


def GetAngle(pntg1, pntg2):
    '''determine angle of line based on start and end points geometries'''
    return pntg1.angleAndDistanceTo(pntg2, method='PLANAR')[0]


if __name__ == '__main__':
    main()

Result:

SanhitaDas
New Contributor

Thank you Xander Bakker for providing the script. This is exactly what we wanted because the data were collected for straight sections where the vehicles did not exhibit high lateral movements. But, while running the code, I got the following error message:

""Runtime error
Traceback (most recent call last):
File "<string>", line 69, in <module>
File "<string>", line 33, in main
File "<string>", line 65, in GetAngle
AttributeError: 'PointGeometry' object has no attribute 'angleAndDistanceTo'  ""

Can you please suggest me how to figure it out?

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi Sanhita Das , what version of ArcGIS are you using? angleAndDistanceTo has been a property of the PointGeometry before 10.3 was introduced. 

0 Kudos
SanhitaDas
New Contributor

I am using ArcGIS 10.2.2.

0 Kudos