/** * Filling property 'coordinates' * @global string $egMultiMaps_CoordinatesSeparator * @param string $coordinates * @param string $service Name of map service * @return boolean */ protected function parseCoordinates($coordinates, $service = null) { global $egMultiMaps_CoordinatesSeparator; $array = explode($egMultiMaps_CoordinatesSeparator, $coordinates); if ($service == 'leaflet' && count($array) == 1) { $value = $array[0]; $coord = Geocoders::getCoordinates($value, $service, array('polygon' => true)); if ($coord !== false && is_array($coord['polygon'])) { $this->coordinates = $coord['polygon']; } else { $this->errormessages[] = \wfMessage('multimaps-unable-parse-coordinates', $value)->escaped(); return false; } } else { foreach ($array as $value) { $point = new Point(); if ($point->parse($value, $service)) { $this->coordinates[] = $point; } else { $this->errormessages[] = \wfMessage('multimaps-unable-parse-coordinates', $value)->escaped(); return false; } } } return true; }
public function testInfinity() { $point = new Point(1, 2); $this->assertFalse($point->isInfinity()); $point = new Point(PointInterface::INFINITY, PointInterface::INFINITY); $this->assertTrue($point->isInfinity()); }
/** * draw line on map * * @param Map $map */ public function draw(Map $map) { $image = $map->getImage(); $startPointInPixels = $map->getPixelPointFromCoordinates($this->_startPoint->getLon(), $this->_startPoint->getLat()); $endPointInPixels = $map->getPixelPointFromCoordinates($this->_endPoint->getLon(), $this->_endPoint->getLat()); $this->_drawLine($image, $startPointInPixels['x'], $startPointInPixels['y'], $endPointInPixels['x'], $endPointInPixels['y']); }
/** * @covers Imagine\Image\Point::getX * @covers Imagine\Image\Point::getY * @covers Imagine\Image\Point::in * * @dataProvider getCoordinates * * @param integer $x * @param integer $y * @param BoxInterface $box * @param Boolean $expected */ public function testShouldAssignXYCoordinates($x, $y, BoxInterface $box, $expected) { $coordinate = new Point($x, $y); $this->assertEquals($x, $coordinate->getX()); $this->assertEquals($y, $coordinate->getY()); $this->assertEquals($expected, $coordinate->in($box)); }
/** * @param Point $point * @return bool */ public function contains(Point $point) { $vertices = $this->points->getPoints(); // Check if the point is inside the polygon or on the boundary $intersections = 0; for ($i = 1; $i < $this->points->getPoints()->count(); $i++) { $vertex1 = $vertices->offsetGet($i - 1); $vertex2 = $vertices->offsetGet($i); // Check if point is on an horizontal polygon boundary if ($vertex1->getY() == $vertex2->getY() && $vertex1->getY() == $point->getY() && $point->getX() > min($vertex1->getX(), $vertex2->getX()) && $point->getX() < max($vertex1->getX(), $vertex2->getX())) { return true; } if ($point->getY() > min($vertex1->getY(), $vertex2->getY()) && $point->getY() <= max($vertex1->getY(), $vertex2->getY()) && $point->getX() <= max($vertex1->getX(), $vertex2->getX()) and $vertex1->getY() != $vertex2->getY()) { $xinters = ($point->getY() - $vertex1->getY()) * ($vertex2->getX() - $vertex1->getX()) / ($vertex2->getY() - $vertex1->getY()) + $vertex1->getX(); // Check if point is on the polygon boundary (other than horizontal) if ($xinters == $point->getX()) { return true; } if ($vertex1->getX() == $vertex2->getX() || $point->getX() <= $xinters) { $intersections++; } } } // If the number of edges we passed through is odd, then it's in the polygon. if ($intersections % 2 != 0) { return true; } else { return false; } }
/** * @covers Imagine\Image\Point::getX * @covers Imagine\Image\Point::getY * @covers Imagine\Image\Point::move * * @dataProvider getMoves * * @param integer $x * @param integer $y * @param integer $move * @param integer $x1 * @param integer $y1 */ public function testShouldMoveByGivenAmount($x, $y, $move, $x1, $y1) { $point = new Point($x, $y); $shift = $point->move($move); $this->assertEquals($x1, $shift->getX()); $this->assertEquals($y1, $shift->getY()); }
/** * @param Point $center * @param Distance $distance * * @return BoundingBox * @author Maximilian Ruta <*****@*****.**> */ public static function createFromCenterAndDistance(Point $center, Distance $distance) { $distanceInDegrees = $distance->getInGeographicDegrees() / 2; $sw = new Point($center->getLatitude() - $distanceInDegrees, $center->getLongitude() - $distanceInDegrees); $ne = new Point($center->getLatitude() + $distanceInDegrees, $center->getLongitude() + $distanceInDegrees); return new BoundingBox($sw, $ne); }
/** * test using an invalid y **/ public function testInvalidPointY() { $point = new Point($this->VALID_X, $this->INVALID_Y); // simply use the $INVALID_IP and an exception will be thrown $point->setX($this->VALID_X); $point->setY($this->INVALID_Y); }
/** * @param Point $place1 * @param Point $place2 * * @return Distance * @author Maximilian Ruta <*****@*****.**> */ public static function distance(Point $place1, Point $place2) { $theta = $place1->getLongitude() - $place2->getLongitude(); $dist = sin(deg2rad($place1->getLatitude())) * sin(deg2rad($place2->getLatitude())) + cos(deg2rad($place1->getLatitude())) * cos(deg2rad($place2->getLatitude())) * cos(deg2rad($theta)); $dist = acos($dist); $dist = rad2deg($dist); return new Distance($dist); }
public function testSetGetPoint() { $point = new Point(); $point->setLat("-23.529366"); $point->setLng("-47.467117"); $this->place->setPoint($point); $this->assertEquals("-23.529366,-47.467117", (string) $this->place->getPoint()); }
/** * @test */ public function testSubstract_SubstractPointIsGreaterThanMyPoint() { $substractPoint = 11; try { $point = new Point(10); $point->substract($substractPoint); } catch (Exception $ex) { return; } $this->fail('例外が発生しなかったよー'); }
/** * Constructor. * * @param float[][]|Point[] $positions * @param CoordinateResolutionSystem|BoundingBox $arg,... */ public function __construct(array $positions) { $this->coordinates = array_map(function ($point) { if (!$point instanceof Point) { $point = new Point($point); } return $point->getCoordinates(); }, $positions); if (func_num_args() > 1) { $this->setOptionalConstructorArgs(array_slice(func_get_args(), 1)); } }
/** * 添加一个楼盘到数据库 * @param $premises Array(name, type, description, project_id, state, area, structure, lng, lat, zoom) * @return bool 是否成功 */ public function add($premises) { $ret = false; $point = new Point(); $point_id = (int) $point->add($premises['lng'], $premises['lat'], $premises['zoom']); $mysql = new MysqlAccess(); if ($point_id > 0) { $sql = "insert into premises(`name`, `description`, `point_id`, `project_id`) " . "values('{$premises['name']}', '{$premises['description']}', {$point_id}, " . "{$premises['project_id']})"; $mysql->runSql($sql); $ret = true; } return $ret; }
/** * @param Point $point * @return float * * thanks to http://stackoverflow.com/questions/7672759/how-to-calculate-distance-from-lat-long-in-php */ public function getCartographicDistance(Point $point) { $earthRadius = 3958.75; $dLat = deg2rad($point->getLatitude() - $this->latitude); $dLng = deg2rad($point->getLongitude() - $this->longitude); $a = sin($dLat / 2) * sin($dLat / 2) + cos(deg2rad($this->latitude)) * cos(deg2rad($point->getLatitude())) * sin($dLng / 2) * sin($dLng / 2); $c = 2 * atan2(sqrt($a), sqrt(1 - $a)); $dist = $earthRadius * $c; // from miles to km $meterConversion = 1.609344; $geopointDistance = $dist * $meterConversion; return round($geopointDistance, 0); }
/** * 添加person */ public function add($person) { $ret = false; $point = new Point(); $now_id = (int) $point->add($person['now']['lng'], $person['now']['lat'], $person['now']['zoom']); $want_id = (int) $point->add($person['want']['lng'], $person['want']['lat'], $person['want']['zoom']); $mysql = new MysqlAccess(); if ($now_id > 0 && $want_id > 0) { $sql = "insert into person(`name`, `now`, `want`, `state`, `description`) values " . "('{$person['name']}', {$now_id}, {$want_id}, '{$person['state']}', '{$person['description']}')"; $mysql->runSql($sql); $ret = true; } return $ret; }
public function random_point_generation_disk($sizeX, $minDist, $maxDist) { $sizeY = $sizeX; // Initial point generation $this->add_point(new Point(round($sizeX / 2), round($sizeY / 2), '0')); $initialPoint = reset($this->vertices); for ($i = 65; $i < 91; $i++) { $letters[] = chr($i); } for ($i = 97; $i < 123; $i++) { $letters[] = chr($i); } $i = 0; // Point creation procedure $maxMissedPoints = 1000; $missedPointCount = 0; while ($missedPointCount < $maxMissedPoints) { $x = rand(0, $sizeX - 1); $y = rand(0, $sizeY - 1); $point = new Point($x, $y, $letters[$i]); $pointCreationFlag = false; if (Point::distance($point, $initialPoint) <= $sizeX / 2) { $pointCreationFlag = $this->add_point($point, $minDist, $maxDist); } if ($pointCreationFlag) { $missedPointCount = 0; $i++; } else { $missedPointCount++; } } }
/** * draw point on map * * @param Map $map */ public function draw(Map $map) { parent::draw($map); $point = $map->getPixelPointFromCoordinates($this->getLon(), $this->getLat()); $vertices = array($point['x'], $point['y'], $point['x'] - 10, $point['y'] - 20, $point['x'] + 10, $point['y'] - 20); imagefilledpolygon($map->getImage(), $vertices, 3, imagecolorallocate($map->getImage(), 200, 0, 0)); }
public function unserialize($data) { $data = unserialize($data); $this->color = $data['color']; parent::unserialize($data['baseData']); echo "\nInside " . __METHOD__ . ", {$this}\n\n"; }
/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate($id) { $model = $this->loadModel($id); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Net'])) { $model->attributes = $_POST['Net']; if ($model->save()) { $pointsAttached = $_POST['Net']['pointsattached']; $pointToNet = new PointToNet(); $pointToNet::model()->deleteAll('net_id = ' . $model->id); foreach ($pointsAttached as $attached) { $pointToNet->attributes = array('net_id' => $model->id, 'point_id' => $attached); $pointToNet->save(); $PointModel = Point::model()->findByPk($attached); $PointModel->CreateChannelsForWindows($model->screen_id, $attached); unset($PointModel); $pointToNet = new PointToNet(); } $model->CreateChannelsForWindows($model->screen_id, $model->id); $this->redirect(array('view', 'id' => $model->id)); } } $this->render('update', array('model' => $model)); }
static function aireTriangle($pointA, $pointB, $pointC) { $AB = Point::distance($pointA, $pointB); $BC = Point::distance($pointB, $pointC); $AC = Point::distance($pointC, $pointA); return sqrt(($AB + $BC + $AC) * (-$AB + $BC + $AC) * ($AB - $BC + $AC) * ($AB + $BC - $AC)) / 4; }
public function init() { parent::init(); // Create new field in your users table for store dashboard preference // Set table name, user ID field name, user preference field name $this->setTableParams('dashboard_page', 'user_id', 'title'); // set array of portlets $this->setPortlets(array(array('id' => 1, 'title' => 'Ultimos clientes', 'content' => Customer::model()->Top(4)), array('id' => 2, 'title' => 'Ultimas reservas', 'content' => Book::model()->Top(4)), array('id' => 3, 'title' => 'Puntos críticos', 'content' => Point::model()->Top(4)), array('id' => 4, 'title' => 'Ultimos boletines', 'content' => Mail::model()->Top(4)), array('id' => 5, 'title' => 'Informes', 'content' => Functions::lastReports()), array('id' => 6, 'title' => 'Ultimas facturas', 'content' => Invoice::model()->Top(4)))); //set content BEFORE dashboard $this->setContentBefore(); // uncomment the following to apply jQuery UI theme // from protected/components/assets/themes folder $this->applyTheme('ui-lightness'); // uncomment the following to change columns count //$this->setColumns(4); // uncomment the following to enable autosave $this->setAutosave(true); // uncomment the following to disable dashboard header $this->setShowHeaders(false); // uncomment the following to enable context menu and add needed items /* $this->menu = array( array('label' => 'Index', 'url' => array('index')), ); */ }
/** * Draw the label * * @param awDrawer $drawer * @param awPoint $p Label center * @param int $key Text position in the array of texts (default to zero) */ public function drawSpecial(awDrawer $drawer, awPoint $p, $key = 0, $theText) { $theTextAW = new awText($theText); if ($key % $this->interval !== 0) { return; } // Hide all labels if ($this->hide) { return; } // Key is hidden if (array_key_exists($key, $this->hideKey)) { return; } // Hide first label if ($key === 0 and $this->hideFirst) { return; } // Hide last label if ($key === count($this->texts) - 1 and $this->hideLast) { return; } $text = $theTextAW; if ($text !== NULL) { // Value must be hidden if (in_array($text->getText(), $this->hideValue)) { return; } $x = $p->x; $y = $p->y; // Get padding list($left, $right, $top, $bottom) = $text->getPadding(); $font = $text->getFont(); $width = $font->getTextWidth($text); $height = $font->getTextHeight($text); switch ($this->hAlign) { case awLabel::RIGHT: $x -= $width + $right; break; case awLabel::CENTER: $x -= ($width - $left + $right) / 2; break; case awLabel::LEFT: $x += $left; break; } switch ($this->vAlign) { case awLabel::TOP: $y -= $height + $bottom; break; case awLabel::MIDDLE: $y -= ($height - $top + $bottom) / 2; break; case awLabel::BOTTOM: $y += $top; break; } $drawer->string($theTextAW, $this->move->move($x, $y)); } }
/** * @return string geohash * @param Point $point * @author algorithm based on code by Alexander Songe <*****@*****.**> * @see https://github.com/asonge/php-geohash/issues/1 */ private function encodePoint($point, $precision = NULL) { if ($precision === NULL) { $lap = strlen($point->y()) - strpos($point->y(), "."); $lop = strlen($point->x()) - strpos($point->x(), "."); $precision = pow(10, -max($lap - 1, $lop - 1, 0)) / 2; } $minlat = -90; $maxlat = 90; $minlon = -180; $maxlon = 180; $latE = 90; $lonE = 180; $i = 0; $error = 180; $hash = ''; while ($error >= $precision) { $chr = 0; for ($b = 4; $b >= 0; --$b) { if ((1 & $b) == (1 & $i)) { // even char, even bit OR odd char, odd bit...a lon $next = ($minlon + $maxlon) / 2; if ($point->x() > $next) { $chr |= pow(2, $b); $minlon = $next; } else { $maxlon = $next; } $lonE /= 2; } else { // odd char, even bit OR even char, odd bit...a lat $next = ($minlat + $maxlat) / 2; if ($point->y() > $next) { $chr |= pow(2, $b); $minlat = $next; } else { $maxlat = $next; } $latE /= 2; } } $hash .= $this->table[$chr]; $i++; $error = min($latE, $lonE); } return $hash; }
/** * Draw the label * * @param $driver * @param $p Label center * @param int $key Text position in the array of texts (default to zero) */ function draw($driver, $p, $key = 0) { if ($key % $this->interval !== 0) { return; } // Hide all labels if ($this->hide) { return; } // Key is hidden if (array_key_exists($key, $this->hideKey)) { return; } // Hide first label if ($key === 0 and $this->hideFirst) { return; } // Hide last label if ($key === count($this->texts) - 1 and $this->hideLast) { return; } $text = $this->getText($key); if ($text !== NULL) { // Value must be hidden if (in_array($text->getText(), $this->hideValue)) { return; } $x = $p->x; $y = $p->y; // Get padding list($left, $right, $top, $bottom) = $text->getPadding(); // $font = $text->getFont(); $width = $driver->getTextWidth($text); $height = $driver->getTextHeight($text); switch ($this->hAlign) { case LABEL_RIGHT: $x -= $width + $right; break; case LABEL_CENTER: $x -= ($width - $left + $right) / 2; break; case LABEL_LEFT: $x += $left; break; } switch ($this->vAlign) { case LABEL_TOP: $y -= $height + $bottom; break; case LABEL_MIDDLE: $y -= ($height - $top + $bottom) / 2; break; case LABEL_BOTTOM: $y += $top; break; } $driver->string($text, $this->move->move($x, $y)); } }
public static function from_array($points, $srid = null, $with_z = false, $with_m = false) { $mp = new self($srid, $with_z, $with_m); foreach ($points as $point) { $mp->geometries[] = Point::from_array($point, $srid, $with_z, $with_m); } return $mp; }
public static function fromString($wktArgument) { $pairs = explode(',', trim($wktArgument)); $points = array_map(function ($pair) { return Point::fromPair($pair); }, $pairs); return new static($points); }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return Point the loaded model * @throws CHttpException */ public function loadModel($id) { $model = Point::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
/** * @param string $wkt * @return LatLng|NULL */ public static function fromWKT($wkt) { $point = Point::fromWKT($wkt); if ($point === NULL) { return NULL; } return new LatLng($point->y, $point->x); }
public static function from_array($points, $srid = null, $with_z = false, $with_m = false) { $line = new self($srid, $with_z, $with_m); foreach ($points as $point) { $line->points[] = Point::from_array($point, $srid, $with_z, $with_m); } return $line; }
public function testPopulateWithPlace() { $point = new Point(); $point->setLat('-23.59243454'); $point->setLng('-46.68677054'); $city = new City(); $city->setCountry('BR'); $city->setState('SP'); $city->setName('São Paulo'); $category = new Category(); $category->setId('123'); $category->setName('Empresas de Internet'); $address = new Address(); $address->setStreet("Rua Funchal"); $address->setNumber(129); $address->setComplement('6o andar'); $address->setCity($city); $place = new Place(); $place->setId("M25GJ288"); $place->setName("Apontador.com - São Paulo"); $place->setDescription("Líder em geolocalização no Brasil e uma das 250 maiores empresas de internet do mundo, segundo o AlwaysOn, o Apontador (www.apontador.com) desenvolve e oferece serviços e ferramentas de busca e localização para facilitar o dia a dia dos usuários, além de mostrar a opinião do público para os locais cadastrados em seus sites. Com mais de 10 milhões de visitantes mensais, a empresa inclui o site líder em busca local Apontador (www.apontador.com.br) e o de mapas e rotas MapLink (www.maplink.com.br)."); $place->setIconUrl("http://localphoto.s3.amazonaws.com/C40372534F143O1437_9896391605729015_l.jpg"); $place->setPoint($point); $place->setCategory($category); $place->setAddress($address); $this->og->populate($place); $rootUrl = \ROOT_URL; $testMeta = <<<META \t<meta property="og:title" content="Apontador.com - São Paulo"/> \t<meta property="og:description" content="Líder em geolocalização no Brasil e uma das 250 maiores empresas de internet do mundo, segundo o AlwaysOn, o Apontador (www.apontador.com) desenvolve e oferece serviços e ferramentas de busca e localização para facilitar o dia a dia dos usuários, além de mostrar a opinião do público para os locais cadastrados em seus sites. Com mais de 10 milhões de visitantes mensais, a empresa inclui o site líder em busca local Apontador (www.apontador.com.br) e o de mapas e rotas MapLink (www.maplink.com.br)."/> \t<meta property="og:image" content="http://maplink.com.br/widget?v=4.1&lat=-23.59243454&lng=-46.68677054"/> \t<meta property="og:url" content="{$rootUrl}sp/s-o-paulo/empresas-de-internet/apontador-com-s-o-paulo/M25GJ288.html"/> \t<meta property="og:street-address" content="Rua Funchal, 129"/> \t<meta property="og:locality" content="São Paulo"/> \t<meta property="og:region" content="SP"/> \t<meta property="og:country-name" content="Brasil"/> \t<meta property="og:latitude" content="-23.59243454"/> \t<meta property="og:longitude" content="-46.68677054"/> \t<meta property="og:type" content="company"/> META; $this->assertEquals($testMeta, $this->og->getMeta()); $testArray = array('title' => 'Apontador.com - São Paulo', 'description' => 'Líder em geolocalização no Brasil e uma das 250 maiores empresas de internet do mundo, segundo o AlwaysOn, o Apontador (www.apontador.com) desenvolve e oferece serviços e ferramentas de busca e localização para facilitar o dia a dia dos usuários, além de mostrar a opinião do público para os locais cadastrados em seus sites. Com mais de 10 milhões de visitantes mensais, a empresa inclui o site líder em busca local Apontador (www.apontador.com.br) e o de mapas e rotas MapLink (www.maplink.com.br).', 'image' => 'http://maplink.apontador.com.br/widget?v=4.1&lat=-23.59243454&lng=-46.68677054', 'url' => ROOT_URL . 'sp/s-o-paulo/empresas-de-internet/apontador-com-s-o-paulo/M25GJ288.html', 'street-address' => 'Rua Funchal, 129', 'locality' => 'São Paulo', 'region' => 'SP', 'country-name' => 'Brasil', 'latitude' => '-23.59243454', 'longitude' => '-46.68677054', 'type' => 'company'); $this->assertEquals($testArray, $this->og->getArray()); }