Пример #1
0
function buildQuadTree($filename)
{
    //  Set the centrepoint of our QuadTree at 0.0 Longitude, 0.0 Latitude
    $centrePoint = new \QuadTrees\QuadTreeXYPoint(0.0, 0.0);
    //  Set the bounding box to the entire globe
    $quadTreeBoundingBox = new \QuadTrees\QuadTreeBoundingBox($centrePoint, 360, 180);
    //  Create our QuadTree
    $quadTree = new \QuadTrees\QuadTree($quadTreeBoundingBox);
    echo "Loading cities: ";
    $cityFile = new \SplFileObject($filename);
    $cityFile->setFlags(\SplFileObject::READ_CSV | \SplFileObject::DROP_NEW_LINE | \SplFileObject::SKIP_EMPTY);
    //  Populate our new QuadTree with cities from around the world
    $cityCount = 0;
    foreach ($cityFile as $cityData) {
        if (!empty($cityData[0])) {
            if ($cityCount % 1000 == 0) {
                echo '.';
            }
            $city = new cityPoint($cityData[0], $cityData[1], $cityData[3], $cityData[2]);
            $quadTree->insert($city);
            ++$cityCount;
        }
    }
    echo PHP_EOL, "Added {$cityCount} cities to QuadTree", PHP_EOL;
    return $quadTree;
}
Пример #2
0
function buildQuadTree($filename)
{
    //  Set the centrepoint of our QuadTree at 0.0 Longitude, 0.0 Latitude
    $centrePoint = new \QuadTrees\QuadTreeXYPoint(0.0, 0.0);
    //  Set the bounding box to the entire globe
    $quadTreeBoundingBox = new \QuadTrees\QuadTreeBoundingBox($centrePoint, 360, 180);
    //  Create our QuadTree
    $quadTree = new \QuadTrees\QuadTree($quadTreeBoundingBox);
    echo "Loading lunarLandings: ";
    $landingFile = new \SplFileObject($filename);
    $landingFile->setFlags(\SplFileObject::READ_CSV | \SplFileObject::DROP_NEW_LINE | \SplFileObject::SKIP_EMPTY);
    //  Populate our new QuadTree with lunarLandings from around the world
    $lunarLandingCount = 0;
    foreach ($landingFile as $lunarLandingData) {
        if (!empty($lunarLandingData[0])) {
            if ($lunarLandingCount % 10 == 0) {
                echo '.';
            }
            $lunarLanding = new lunarLandingPoint(trim($lunarLandingData[0]), trim($lunarLandingData[1]), trim($lunarLandingData[2]), trim($lunarLandingData[4]), trim($lunarLandingData[3]));
            $quadTree->insert($lunarLanding);
            ++$lunarLandingCount;
        }
    }
    echo PHP_EOL, "Added {$lunarLandingCount} lunar landing details to QuadTree", PHP_EOL;
    return $quadTree;
}