コード例 #1
0
ファイル: MyUtils.php プロジェクト: romanvlcek/wifimap
 /**
  * generate key for cache save
  *
  * @param string $mode
  * @param Coords $coords
  * @param int $zoom
  * @param array[] $params
  * @return string
  */
 public static function generateCacheKey($mode, $coords, $zoom, $params = array())
 {
     $key = $mode . ':' . $coords->getLatStart() . ':' . $coords->getLatEnd() . ':' . $coords->getLonStart() . ':' . $coords->getLonEnd() . ':' . $zoom;
     if (count($params) > 0) {
         $key .= "::";
         foreach ($params as $k => $v) {
             $key .= "~" . $k . "=" . $v;
         }
     }
     return $key;
 }
コード例 #2
0
ファイル: WifiManager.php プロジェクト: romanvlcek/wifimap
 /**
  * return nets data in passed lat lng range
  *
  * @param Coords $coords
  * @param array $select
  * @param bool $asArray
  * @return Wifi[]
  */
 public function getAllNetsInLatLngRange($coords, $select = array('*'), $asArray = false)
 {
     $sqlSelect = $this->buildSelect($select);
     $sql = 'SELECT ' . $sqlSelect . ' FROM ' . self::TABLE . ' WHERE  (`latitude` > ?) AND (`latitude` < ?) AND (`longitude` > ?) AND (`longitude` < ?)';
     $pdo = $this->database->getConnection()->getPdo();
     $sth = $pdo->prepare($sql);
     $sth->execute(array($coords->getLatStart(), $coords->getLatEnd(), $coords->getLonStart(), $coords->getLonEnd()));
     $data = $sth->fetchAll(\PDO::FETCH_ASSOC);
     // return as array of Objects
     if (!$asArray) {
         $wifi = array();
         foreach ($data as $w) {
             $wifi[] = Wifi::createWifiFromDBRow($w);
         }
         $data = $wifi;
     }
     return $data;
 }
コード例 #3
0
ファイル: WigleDownload.php プロジェクト: romanvlcek/wifimap
 /**
  * @param Coords $coords
  * @param int $first
  * @return string JSON with Wigle data
  */
 private function getDataFromWigle($coords, $first = 0)
 {
     $arr = array("longrange1" => $coords->getLonStart(), "longrange2" => $coords->getLonEnd(), "latrange1" => $coords->getLatStart(), "latrange2" => $coords->getLatEnd());
     if ($first != 0) {
         $arr["first"] = $first;
         $arr["last"] = $first + 99;
     }
     return $this->sendCurlRequest(self::WIGLE_GETDATA_URL, $arr);
 }
コード例 #4
0
 /**
  * create X,Y array MAP
  * index to lat or lng
  *
  * @param array|\Nette\Database\Table\IRow[] $data
  * @param Coords $coords
  * @return array
  */
 private function createMappingXY($data, $coords)
 {
     $mappingX = array($coords->getLatStart(), $coords->getLatEnd());
     $mappingY = array($coords->getLonStart(), $coords->getLonEnd());
     foreach ($data as $d) {
         $d_coords = new Coords($d['lat_start'], $d['lat_end'], $d['lon_start'], $d['lon_end']);
         if (!in_array($d_coords->getLatStart(), $mappingX) && $d_coords->getLatStart() >= $coords->getLatStart() && $d_coords->getLatStart() <= $coords->getLatEnd()) {
             $mappingX[] = $d_coords->getLatStart();
         }
         if (!in_array($d_coords->getLatEnd(), $mappingX) && $d_coords->getLatEnd() <= $coords->getLatEnd() && $d_coords->getLatEnd() >= $coords->getLatStart()) {
             $mappingX[] = $d_coords->getLatEnd();
         }
         if (!in_array($d_coords->getLonStart(), $mappingY) && $d_coords->getLonStart() >= $coords->getLonStart() && $d_coords->getLonStart() <= $coords->getLonEnd()) {
             $mappingY[] = $d_coords->getLonStart();
         }
         if (!in_array($d_coords->getLonEnd(), $mappingY) && $d_coords->getLonEnd() <= $coords->getLonEnd() && $d_coords->getLonEnd() >= $coords->getLonStart()) {
             $mappingY[] = $d_coords->getLonEnd();
         }
     }
     sort($mappingX);
     sort($mappingY);
     return array('xMap' => $mappingX, 'yMap' => $mappingY);
 }
コード例 #5
0
 /**
  * counts lat lng range shown in one pixel
  * onepxlat -> latitude range in one pixel
  * onepxlon -> longitude range in one pixel
  *
  * @param Coords $coords
  * @uses OverlayRenderer::IMAGE_BIGGER as size of image
  * @return object
  */
 private function getConversionRatio($coords)
 {
     $one_pixel_lat = abs($coords->getLatEnd() - $coords->getLatStart()) / self::IMAGE_BIGGER;
     $one_pixel_lon = abs($coords->getLonEnd() - $coords->getLonStart()) / self::IMAGE_BIGGER;
     return (object) array("onepxlat" => $one_pixel_lat, "onepxlon" => $one_pixel_lon);
 }
コード例 #6
0
 /**
  * return number of nets on Wigle overlay Image
  *
  * @param Coords $coords
  * @return int
  */
 private function analyzeImage($coords)
 {
     // TODO: ziskavat i jinak celky obrazek nez ctverec pokud mam jiny rozsah souradnic nez ctverec?
     $params = array("lat1" => $coords->getLatStart(), "long1" => $coords->getLonStart(), "lat2" => $coords->getLatEnd(), "long2" => $coords->getLonEnd(), "redir" => "Y", "networksOnly" => "Y", "sizeX" => 256, "sizeY" => 256);
     $url = self::WIGLE_IMAGE_OVERLAY_URL . "?" . http_build_query($params);
     $headers = get_headers($url, 1);
     $url = self::WIGLE_URL . trim($headers["Location"]);
     $image = imagecreatefrompng($url);
     $points = 0;
     for ($x = 0; $x < 256; $x++) {
         for ($y = 0; $y < 256; $y++) {
             if (in_array(dechex(imagecolorat($image, $x, $y)), $this->wigleNetColors)) {
                 $points++;
             }
         }
     }
     return $points;
 }