Exemple #1
0
 static function line($pointList, $epsilon)
 {
     // Find the point with the maximum distance
     $dmax = 0;
     $index = 0;
     $totalPoints = count($pointList);
     for ($i = 1; $i < $totalPoints - 1; $i++) {
         $d = Simplify::perpendicularDistance($pointList[$i]['x'], $pointList[$i]['y'], $pointList[0]['x'], $pointList[0]['y'], $pointList[$totalPoints - 1]['x'], $pointList[$totalPoints - 1]['y']);
         if ($d > $dmax) {
             $index = $i;
             $dmax = $d;
         }
     }
     $resultList = array();
     // If max distance is greater than epsilon, recursively simplify
     if ($dmax >= $epsilon) {
         // Recursive call
         $recResults1 = Simplify::line(array_slice($pointList, 0, $index + 1), $epsilon);
         $recResults2 = Simplify::line(array_slice($pointList, $index, $totalPoints - $index), $epsilon);
         // Build the result list
         $resultList = array_merge(array_slice($recResults1, 0, count($recResults1) - 1), array_slice($recResults2, 0, count($recResults2)));
     } else {
         $resultList = array($pointList[0], $pointList[$totalPoints - 1]);
     }
     // Return the result
     return $resultList;
 }
Exemple #2
0
 function upload()
 {
     require_once APPPATH . 'third_party/ShapeFile.php';
     require_once APPPATH . 'third_party/Simplify.php';
     $options = array('noparts' => false);
     try {
         $shp = new ShapeFile($_FILES['shp_file']['tmp_name'], null, $options);
         $polygons = array();
         while ($record = $shp->getNext()) {
             $shpData = $record->getShpData();
             foreach ($shpData['parts'] as $part) {
                 $polygons[] = Simplify::line($part['points'], count($part['points']) / 1000000);
             }
         }
     } catch (Exception $e) {
         $this->session->set_flashdata('error', $e->getMessage());
     }
     $this->user_polygons_model->save(array('user_id' => $this->tank_auth->get_user_id(), 'name' => $_FILES['shp_file']['name'], 'points' => json_encode($polygons)));
     redirect('/areas');
 }