Ejemplo n.º 1
0
 /**
  * 
  * @param Coordinates $coordinates
  * @return Tile
  */
 public function getTile($coordinates)
 {
     if (array_key_exists($coordinates->getUniqueIndex(), $this->tiles)) {
         return $this->tiles[$coordinates->getUniqueIndex()];
     }
     return $this->defaultTile;
 }
Ejemplo n.º 2
0
 protected function getPointMock($dimension = null, $srid = null, Coordinates $coordinates = null)
 {
     $mock = $this->getGeometryMockForClass('GeoIO\\Geometry\\Point', $dimension, $srid);
     if ($coordinates) {
         $mock->expects($this->any())->method('getX')->will($this->returnValue($coordinates->getX()));
         $mock->expects($this->any())->method('getY')->will($this->returnValue($coordinates->getY()));
         $mock->expects($this->any())->method('getZ')->will($this->returnValue($coordinates->getZ()));
         $mock->expects($this->any())->method('getM')->will($this->returnValue($coordinates->getM()));
     }
     return $mock;
 }
Ejemplo n.º 3
0
 /**
  * Проверка, находится ли ровер в пределах полигона
  *
  * @param int $sizeX размер полигона по оси X
  * @param int $sizeY размер полигона по оси Y
  * @param int $posX позиция ровера по оси X
  * @param int $posY позиция ровера по оси Y      
  * @return bool      
  **/
 public function checkPos(Polygon $polygon, Coordinates $coord)
 {
     $sizeX = $polygon->getSize()->getX();
     $sizeY = $polygon->getSize()->getY();
     $posX = $coord->getX();
     $posY = $coord->getY();
     if ($posX > $sizeX or $posX < 0 or $posY > $sizeY or $posY < 0) {
         return false;
     } else {
         return true;
     }
 }
Ejemplo n.º 4
0
 /**
  * Returns the longitude value.
  *
  * @return double
  */
 public function getLongitude()
 {
     if (null === $this->coordinates) {
         return null;
     }
     return $this->coordinates->getLongitude();
 }
Ejemplo n.º 5
0
 private function tileToHTML(Tile $tile, array $screenCoords, Coordinates $coordinates)
 {
     $classTile = 'clear';
     $label = '';
     if (!$tile->isClear()) {
         $classTile = 'occupied';
     }
     if ($tile->hasGoalPathMarker()) {
         $classTile = 'goalPath';
     }
     if ($tile->hasStartMarker()) {
         $classTile = 'start';
         $label = 'start';
     }
     if ($tile->hasGoalMarker()) {
         $classTile = 'goal';
         $label = 'goal';
     }
     return '<div class="tile ' . $classTile . '" style="left:' . $screenCoords[0] . 'px; top:' . $screenCoords[1] . 'px; width:' . $this->tile_size . 'px; height:' . $this->tile_size . 'px;" title="' . $coordinates->__toString() . '">' . $label . '</div>';
 }
Ejemplo n.º 6
0
 public function DistanceFrom(Coordinates $c)
 {
     global $NN_config;
     $distance = 0;
     if ($this->Galaxy() - $c->Galaxy() != 0) {
         $distance = abs($this->Galaxy() - $c->Galaxy()) * $NN_config["galaxy_distance"];
     } elseif ($this->System() - $c->System() != 0) {
         $distance = abs($this->System() - $c->System()) * $NN_config["system_distance"];
     } elseif ($this->Planet() - $c->Planet() != 0) {
         $distance = abs($this->Planet() - $c->Planet()) * $NN_config["planet_distance"];
     } else {
         $distance = 5;
     }
     return $distance;
 }
Ejemplo n.º 7
0
 public function findAction()
 {
     $bdd = Connection::ConnectToMySQL();
     if (isset($_GET['lat']) && isset($_GET['lon'])) {
         if (isset($_GET['radius'])) {
             $radius = $_GET['radius'];
         } else {
             $radius = 10;
         }
         $coord = new Coordinates(floatval($_GET['lat']), floatval($_GET['lon']));
         if ($radius > 40) {
             $radius = 40;
         }
         $s_lat = $coord->getLatitude() - 0.09 * ($radius / 10);
         //Check for
         $s_lon = $coord->getLongitude() - 0.125 * ($radius / 10);
         $e_lat = $coord->getLatitude() + 0.09 * ($radius / 10);
         $e_lon = $coord->getLongitude() + 0.125 * ($radius / 10);
         $date = '2014-00-00';
         //Base date
         $request = $bdd->prepare("SELECT * FROM fuel_station LEFT JOIN fuel_price ON last_update = fuel_price.price_id WHERE latitude >= :s_lat AND latitude <= :e_lat AND longitude >= :s_lon AND longitude <= :e_lon AND last_update >= :date");
         //Only select station with a valid price
         $request->execute(array('s_lat' => $s_lat, 'e_lat' => $e_lat, 's_lon' => $s_lon, 'e_lon' => $e_lon, 'date' => $date));
         $station = array();
         while ($donnees = $request->fetch()) {
             $station_row = new FuelStation();
             $station_row->setStationId($donnees['station_id']);
             $station_row->setCoordinates(new Coordinates($donnees['latitude'], $donnees['longitude']));
             $station_row->setPostalCode($donnees['postal_code']);
             $station_row->setAddress($donnees['address']);
             $station_row->setCity($donnees['city']);
             $station_row->setStationName($donnees['station_name']);
             $station_row->setBrand($donnees['brand']);
             $station_row->setLastUpdate($donnees['date']);
             //Replace by a join
             $station_row->updateDistance($coord);
             $station_row->setFuelPrice(new FuelPrice($donnees['diesel_price'], $donnees['petrol95_price'], $donnees['petrol95E10_price'], $donnees['petrol98_price'], $donnees['gpl_price']));
             array_push($station, $station_row);
         }
         if (count($station) <= 0) {
             Message::sendJSONMessage(true, "Aucune station trouvée");
             return;
         }
         Message::sendJSONMessage(false, $station);
     }
 }
Ejemplo n.º 8
0
 public function toArray()
 {
     return array('southwest' => array('lat' => $this->southwest->getLat(), 'lng' => $this->southwest->getLng()), 'northeast' => array('lat' => $this->northeast->getLat(), 'lng' => $this->northeast->getLng()));
 }
Ejemplo n.º 9
0
 /**
  * @param string $type
  * @param string $coordinates
  */
 public function __construct($type, $coordinates, $name = null)
 {
     parent::__construct($coordinates);
     $this->_type = $type;
     $this->_name = $name;
 }
 /**
  * [doScrapping description]
  * @param  [type] $endpoint [description]
  * @return [type]           [description]
  */
 private function doScrapping($endpoint)
 {
     $event = null;
     $earthquake = null;
     $i = 0;
     Debugger::dump('endpoint: ' . $endpoint . '    _' . $_SERVER['HTTP_USER_AGENT']);
     Debugger::dump('***INICIANDO SCRAPPING****');
     $content = $this->scrapper->getContent($endpoint);
     if ($content) {
         $this->scrapper->domLoad($content);
         $tableList = $this->scrapper->findInDom('table tbody tr');
     } else {
         Debugger::dump('***ERROR, NO SE OBTUBIERON DATOS');
     }
     //get each table node
     foreach ($tableList as $tableKey => $table) {
         $earthquakeData = array();
         //get each data item
         $i = 0;
         foreach ($table->find('td') as $itemKey => $tableItem) {
             $earthquakeData[$itemKey] = $tableItem->text();
             $i++;
         }
         if ($i < 8 or empty($earthquakeData)) {
             continue;
         }
         $latDMSArr = Coordinates::extractDMS($earthquakeData[2]);
         $lonDMSArr = Coordinates::extractDMS($earthquakeData[3]);
         $lat = Coordinates::DMStoDEC($latDMSArr['coordinates'][0], $latDMSArr['coordinates'][1], 0, $latDMSArr['geoDir']);
         $lon = Coordinates::DMStoDEC($lonDMSArr['coordinates'][0], $lonDMSArr['coordinates'][1], 0, $lonDMSArr['geoDir']);
         $dateUTC = $earthquakeData[0];
         $dateTs = DatesUtils::toTimestamp($dateUTC);
         $dateSQL = DatesUtils::toSQLDate($dateUTC);
         $eventData = array('lat' => $lat, 'lon' => $lon, 'ts' => $dateSQL, 'hash' => md5($dateTs));
         /*  Evitar crear eventos duplicados que muestren erroneamente más de un evento siendo que se trata del mismo
          *  pero actualizado.
          *  Esto se hace debido a que el primer informe ante un evento, puede ser preliminar
          *  y se pueden publicar actualizaciones de datos con cambios en magnitud o ubicación geográfica posteriormente.
          */
         $eventExists = $this->Event->checkForExists($eventData, $this->dateBounds);
         if ($eventExists['exists']) {
             Debugger::dump('***EVENTO YA EXISTE ****');
             //echo ('evento ya existe <br>');
             $event = $eventExists;
         } else {
             Debugger::dump('***NO SE ENCONTRO EVENTO, CREANDO ****');
             $this->Event->create();
             $event = $this->Event->save($eventData);
         }
         if ($event) {
             $metadatum = array('event_id' => $event['Event']['id'], 'agency_id' => 2, 'lat' => $eventData['lat'], 'lon' => $eventData['lon'], 'ts' => $dateSQL, 'depth' => $earthquakeData[4], 'magnitude' => floatval($earthquakeData[1]), 'geo_reference' => $earthquakeData[7], 'magnitude_type' => $earthquakeData[1] > 3.5 ? 'Mw' : 'Ml');
             if (!$eventExists['exists']) {
                 Debugger::dump('***SISMO NO EXISTE, CREANDO ****');
                 $this->EventMetadatum->create();
                 $earthquake = $this->EventMetadatum->save($metadatum);
             } else {
                 $earthquakeExists = $this->EventMetadatum->checkForExists($metadatum, $this->dateBounds, $eventExists['Event']['id']);
                 if ($earthquakeExists['exists']) {
                     Debugger::dump('***EVENTO EXISTE, SISMO TAMBIEN ****');
                 } else {
                     Debugger::dump('***EVENTO EXISTE, NUEVO SISMO NO. CREANDO NUEVO ASOCIADO A EVENTO****');
                     $this->EventMetadatum->create();
                     $earthquake = $this->EventMetadatum->save($metadatum);
                 }
             }
         }
     }
 }
Ejemplo n.º 11
0
function buildCoordinates($coordinatesXMLObject)
{
    $coordinates = new Coordinates();
    $coordinates_string = $coordinatesXMLObject;
    if (is_object($coordinatesXMLObject)) {
        $coordinates_string = $coordinatesXMLObject->__toString();
    }
    $coordinates_array = explode(",", $coordinates_string);
    if (isset($coordinates_array[0])) {
        $coordinates->setLongitude($coordinates_array[0]);
    }
    if (isset($coordinates_array[1])) {
        $coordinates->setLatitude($coordinates_array[1]);
    }
    if (isset($coordinates_array[2])) {
        $coordinates->setAltitude($coordinates_array[2]);
    }
    return $coordinates;
}
Ejemplo n.º 12
0
 public function jsonSerialize()
 {
     return array_merge(array('resources' => $this->resources), parent::jsonSerialize());
 }
Ejemplo n.º 13
0
 /**
  * __equals
  *
  * @param Coordinates $coordinates
  * @return boolean
  */
 function __equals($coordinates)
 {
     return $this->x == $coordinates->getX() && $this->y == $coordinates->getY();
 }
Ejemplo n.º 14
0
 public function testConstructorShouldAllowEmptyZAndMCoordinates()
 {
     $coordinates = new Coordinates(1, 2);
     $this->assertNull($coordinates->getZ());
     $this->assertNull($coordinates->getM());
 }
Ejemplo n.º 15
0
if ($user == NULL) {
    return;
}
// Fill galaxy and system selection menu
if ($_GET) {
    $system = $_GET['system'];
    if (isset($_GET['systemRight'])) {
        $system++;
    } elseif (isset($_GET['systemLeft'])) {
        $system--;
    }
    $galaxy = $_GET['galaxy'];
    if (isset($_GET['galaxyRight'])) {
        $galaxy++;
    } elseif (isset($_GET['galaxyLeft'])) {
        $galaxy--;
    }
} else {
    $galaxy = $user->CurrentColony()->Coordinates()->Galaxy();
    $system = $user->CurrentColony()->Coordinates()->System();
}
$coordinates = new Coordinates($galaxy, $system, 1);
// The Coordinates class automatically clamps values, so they're always within range
$vars['current_galaxy'] = $coordinates->Galaxy();
$vars['current_system'] = $coordinates->System();
// Render new galaxy view
$view = new GalaxyView($user, $coordinates);
$vars['galaxy_view'] = $view->Render();
// Render galaxy page
$page = new Page("galaxy/galaxy", $vars, "Galaxy View", "galaxy_view");
echo $page->Display();
Ejemplo n.º 16
0
 public function jsonSerialize()
 {
     return array_merge(array('type' => $this->type, 'name' => $this->name), parent::jsonSerialize());
 }
Ejemplo n.º 17
0
 /**
  * @param string $type
  * @param string $coordinates
  */
 public function __construct($coordinates, $metal, $crystal)
 {
     parent::__construct($coordinates);
     $this->_resources = new Resources($metal, $crystal, 0);
 }
Ejemplo n.º 18
0
 private function newAdjacentPlacements(Coordinates $placement)
 {
     $newPlacements = [];
     $neighbors = $placement->getNeighbors();
     return array_filter($neighbors, [$this, 'newPlacementAtPosition']);
 }
Ejemplo n.º 19
0
 /**
  * @param Coordinates $other
  * @return Coordinates
  */
 public function subtract($other)
 {
     return $this->add($other->multiply(-1));
 }