줄무늬를 사용하여 점을 만드는 프로그램을 쓰려고하는데, 어떻게 든 점을 만들려고 할 때 Linestring
다음 오류가 발생합니다. 이것은 내가 정수 번호를 넣어 경우에도 지속 :TypeError : __init __() 정확히 4 인수 (3 주어진) 점을 정확하게 걸립니다
내가 얻을 내 프로그램에 대한 다음과 같은 오류 :
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)
전체 코드를 읽지 않아도되는 문제 영역을 지적 했으므로 문제점을 만들 수없고 그 이유를 모르겠습니다. 내가 잘못 매끈한에서 포인트를 사용하고
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')
어떤 조언을 환영합니다 :
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])
문제 영역은 여기에 있습니다 : 여기 내 코드?
@downvoter 내가 개선 할 수있는 것을 언급하지 않고 downvoting에 감사드립니다. – LoveMeow
'from shapely.geometry import point'를 사용하여 Point를 가져 왔습니까? – James
예, 교차점 (포인트)이 선 스트링이 아닌 경우 작동합니다. – LoveMeow