-1

I am trying to write a program to create lines and points using shapely, somehow when I try to create a point from a Linestring I get the following error, and this persists even if I put in integer numbers:

I get the following error for my program:

TypeError
Traceback (most recent call last)
    <ipython-input-356-a717c6058dbb> in <module>()
    ----> 1 naive_2_meeting(floor_1,floor_2,floor_3,'b5ce04fe','b5ce04fe')

    <ipython-input-355-cb9e84a49a> in naive_2_meeting(floor_1, floor_2, floor_3, uid1, uid2)
     30                 p = p.astype(float)
     31                 print(p[0][0],p[0][1])
---> 32                 point = Point(1.0,2.0)
     33                 # check if intersection a line or a point
     34                 # line 1

TypeError: __init__() takes exactly 4 arguments (3 given)

and the output I get(which is the linestring, I need the first coordinate as a point):

LINESTRING (62.45216400000002 25.25002557370135, 62.34162800000001 25.33145349735835)

# need: (62.452164000000018, 25.25002557370135)

I have indicated the problem area so you dont have to read the whole code, my problem is I cannot create a point and I do not know why. Here is my code:

def naive_2_meeting(floor_1,floor_2,floor_3,uid1,uid2):
    flag = 0
    # check floor 1, convert to numpy array for speed
    floor_1_uid1 = floor_1[floor_1['uid']==uid1].sort_values(['epoch','x','y'],
        ascending=[True,True,True]).as_matrix()
    floor_1_uid2 = floor_1[floor_1['uid']==uid2].sort_values(['epoch','x','y'],
        ascending=[True,True,True]).as_matrix()

    # compare each line segment to each other
    for i in range(0,len(floor_1_uid1)-1):
        a = floor_1_uid1[i][0]
        b = floor_1_uid1[i][1]
        c = floor_1_uid1[i+1][0]
        d = floor_1_uid1[i+1][1]
        for j in range(0,len(floor_1_uid2)-1):
            a1 = floor_1_uid2[j][0]
            b1 = floor_1_uid2[j][1]
            c1 = floor_1_uid2[j+1][0]
            d1 = floor_1_uid2[j+1][1]
            line1 = LineString([(a,b),(c,d)])
            line2 = LineString([(a1,b1),(c1,d1)])

            if line1.intersects(line2):
                # find intersection point
                point = line1.intersection(line2)
                print (point)
                if point.geom_type == 'LineString':
                    # need to extract the begining of the intersecting lineString
                    print('linestring intersection')

                    p = np.array(point)
                    p = p.astype(float)
                    print(p[0][0],p[0][1])

The problem area is here:

                    point = Point(1.0,2.0)
                # check if intersection a line or a point
                # line 1
                # length of segment
                length_total = Point(a,b).distance(Point(c,d))
                length_first_mid = Point(a,b).distance(point)
                #length_last_mid = Point(c,d).distance(point)
                # calculate the time from first to last
                epoch_diff = floor_1_uid1[i+1][4] - floor_1_uid1[i][4]

                time_add = (epoch_diff * length_first_mid) / length_total
                time_meet = floor_1_uid1[i][4] + time_add

                # line 2
                # length of segment
                length_total_1 = Point(a1,b1).distance(Point(c1,d1))
                length_first_mid_1 = Point(a1,b1).distance(point)
                #length_last_mid = Point(c,d).distance(point)
                # calculate the time from first to last
                # assume uniform velocity along an interpolated line
                epoch_diff_1 = floor_1_uid1[j+1][4] - floor_1_uid1[j][4]

                time_add_1 = (epoch_diff_1 * length_first_mid_1) / length_total_1
                time_meet_1 = floor_1_uid1[j][4] + time_add_1

                #is the time within a certain time range
                if np.absolute(time_meet_1-time_meet)<20:
                    print ('They both intersect at ',line1.intersection(line2))
                    flag = 1

                # else it means they cross paths at different times
            elif line1.distance(line2) < 5:
                # find the point
                print('They both intersect')
                flag = 1
                return

    if flag == 0:
        print('They do not intersect')

Any advice is welcome, am I using the Point from Shapely wrongly?

James
  • 32,991
  • 4
  • 47
  • 70
LoveMeow
  • 3,858
  • 9
  • 44
  • 66

2 Answers2

0

Try Point((1.0,2.0)) (adding the parenthesis). Also, add print Point and check the shapely imported class is shown (just to be sure you didn't override the class by redefining Point).

eguaio
  • 3,754
  • 1
  • 24
  • 38
0

The comment made by @bruno desthuilliers made me check all the recently installed libraries, the problem was the vectors library which I recently installed, once removed the problem was gone! Thank you!

LoveMeow
  • 3,858
  • 9
  • 44
  • 66