嗨,大家好。
我有这个非常复杂的问题在这里解释。所以基本上,这是数据表:

我应该使用JSL脚本创建一个名为“你周围的总坐标”的列,通过想象在特定坐标周围有8个方格(基本上不包括它自己的坐标),如下图所示,其中小蓝圈代表这个特定的坐标。因此,最大“您周围的总坐标”为8。例如,如上图所示,通过数字9998887,坐标(-2,1)的“你周围的总坐标”为3,即(-2,2),( - 1,1)和(-1,0)。仅作为注释,横轴表示x坐标的偏移,同样,纵轴表示x坐标的偏移。从上面的数据表中可以很容易地得出20“你周围的总坐标”,但在我的实际任务中,有大约23,000多行需要处理。另外,我还应该根据上面数据表中显示的9465371和9998887(它们具有相同的坐标)对数字进行排序,然后再处理“您周围的总坐标”。

dt = current data table();
dt << New column ("Total Coordinates Around You",
numeric,
continuous,
formula (
For ( i = 1, i<= N Row(), i++,
(:Total Coordinates Around You = 0; munipulated_x = :X-Coordinate - 1; munipulated_y = Y-Coordinate - 1; j = 1; k = 1; formula (
For ( j = 1, j <= 3, j++,
(formula(
For ( k = 1, k <= 3, k++,
(formula( If (munipulated_x == :X-Coordinate & munipulated_y == :Y-Coordinate, :Total Coordinates Around You))
; munipulated_y ++)
)
) ; munipulated_x ++)
)
) ; :Total Coordinates Around You --)
)
)
);上面是我创建的一个脚本,我不知道为什么这不能使用循环。有人可以告诉我有关如何处理这个问题的步骤和解决方案吗?这个问题还有第二部分,一旦我完成第一部分,我将尝试。如果对问题和解释的清晰度有任何疑问,请允许我解释,并再次原谅我的解释。谢谢。
我不会在公式中执行它,因为它针对每一行运行,因此在公式内部循环将导致您非常慢。
这可能不是最好的方式,但似乎有效。 假设我理解正确并且您正在尝试找到有多少瓷砖触及您的开始瓷砖?
如果您正在尝试这样做,请告诉我。
Names default to here(1);
dt = New Table( "Example",
Add Rows( 20 ),
New Column( "Number",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values(
[9465371, 9465371, 9465371, 9465371, 9465371, 9465371, 9465371, 9465371,
9465371, 9465371, 9998887, 9998887, 9998887, 9998887, 9998887, 9998887,
9998887, 9998887, 9998887, 9998887]
)
),
New Column( "X-Coordinate",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values(
[2, 2, 1, 1, 0, 0, -1, -1, -2, -2, 2, 2, 1, 1, 0, 0, -1, -1, -2, -2]
)
),
New Column( "Y-Coordinate",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Selected,
Set Values( [2, 1, 0, -1, 3, 2, 1, 0, 2, 1, 2, 1, 0, -1, 3, 2, 1, 0, 2, 1] )
),
New Column("Adjacent", Numeric, "Continuous")
);
summarize(dt, byn = By(:Number));
for(i=1, i<=nitems(byn), i++,
sel = byn[i];
rows = dt << Get Rows Where(:Number == num(sel));
mat = dt[rows, {"X-Coordinate", "Y-Coordinate"}];
for(k = 1, k<=nrows(rows), k++,
row = rows[k];
// do a check that you're within the limit
adj = sqrt( (mat[k, 1] - mat[0, 1])^2 + (mat[k, 2] - mat[0, 2])^2) <= sqrt(2);
Column(dt, "Adjacent")[row] = nrows(Loc(adj)) - 1;
)
);我不确定我是否理解这个要求,但是如果你想找到给定点的相邻点,你也可以使用'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 thes 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 ) ) )
);