以下は、一連のポイントをグリッド パーティションごとに 1 つのポイントに減らすための疑似コードです (私はあなたの言語を知りません)。ポイントのセットと任意の軸に沿ったパーティションの数を指定します。コードは最初にポイントをウォークスルーして、境界ボックスを形成する最大/最小エンドポイントを見つけます。次に、バウンディング ボックスを X 軸と Y 軸に沿っていくつかのパーティションに分割します。
次に、コードは各グリッド パーティションを通過し、ポイントの配列がグリッド内にあるかどうかを確認します。ポイントがグリッド内にある場合、最初の一致が保持され、残りのポイントが削除されます。コードを変換したり、基準を変更したりして、ポイントを維持してください。
function ReduceGrid( array points, int npartitions )
{
int max_x = 0, max_y = 0;
int min_x = MAX_INT, min_y = MAX_INT
// Find the bounding box of the points
foreach point in points
{
if ( point.X > max_x )
max_x = point.X;
if ( point.Y < min_x )
min_x = point.X;
if ( point.Y > max_y )
max_y = point.Y;
if ( point.Y < min_y )
min_y = point.Y;
}
// Get the X and Y axis lengths of the paritions
float partition_length_x = ( ( float ) ( max_x - min_x ) ) / npartitions;
float partition_length_y = ( ( float ) ( max_y - min_y ) ) / npartitions;
// Reduce the points to one in each grid partition
for ( int n = 0; n < npartitions; n++ )
{
// Get the boundary of this grid paritition
int min_X = min_x + ( n * partition_length_x );
int min_Y = min_y + ( n * partition_length_y );
int max_X = min_x + ( ( n + 1 ) * partition_length_x );
int max_Y = min_y + ( ( n + 1 ) * partition_length_y );
boolean reduce = false; // set to true after finding the first point in the paritition
foreach point in points
{
// the point is in the grid parition
if ( point.X >= min_x && point.X < max_x &&
point.Y >= min_y && point.X < max_y )
{
// first point found
if ( false == reduce )
reduce = true;
else
points.Remove( point ); // remove the point from the list
}
}
}
}
アンドリュー、OpenGeoCode.Org の共同創設者