public function area($exterior_only = FALSE, $signed = FALSE) { if ($this->isEmpty()) { return 0; } if ($this->geos() && $exterior_only == FALSE) { return $this->geos()->area(); } $exterior_ring = $this->components[0]; $pts = $exterior_ring->getComponents(); $c = count($pts); if ((int) $c == '0') { return NULL; } $a = '0'; foreach ($pts as $k => $p) { $j = ($k + 1) % $c; $a = $a + $p->getX() * $pts[$j]->getY() - $p->getY() * $pts[$j]->getX(); } if ($signed) { $area = $a / 2; } else { $area = abs($a / 2); } if ($exterior_only == TRUE) { return $area; } foreach ($this->components as $delta => $component) { if ($delta != 0) { $inner_poly = new Polygon(array($component)); $area -= $inner_poly->area(); } } return $area; }
public function actionPolygons() { $model = new Sector(); $this->performAjaxValidation($model); foreach ($_POST['polygons'] as $sectorId => $coordinates) { $sector = Sector::model()->findByPk($sectorId); if ($sector) { foreach ($sector->polygons as $polygon) { $polygon->delete(); } } else { $sector = new Sector(); $sector->attributes = $_POST[get_class($sector)]; $sector->save(); } foreach ($coordinates as $i => $latLng) { $polygon = new Polygon(); $polygon->sector_id = $sector->id; $polygon->attributes = $latLng; $polygon->save(); } } if (!Yii::app()->request->isAjaxRequest) { $this->redirect('/regions/index/index'); } }
/** * Проверка, находится ли ровер в пределах полигона * * @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; } }
/** * Constructor. * * @param float[][][][]|Polygon[] $polygons * @param CoordinateResolutionSystem|BoundingBox $arg,... */ public function __construct(array $polygons) { $this->coordinates = array_map(function ($polygon) { if (!$polygon instanceof Polygon) { $polygon = new Polygon($polygon); } return $polygon->getCoordinates(); }, $polygons); if (func_num_args() > 1) { $this->setOptionalConstructorArgs(array_slice(func_get_args(), 1)); } }
public static function createPolyFromCoordinateString($rawCoordinateString) { $coordinateString = ltrim(trim($rawCoordinateString)); $coordinates = explode(' ', $coordinateString); $poly = new Polygon(); /** @var array $c */ foreach ($coordinates as $c) { $cartesian = explode(',', $c); $point = new Point($cartesian[0], $cartesian[1]); $poly->addVertex($point); } return $poly; }
public static function from_array($point_set_sets, $srid = null, $with_z = false, $with_m = false) { $mp = new self($srid, $with_z, $with_m); foreach ($point_set_sets as $point_set) { $mp->geometries[] = Polygon::from_array($point_set, $srid, $with_z, $with_m); } return $mp; }
/** * Expects a polygon that is "unwrapped", i.e. if the polygon should cross * the antimeridian, its longitude coordinates are appropriately extended * to a coordinate system stretching from -360° west to 360° east. * * @param Polygon $polygon * @return ViewBounds */ public static function fromPolygon(Polygon $polygon) { $points = $polygon->points(); // Initialise extremes with first point's coordinates $n = $points[0]->y(); $e = $points[0]->x(); $s = $points[0]->y(); $w = $points[0]->x(); // Extend the bounds correspondingly foreach ($points as $point) { $n = max($n, $point->y()); $e = max($e, $point->x()); $s = min($s, $point->y()); $w = min($w, $point->x()); } // Instantiate ViewBounds accordingly, then return return new ViewBounds(new LatLng($s, $w), new LatLng($n, $e)); }
/** * @AjaxCallable=TRUE * @AjaxMethod=POST * @AjaxAsync=TRUE */ function save_poi() { $this->load->library('geo/LatLng'); $this->load->library('geo/Point'); $this->load->library('geo/Polygon'); $this->load->model('POIModel'); $id = filter_input(INPUT_POST, 'id', FILTER_VALIDATE_INT); $name = filter_input(INPUT_POST, 'name', FILTER_SANITIZE_STRING); $label = filter_input(INPUT_POST, 'label', FILTER_SANITIZE_STRING); $cat = filter_input(INPUT_POST, 'cat', FILTER_SANITIZE_STRING); $sub = filter_input(INPUT_POST, 'sub', FILTER_SANITIZE_STRING); $sLatLng = filter_input(INPUT_POST, 'latLng', FILTER_VALIDATE_FLOAT, FILTER_REQUIRE_ARRAY); $sBoundary = filter_input(INPUT_POST, 'boundary', FILTER_VALIDATE_FLOAT, FILTER_REQUIRE_ARRAY); $countryId = filter_input(INPUT_POST, 'countryId', FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE); $nearbyId = filter_input(INPUT_POST, 'nearbyId', FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE); $features = filter_input(INPUT_POST, 'feature', FILTER_SANITIZE_STRING, FILTER_REQUIRE_ARRAY); $latLng = LatLng::deserialize($sLatLng); $boundary = Polygon::deserialize($sBoundary); if ($id !== false) { POIModel::update($id, $nearbyId, $countryId, $name, $label, $cat, $sub, $latLng, $boundary, $features); return $id; } else { return POIModel::add(1, $nearbyId, $countryId, $name, $label, $cat, $sub, $latLng, $boundary, $features); } }
public function addPolygon(Polygon $polygon) { $this->coordinates[] = $polygon->getCoordinates(); return $this; }
/** * @covers MultiMaps\Polygon::getPropertyValidValues */ public function testGetPropertyValidValues() { $this->assertNull(Polygon::getPropertyValidValues('poiuygtfcvbnmnbgvfd')); }
/** * @AjaxCallable=TRUE * @AjaxMethod=POST * @AjaxAsync=TRUE */ public function updatePoi() { $this->load->library('geo/*'); $this->load->model('POIModel'); $id = filter_input(INPUT_POST, 'id', FILTER_VALIDATE_INT); $name = filter_input(INPUT_POST, 'name', FILTER_SANITIZE_STRING); $label = filter_input(INPUT_POST, 'label', FILTER_SANITIZE_STRING); $url = filter_input(INPUT_POST, 'url', FILTER_SANITIZE_STRING); $nearId = filter_input(INPUT_POST, 'nearId', FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE); $countryId = filter_input(INPUT_POST, 'countryId', FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE); $cat = filter_input(INPUT_POST, 'cat', FILTER_SANITIZE_STRING); $sub = filter_input(INPUT_POST, 'sub', FILTER_SANITIZE_STRING); $latLngWKT = filter_input(INPUT_POST, 'latLng', FILTER_SANITIZE_STRING); $borderWKT = filter_input(INPUT_POST, 'border', FILTER_SANITIZE_STRING); $attrs = filter_input(INPUT_POST, 'attrs', FILTER_SANITIZE_STRING, FILTER_REQUIRE_ARRAY); $latLng = LatLng::fromWKT($latLngWKT); $border = Polygon::fromWKT($borderWKT); //POIModel::addNew(1, $nearId, $countryId, $name, $label, $cat, $sub, $latLng, $border, $attrs); POIModel::update($id, $url, $nearId, $countryId, 1, $name, $label, $cat, $sub, $latLng, $border, $attrs); return TRUE; }
function CreateTestAnnots($doc) { $ew = new ElementWriter(); $eb = new ElementBuilder(); $first_page = $doc->PageCreate(new Rect(0.0, 0.0, 600.0, 600.0)); $doc->PagePushBack($first_page); $ew->Begin($first_page, ElementWriter::e_overlay, false); // begin writing to this page $ew->End(); // save changes to the current page // // Test of a free text annotation. // $txtannot = FreeText::Create($doc->GetSDFDoc(), new Rect(10.0, 400.0, 160.0, 570.0)); $txtannot->SetContents("\n\nSome swift brown fox snatched a gray hare out of the air by freezing it with an angry glare." . "\n\nAha!\n\nAnd there was much rejoicing!"); $txtannot->SetBorderStyle(new BorderStyle(BorderStyle::e_solid, 1.0, 10.0, 20.0), true); $txtannot->SetQuaddingFormat(0); $first_page->AnnotPushBack($txtannot); $txtannot->RefreshAppearance(); $txtannot = FreeText::Create($doc->GetSDFDoc(), new Rect(100.0, 100.0, 350.0, 500.0)); $txtannot->SetContentRect(new Rect(200.0, 200.0, 350.0, 500.0)); $txtannot->SetContents("\n\nSome swift brown fox snatched a gray hare out of the air by freezing it with an angry glare." . "\n\nAha!\n\nAnd there was much rejoicing!"); $txtannot->SetCalloutLinePoints(new Point(200.0, 300.0), new Point(150.0, 290.0), new Point(110.0, 110.0)); $txtannot->SetBorderStyle(new BorderStyle(BorderStyle::e_solid, 1.0, 10.0, 20.0), true); $txtannot->SetEndingStyle(LineAnnot::e_ClosedArrow); $txtannot->SetColor(new ColorPt(0.0, 1.0, 0.0)); $txtannot->SetQuaddingFormat(1); $first_page->AnnotPushBack($txtannot); $txtannot->RefreshAppearance(); $txtannot = FreeText::Create($doc->GetSDFDoc(), new Rect(400.0, 10.0, 550.0, 400.0)); $txtannot->SetContents("\n\nSome swift brown fox snatched a gray hare out of the air by freezing it with an angry glare." . "\n\nAha!\n\nAnd there was much rejoicing!"); $txtannot->SetBorderStyle(new BorderStyle(BorderStyle::e_solid, 1.0, 10.0, 20.0), true); $txtannot->SetColor(new ColorPt(0.0, 0.0, 1.0)); $txtannot->SetOpacity(0.2); $txtannot->SetQuaddingFormat(2); $first_page->AnnotPushBack($txtannot); $txtannot->RefreshAppearance(); $page = $doc->PageCreate(new Rect(0.0, 0.0, 600.0, 600.0)); $doc->PagePushBack($page); $ew->Begin($page, ElementWriter::e_overlay, false); // begin writing to this page $eb->Reset(); // Reset the GState to default $ew->End(); // save changes to the current page //Create a Line annotation... $line = LineAnnot::Create($doc->GetSDFDoc(), new Rect(250.0, 250.0, 400.0, 400.0)); $line->SetStartPoint(new Point(350.0, 270.0)); $line->SetEndPoint(new Point(260.0, 370.0)); $line->SetStartStyle(LineAnnot::e_Square); $line->SetEndStyle(LineAnnot::e_Circle); $line->SetColor(new ColorPt(0.3, 0.5, 0.0), 3); $line->SetContents("Dashed Captioned"); $line->SetShowCaption(true); $line->SetCaptionPosition(LineAnnot::e_Top); $line->SetBorderStyle(new BorderStyle(BorderStyle::e_dashed, 2.0, 0.0, 0.0, array(2.0, 2.0))); $line->RefreshAppearance(); $page->AnnotPushBack($line); $line = LineAnnot::Create($doc->GetSDFDoc(), new Rect(347.0, 377.0, 600.0, 600.0)); $line->SetStartPoint(new Point(385.0, 410.0)); $line->SetEndPoint(new Point(540.0, 555.0)); $line->SetStartStyle(LineAnnot::e_Circle); $line->SetEndStyle(LineAnnot::e_OpenArrow); $line->SetColor(new ColorPt(1.0, 0.0, 0.0), 3); $line->SetInteriorColor(new ColorPt(0.0, 1.0, 0.0), 3); $line->SetContents("Inline Caption"); $line->SetShowCaption(true); $line->SetCaptionPosition(LineAnnot::e_Inline); $line->SetLeaderLineExtensionLength(-4.0); $line->SetLeaderLineLength(-12.0); $line->SetLeaderLineOffset(2.0); $line->RefreshAppearance(); $page->AnnotPushBack($line); $line = LineAnnot::Create($doc->GetSDFDoc(), new Rect(10.0, 400.0, 200.0, 600.0)); $line->SetStartPoint(new Point(25.0, 426.0)); $line->SetEndPoint(new Point(180.0, 555.0)); $line->SetStartStyle(LineAnnot::e_Circle); $line->SetEndStyle(LineAnnot::e_Square); $line->SetColor(new ColorPt(0.0, 0.0, 1.0), 3); $line->SetInteriorColor(new ColorPt(1.0, 0.0, 0.0), 3); $line->SetContents("Offset Caption"); $line->SetShowCaption(true); $line->SetCaptionPosition(LineAnnot::e_Top); $line->SetTextHOffset(-60); $line->SetTextVOffset(10); $line->RefreshAppearance(); $page->AnnotPushBack($line); $line = LineAnnot::Create($doc->GetSDFDoc(), new Rect(200.0, 10.0, 400.0, 70.0)); $line->SetStartPoint(new Point(220.0, 25.0)); $line->SetEndPoint(new Point(370.0, 60.0)); $line->SetStartStyle(LineAnnot::e_Butt); $line->SetEndStyle(LineAnnot::e_OpenArrow); $line->SetColor(new ColorPt(0.0, 0.0, 1.0), 3); $line->SetContents("Regular Caption"); $line->SetShowCaption(true); $line->SetCaptionPosition(LineAnnot::e_Top); $line->RefreshAppearance(); $page->AnnotPushBack($line); $line = LineAnnot::Create($doc->GetSDFDoc(), new Rect(200.0, 70.0, 400.0, 130.0)); $line->SetStartPoint(new Point(220.0, 111.0)); $line->SetEndPoint(new Point(370.0, 78.0)); $line->SetStartStyle(LineAnnot::e_Circle); $line->SetEndStyle(LineAnnot::e_Diamond); $line->SetContents("Circle to Diamond"); $line->SetColor(new ColorPt(0.0, 0.0, 1.0), 3); $line->SetInteriorColor(new ColorPt(0.0, 1.0, 0.0), 3); $line->SetShowCaption(true); $line->SetCaptionPosition(LineAnnot::e_Top); $line->RefreshAppearance(); $page->AnnotPushBack($line); $line = LineAnnot::Create($doc->GetSDFDoc(), new Rect(10.0, 100.0, 160.0, 200.0)); $line->SetStartPoint(new Point(15.0, 110.0)); $line->SetEndPoint(new Point(150.0, 190.0)); $line->SetStartStyle(LineAnnot::e_Slash); $line->SetEndStyle(LineAnnot::e_ClosedArrow); $line->SetContents("Slash to CArrow"); $line->SetColor(new ColorPt(1.0, 0.0, 0.0), 3); $line->SetInteriorColor(new ColorPt(0.0, 1.0, 1.0), 3); $line->SetShowCaption(true); $line->SetCaptionPosition(LineAnnot::e_Top); $line->RefreshAppearance(); $page->AnnotPushBack($line); $line = LineAnnot::Create($doc->GetSDFDoc(), new Rect(270.0, 270.0, 570.0, 433.0)); $line->SetStartPoint(new Point(300.0, 400.0)); $line->SetEndPoint(new Point(550.0, 300.0)); $line->SetStartStyle(LineAnnot::e_RClosedArrow); $line->SetEndStyle(LineAnnot::e_ROpenArrow); $line->SetContents("ROpen & RClosed arrows"); $line->SetColor(new ColorPt(0.0, 0.0, 1.0), 3); $line->SetInteriorColor(new ColorPt(0.0, 1.0, 0.0), 3); $line->SetShowCaption(true); $line->SetCaptionPosition(LineAnnot::e_Top); $line->RefreshAppearance(); $page->AnnotPushBack($line); $line = LineAnnot::Create($doc->GetSDFDoc(), new Rect(195.0, 395.0, 205.0, 505.0)); $line->SetStartPoint(new Point(200.0, 400.0)); $line->SetEndPoint(new Point(200.0, 500.0)); $line->RefreshAppearance(); $page->AnnotPushBack($line); $line = LineAnnot::Create($doc->GetSDFDoc(), new Rect(55.0, 299.0, 150.0, 301.0)); $line->SetStartPoint(new Point(55.0, 300.0)); $line->SetEndPoint(new Point(155.0, 300.0)); $line->SetStartStyle(LineAnnot::e_Circle); $line->SetEndStyle(LineAnnot::e_Circle); $line->SetContents("Caption that's longer than its line."); $line->SetColor(new ColorPt(1.0, 0.0, 1.0), 3); $line->SetInteriorColor(new ColorPt(0.0, 1.0, 0.0), 3); $line->SetShowCaption(true); $line->SetCaptionPosition(LineAnnot::e_Top); $line->RefreshAppearance(); $page->AnnotPushBack($line); $line = LineAnnot::Create($doc->GetSDFDoc(), new Rect(300.0, 200.0, 390.0, 234.0)); $line->SetStartPoint(new Point(310.0, 210.0)); $line->SetEndPoint(new Point(380.0, 220.0)); $line->SetColor(new ColorPt(0.0, 0.0, 0.0), 3); $line->RefreshAppearance(); $page->AnnotPushBack($line); $page3 = $doc->PageCreate(new Rect(0.0, 0.0, 600.0, 600.0)); $ew->Begin($page3); // begin writing to the page $ew->End(); // save changes to the current page $doc->PagePushBack($page3); $circle = Circle::Create($doc->GetSDFDoc(), new Rect(300.0, 300.0, 390.0, 350.0)); $circle->SetColor(new ColorPt(0.0, 0.0, 0.0), 3); $circle->RefreshAppearance(); $page3->AnnotPushBack($circle); $circle = Circle::Create($doc->GetSDFDoc(), new Rect(100.0, 100.0, 200.0, 200.0)); $circle->SetColor(new ColorPt(0.0, 1.0, 0.0), 3); $circle->SetInteriorColor(new ColorPt(0.0, 0.0, 1.0), 3); $circle->SetBorderStyle(new BorderStyle(BorderStyle::e_dashed, 3.0, 0.0, 0.0, array(2.0, 4.0))); $circle->SetPadding(2.0); $circle->RefreshAppearance(); $page3->AnnotPushBack($circle); $sq = Square::Create($doc->GetSDFDoc(), new Rect(10.0, 200.0, 80.0, 300.0)); $sq->SetColor(new ColorPt(0.0, 0.0, 0.0), 3); $sq->RefreshAppearance(); $page3->AnnotPushBack($sq); $sq = Square::Create($doc->GetSDFDoc(), new Rect(500.0, 200.0, 580.0, 300.0)); $sq->SetColor(new ColorPt(1.0, 0.0, 0.0), 3); $sq->SetInteriorColor(new ColorPt(0.0, 1.0, 1.0), 3); $sq->SetBorderStyle(new BorderStyle(BorderStyle::e_dashed, 6.0, 0.0, 0.0, array(4.0, 2.0))); $sq->SetPadding(4.0); $sq->RefreshAppearance(); $page3->AnnotPushBack($sq); $poly = Polygon::Create($doc->GetSDFDoc(), new Rect(5.0, 500.0, 125.0, 590.0)); $poly->SetColor(new ColorPt(1.0, 0.0, 0.0), 3); $poly->SetInteriorColor(new ColorPt(1.0, 1.0, 0.0), 3); $poly->SetVertex(0, new Point(12.0, 510.0)); $poly->SetVertex(1, new Point(100.0, 510.0)); $poly->SetVertex(2, new Point(100.0, 555.0)); $poly->SetVertex(3, new Point(35.0, 544.0)); $poly->SetBorderStyle(new BorderStyle(BorderStyle::e_solid, 4.0, 0.0, 0.0)); $poly->SetPadding(4.0); $poly->RefreshAppearance(); $page3->AnnotPushBack($poly); $poly = PolyLine::Create($doc->GetSDFDoc(), new Rect(400.0, 10.0, 500.0, 90.0)); $poly->SetColor(new ColorPt(1.0, 0.0, 0.0), 3); $poly->SetInteriorColor(new ColorPt(0.0, 1.0, 0.0), 3); $poly->SetVertex(0, new Point(405.0, 20.0)); $poly->SetVertex(1, new Point(440.0, 40.0)); $poly->SetVertex(2, new Point(410.0, 60.0)); $poly->SetVertex(3, new Point(470.0, 80.0)); $poly->SetBorderStyle(new BorderStyle(BorderStyle::e_solid, 2.0, 0.0, 0.0)); $poly->SetPadding(4.0); $poly->SetStartStyle(LineAnnot::e_RClosedArrow); $poly->SetEndStyle(LineAnnot::e_ClosedArrow); $poly->RefreshAppearance(); $page3->AnnotPushBack($poly); $lk = Link::Create($doc->GetSDFDoc(), new Rect(5.0, 5.0, 55.0, 24.0)); //$lk->SetColor( new ColorPt(0.0,1.0,0.0), 3.0 ); $lk->RefreshAppearance(); $page3->AnnotPushBack($lk); $page4 = $doc->PageCreate(new Rect(0.0, 0.0, 600.0, 600.0)); $ew->Begin($page4); // begin writing to the page $ew->End(); // save changes to the current page $doc->PagePushBack($page4); $ew->Begin($page4); $font = Font::Create($doc->GetSDFDoc(), Font::e_helvetica); $element = $eb->CreateTextBegin($font, 16.0); $element->SetPathFill(true); $ew->WriteElement($element); $element = $eb->CreateTextRun("Some random text on the page", $font, 16.0); $element->SetTextMatrix(1.0, 0.0, 0.0, 1.0, 100.0, 500.0); $ew->WriteElement($element); $ew->WriteElement($eb->CreateTextEnd()); $ew->End(); $hl = HighlightAnnot::Create($doc->GetSDFDoc(), new Rect(100.0, 490.0, 150.0, 515.0)); $hl->SetColor(new ColorPt(0.0, 1.0, 0.0), 3); $hl->RefreshAppearance(); $page4->AnnotPushBack($hl); $sq = Squiggly::Create($doc->GetSDFDoc(), new Rect(100.0, 450.0, 250.0, 600.0)); //$sq->SetColor( new ColorPt(1.0,0.0,0.0), 3 ); $sq->SetQuadPoint(0, new QuadPoint(new Point(122.0, 455.0), new Point(240.0, 545.0), new Point(230.0, 595.0), new Point(101.0, 500.0))); $sq->RefreshAppearance(); $page4->AnnotPushBack($sq); $cr = Caret::Create($doc->GetSDFDoc(), new Rect(100.0, 40.0, 129.0, 69.0)); $cr->SetColor(new ColorPt(0.0, 0.0, 1.0), 3); $cr->SetSymbol("P"); $cr->RefreshAppearance(); $page4->AnnotPushBack($cr); $page5 = $doc->PageCreate(new Rect(0.0, 0.0, 600.0, 600.0)); $ew->Begin($page5); // begin writing to the page $ew->End(); // save changes to the current page $doc->PagePushBack($page5); global $input_path; $fs = FileSpec::Create($doc->GetSDFDoc(), $input_path . "butterfly.png", false); $page6 = $doc->PageCreate(new Rect(0.0, 0.0, 600.0, 600.0)); $ew->Begin($page6); // begin writing to the page $ew->End(); // save changes to the current page $doc->PagePushBack($page6); for ($ipage = 0; $ipage < 2; ++$ipage) { for ($iann = 0; $iann < 100; $iann++) { if (!($iann > FileAttachment::e_Tag)) { $fa = FileAttachment::Create($doc->GetSDFDoc(), new Rect(50.0 + 50.0 * (double) $iann, 100.0, 70.0 + 50.0 * (double) $iann, 120.0), $fs, $iann); if ($ipage) { $fa->SetColor(new ColorPt(1.0, 1.0, 0.0)); } $fa->RefreshAppearance(); if ($ipage == 0) { $page5->AnnotPushBack($fa); } else { $page6->AnnotPushBack($fa); } } if ($iann > Text::e_Note) { break; } $txt = Text::Create($doc->GetSDFDoc(), new Rect(10.0 + (double) $iann * 50.0, 200.0, 30.0 + (double) $iann * 50.0, 220.0)); $txt->SetIcon($iann); $txt->SetContents($txt->GetIconName()); if ($ipage) { $txt->SetColor(new ColorPt(1.0, 1.0, 0.0)); } $txt->RefreshAppearance(); if ($ipage == 0) { $page5->AnnotPushBack($txt); } else { $page6->AnnotPushBack($txt); } } } $txt = Text::Create($doc->GetSDFDoc(), new Rect(10.0, 20.0, 30.0, 40.0)); $txt->SetIcon("UserIcon"); $txt->SetContents("User defined icon, unrecognized by appearance generator"); $txt->SetColor(new ColorPt(0.0, 1.0, 0.0)); $txt->RefreshAppearance(); $page6->AnnotPushBack($txt); $ink = Ink::Create($doc->GetSDFDoc(), new Rect(100.0, 400.0, 200.0, 550.0)); $ink->SetColor(new ColorPt(0.0, 0.0, 1.0)); $ink->SetPoint(1, 3, new Point(220.0, 505.0)); $ink->SetPoint(1, 0, new Point(100.0, 490.0)); $ink->SetPoint(0, 1, new Point(120.0, 410.0)); $ink->SetPoint(0, 0, new Point(100.0, 400.0)); $ink->SetPoint(1, 2, new Point(180.0, 490.0)); $ink->SetPoint(1, 1, new Point(140.0, 440.0)); $ink->SetBorderStyle(new BorderStyle(BorderStyle::e_solid, 3.0, 0.0, 0.0)); $ink->RefreshAppearance(); $page6->AnnotPushBack($ink); $page7 = $doc->PageCreate(new Rect(0.0, 0.0, 600.0, 600.0)); $ew->Begin($page7); // begin writing to the page $ew->End(); // save changes to the current page $doc->PagePushBack($page7); $snd = Sound::Create($doc->GetSDFDoc(), new Rect(100.0, 500.0, 120.0, 520.0)); $snd->SetColor(new ColorPt(1.0, 1.0, 0.0)); $snd->SetIcon(Sound::e_Speaker); $snd->RefreshAppearance(); $page7->AnnotPushBack($snd); $snd = Sound::Create($doc->GetSDFDoc(), new Rect(200.0, 500.0, 220.0, 520.0)); $snd->SetColor(new ColorPt(1.0, 1.0, 0.0)); $snd->SetIcon(Sound::e_Mic); $snd->RefreshAppearance(); $page7->AnnotPushBack($snd); $page8 = $doc->PageCreate(new Rect(0.0, 0.0, 600.0, 600.0)); $ew->Begin($page8); // begin writing to the page $ew->End(); // save changes to the current page $doc->PagePushBack($page8); for ($ipage = 0; $ipage < 2; ++$ipage) { $px = 5; $py = 520; for ($istamp = RubberStamp::e_Approved; $istamp <= RubberStamp::e_Draft; $istamp = $istamp + 1) { $st = RubberStamp::Create($doc->GetSDFDoc(), new Rect(1.0, 1.0, 100.0, 100.0)); $st->SetIcon($istamp); $st->SetContents($st->GetIconName()); $st->SetRect(new Rect((double) $px, (double) $py, (double) $px + 100.0, (double) $py + 25.0)); $py -= 100; if ($py < 0) { $py = 520; $px += 200; } if ($ipage == 0) { //$page7->AnnotPushBack( $st ); } else { $page8->AnnotPushBack($st); $st->RefreshAppearance(); } } } $st = RubberStamp::Create($doc->GetSDFDoc(), new Rect(400.0, 5.0, 550.0, 45.0)); $st->SetIcon("UserStamp"); $st->SetContents("User defined stamp"); $page8->AnnotPushBack($st); $st->RefreshAppearance(); }
public function __construct($width, $height) { parent::__construct($width, $height); }
public static function parsMoving($s) { $error = "Неверно заданы команды для ровера!<br>"; $s = strtoupper(trim($s)); $commands = str_split($s); // получаем массив команд foreach ($commands as $value) { if (Moving::checkMove($value)) { Moving::moveTo($value); if (Position::checkPos(Polygon::getSizeX(), Polygon::getSizeY(), Position::getPosX(), Position::getPosY()) == false) { echo "Ровер выехал за пределы полигона! (" . Position::getPosX() . " " . Position::getPosY() . " " . Orientation::getSide() . ")<br>"; break; } //echo "-Измененная позиция ровера: ". Position::getPosX() . " " . Position::getPosY() . " " . Orientation::getSide() ."<br>"; } else { echo $error; echo $value . "<br>"; break; } } echo "Измененная позиция ровера: " . Position::getPosX() . " " . Position::getPosY() . " " . Orientation::getSide() . "<br>"; }
public function __construct(Point $top_left, Point $bottom_right) { parent::__construct([$top_left, $bottom_right]); }
function polygon_finder_recursive(Graph $graph, $currentPolygon, $currentVertex, $lastVertex) { // Interdiction path table // Struct : array[ pointGuid1 ][ pointGuid2 ] static $pathTable = array(); $polygons = array(); $return = false; $vertices = $graph->vertices; $edges = $graph->edges; if (is_null($lastVertex) || !isset($pathTable[$lastVertex->guid][$currentVertex->guid])) { // The path loops = area found if (in_array($currentVertex, $currentPolygon)) { // Working backward to find the closure point, exclude non-area included vertices $polygon = new Polygon(); do { $newPoint = array_pop($currentPolygon); $polygon->addPoint($newPoint); } while ($currentVertex != $newPoint); $currentPolygon = $polygon; // If the polygon area doesn't include the central point if ($polygon->includes(reset($vertices)) !== 1) { // Update the interdiction table $j = count($currentPolygon) - 1; for ($k = 0; $k < count($currentPolygon); $k++) { //$pathTable[ $currentPolygon[ $j ]->guid ][ $currentPolygon[ $k ]->guid ] = true; $pathTable[$currentPolygon[$k]->guid][$currentPolygon[$j]->guid] = true; $j++; if ($j == count($currentPolygon)) { $j = 0; } } $return = $currentPolygon; } } else { $currentPolygon[] = $currentVertex; if (is_null($lastVertex)) { // First point : we search every line from the point foreach (array_keys($edges[$currentVertex->guid]) as $guid) { $polygon = polygon_finder_recursive($graph, $currentPolygon, $vertices[$guid], $currentVertex); if ($polygon !== false) { $polygonList[] = $polygon; } $return = $polygonList; } } else { // Existing line : we follow the first available path with the smallest angle $angleList = array(); foreach (array_keys($edges[$currentVertex->guid]) as $guid) { // Stop condition : already passed through here in this direction if ($lastVertex->guid != $guid && !isset($pathTable[$currentVertex->guid][$vertices[$guid]->guid])) { $angleList[$guid] = Point::anglePolar($lastVertex, $currentVertex, $vertices[$guid]); } } asort($angleList); list($guid, $angle) = each($angleList); if (!is_null($guid)) { $return = polygon_finder_recursive($graph, $currentPolygon, $vertices[$guid], $currentVertex); } } } } return $return; }
public static function parsMoving($s, $n) { $error = "Неверно заданы команды для ровера №" . $n . "!<br>"; $success = true; // По умолчанию надеемся, что ф-ция отбработает успешно $s = strtoupper(trim($s)); $commands = str_split($s); // получаем массив команд foreach ($commands as $value) { if (Moving::checkMove($value)) { Moving::moveTo($value); if (Position::checkPos(Polygon::getSizeX(), Polygon::getSizeY(), Position::getPosX(), Position::getPosY()) == false) { echo "Ровер " . $n . " выехал за пределы полигона! (" . Position::getPosX() . " " . Position::getPosY() . " " . Orientation::getSide() . ")<br>"; break; } //echo "-Измененная позиция ровера: ". Position::getPosX() . " " . Position::getPosY() . " " . Orientation::getSide() ."<br>"; } else { echo $error; //echo $value . "<br>"; $success = false; break; } } return $success; }
static function fromResponse(array $arr) { $polygon = Polygon::fromResponse($arr["polygon"]); $bbox = Bbox::fromResponse($arr["bbox"]); $sourceType = null; if (array_key_exists("url", $arr)) { $sourceType = "URL"; $source = $arr["url"]; } else { if (array_key_exists("base64", $arr)) { $sourceType = "BASE64"; $source = $arr["base64"]; } else { //throw new \Exception ("Invalid image response"); $source = ""; $sourceType = "BASE64"; } } return new Image($source, $sourceType, $polygon, $bbox, $arr["width"], $arr["height"]); }
public static function loadWithinBorder(Polygon $border, $types, $exceptId = 0) { $res = db()->select()->all('poi')->col('latLng', 'poi')->op(AS_TEXT)->alias('latLngWKT')->col('border', 'poi')->op(AS_TEXT)->alias('borderWKT')->col('name', 'poiNear')->alias('nearName')->col('name', 'poiCountry')->alias('countryName')->col('name', 'poiType')->alias('subName')->from('poi')->leftJoin('poi')->alias('poiNear')->on('id', 'nearId')->leftJoin('poi')->alias('poiCountry')->on('id', 'countryId')->leftJoin('poi_type')->alias('poiType')->on('id', 'sub')->where("ST_Within(GeomFromText(POINT(`poi`.`lng`, `poi`.`lat`)), GeomFromText({$border->toWKT()}))")->andCond('sub', 'poi', IN, $types)->andCond('id', 'poi', NE, $exceptId)->exec(); while ($o = $res->fetchObject()) { $pois[] = new POIModel($o); } return $pois; }
public function getProperty($name) { switch ($name) { case 'radiuses': return $this->radiuses; break; default: return parent::getProperty($name); break; } }
public static function area(Polygon $polygon) { $points = $polygon->points(); $r = 6378; $lam1 = 0; $lam2 = 0; $beta1 = 0; $beta2 = 0; $cosB1 = 0; $cosB2 = 0; $hav = 0; $sum = 0; $lat = []; $lng = []; for ($i = 0; $i < count($points); $i++) { array_push($lat, $points[$i]->y() * pi() / 180); array_push($lng, $points[$i]->x() * pi() / 180); } for ($j = 0; $j < count($lat); $j++) { $k = $j + 1; if ($j == 0) { $lam1 = $lng[$j]; $beta1 = $lat[$j]; $lam2 = $lng[$j + 1]; $beta2 = $lat[$j + 1]; $cosB1 = cos($beta1); $cosB2 = cos($beta2); } else { $k = ($j + 1) % count($lat); $lam1 = $lam2; $beta1 = $beta2; $lam2 = $lng[$k]; $beta2 = $lat[$k]; $cosB1 = $cosB2; $cosB2 = cos($beta2); } if ($lam1 != $lam2) { $hav = (1.0 - cos($beta2 - $beta1)) / 2.0 + $cosB1 * $cosB2 * ((1.0 - cos($lam2 - $lam1)) / 2.0); $a = 2 * asin(sqrt($hav)); $b = pi() / 2 - $beta2; $c = pi() / 2 - $beta1; $s = 0.5 * ($a + $b + $c); $t = tan($s / 2) * tan(($s - $a) / 2) * tan(($s - $b) / 2) * tan(($s - $c) / 2); $excess = abs(4 * atan(sqrt(abs($t)))); if ($lam2 < $lam1) { $excess = -$excess; } $sum += $excess; } } return abs($sum) * $r * $r; }
/** * Add polygon to map * @param string $value * @return boolean */ public function addElementPolygon($value) { $return = true; $stringspolygon = explode($GLOBALS['egMultiMaps_SeparatorItems'], $value); foreach ($stringspolygon as $polygonvalue) { if (trim($polygonvalue) == '') { continue; } $polygon = new Polygon(); if (!$polygon->parse($polygonvalue, $this->classname)) { $return = false; $this->errormessages = array_merge($this->errormessages, $polygon->getErrorMessages()); } if (!$polygon->isValid()) { continue; } $this->polygons[] = $polygon; $this->elementsBounds->extend($polygon->pos); } return $return; }