2017-03-07 26 views
-1

私は、そしてこれは私が整数に入れていても解消されない:TypeError:__init __()は正確に4つの引数をとります(3与えられます)Point Shapely

私は私のプログラムのために、次のエラーを取得:

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) 

とラインストリングである私は(取得出力を、私は最初のポイントとして座標必要):

LINESTRING (62.45216400000002 25.25002557370135, 62.34162800000001 25.33145349735835) 

# need: (62.452164000000018, 25.25002557370135) 

コード全体を読む必要がないように問題の領域を示しました。私の問題はポイントを作成できないため、理由がわかりません。ここ は私のコードです:

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]) 

問題領域はここにある:、何かアドバイスは大歓迎です

    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') 

私が間違って格好の良いからポイントを使用していますか?

+0

@downvoter私が改善できるものについて言及せずにdownvotingに感謝します。 – LoveMeow

+1

'from shapely.geometry import point'を使用してポイントをインポートしましたか? – James

+0

はい、私は、交点(点)が線ストリングでない場合に使用します – LoveMeow

答えて

0

try Point((1.0,2.0))(かっこを追加)。また、print Pointを追加し、整形されたインポートされたクラスが表示されていることを確認します(Pointを再定義してクラスをオーバーライドしなかったことを確認してください)。

0

@bruno desthuilliersのコメントは最近インストールされたすべてのライブラリをチェックしました。問題は、私が最近インストールしたベクターライブラリでした。一度問題がなくなりました。ありがとうございました!

関連する問題