4

I'm using LASlib to find the nearest neighbors of a subset of points in a point cloud. I'm using brute force to find nearest neighbors, which is extremely slow (my code below). Is there a better way, using the LASlib API to find nearest neighbors?

LASreadOpener lasreadopener;
lasreadopener.set_file_name("myLasFile.las");
LASreader* lasreader = lasreadopener.open();

float searchDistance = 1.0f;
I64 idx;
while (lasreader->read_point())
{
    //check to see if this point meets my conditions
    if (!conditions_met) // just pseudo code, i acutally check certain point attributes
    {
        continue;
    }

    idx = lasreader->p_count;
    double x = lasreader->point.get_x();
    double y = lasreader->point.get_y();

    // return to beginning
    lasreader->seek(0);

    // loop through all points
    while (lasreader->read_point())
    {
        if (lasreader->point.inside_circle(x, y, searchDistance))
        {
            // do something with this point
        }
    }

    //return to original loop point
    lasreader->seek(idx);
}
lasreader->close();
delete lasreader;
2

You need to use the spatial indexing capability available within LASlib. Here is an example for running a query on one point that is known a priori. Note that you need your LAS file to have an accompanying LAX file generated with LASindex for this to be any faster.

F64 x = 520450;
F64 y = 2223045; 
F32 searchDistance = 1.0f;
LASreadOpener lasreadopener;
lasreadopener.set_file_name("myLasFile.las");
lasreadopener.set_inside_circle(x, y, searchDistance);

LASreader* lasreader = lasreadopener.open();

while (lasreader->read_point())
{
   // do something with this point
}

lasreader->close();
delete lasreader;
  • Please do not use your answers to advertise a help site that you appear to be affiliated with. – PolyGeo Sep 16 '17 at 6:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.