아마도 이것에 대한 간단한 해결책이 있지만 아직 알아 내지 못했습니다. X 및 Y 위치가있는 위치 ID 테이블이 있습니다. 가장 가까운 위치를 식별하고 해당 위치까지의 유클리드 거리를 계산해야합니다.거리가 너무 번거롭지는 않지만 가장 가까운 위치를 찾는 데 어려움을 겪고 있습니다. 파일이 첨부되었습니다. 감사.
안녕 Peter, 이것은 KNN 플랫폼을 사용하여 이웃 행과 거리를 얻은 다음 새 열에 이웃 ID를 씁니다.
Names Default To Here( 1 );
dt = Current Data Table();
knn = K Nearest Neighbors(
X( :X Location, :Y Location ),
K( 1 ),
save near neighbor rows,
save near neighbor distances
);
knn << close window;
dt << New Column( "Neighbor ID", formula( dt:siteId[:rowNear 1] ) );
dt:Neighbor ID << delete formula;
에서 언급 한 'KDTable ()'에서 선택 안녕하세요. , 다음은 예입니다.
Names Default To Here( 1 );
n = 100; // Size of square
// Make a table of x and y locations
dtx = AsTable((1::n)`, << Invisible);
dty = AsTable((1::n)`, << Invisible);
dt = dty << Join( With( dtx ), Cartesian Join );
Close(dtx, NoSave);
Close(dty, NoSave);
Column(dt, 1) << setName("x");
Column(dt, 2) << setName("y");
dt << deleteProperty("Source");
dt << setName("xy Locations");
// Put these locations into a matrix
mat = dt << getAsMatrix;
tbl = KDTable( mat );
// Pick a point in the interior, so we don't need to decide on any boundary conditions
myX = RandomInteger(2, n-1);
myY = RandomInteger(2, n-1);
myRow = Loc(mat[0, 1] == myX & mat[0, 2] == myY);
myRow = myRow[1];
// Find the 8 nearest neighbours to the chosen point
{rows, dist} = tbl << K nearest rows( 8, myRow );
Show( myRow, rows );
// Check it worked
myXvals = Column(dt, "x")[myRow];
myYvals = Column(dt, "y")[myRow];
dt << NewColumn("Distance", Numeric, Continuous, Formula(sqrt((:x - myXvals)^2 +(:y - myYvals)^2)));
dt << selectRows(VConcat(myRow, rows`));
gb = dt << Graph Builder(
Size( 529, 453 ),
Show Control Panel( 0 ),
Variables( X( :x ), Y( :y ), Color( :Distance ) ),
Elements( Points( X, Y, Legend( 5 ) ) )
);