addPoint() public method

public addPoint ( Coordinate $point )
$point Coordinate
Exemplo n.º 1
0
 /**
  * Simplifies the given polyline
  *
  * 1. calculate the bearing angle between the first two points p1 and p2: b1
  * 2. calculate the bearing angle between the next two points p2 and p3: b2
  * 3. calculate the difference between b1 and b2: deltaB; if deltaB is
  *    smaller than the threshold angle, remove the middle point p2
  * 4. start again at (1.) as long as the polyline contains more points
  *
  * @param Polyline $polyline
  *
  * @return Polyline
  */
 public function simplify(Polyline $polyline)
 {
     $counterPoints = $polyline->getNumberOfPoints();
     if ($counterPoints < 3) {
         return clone $polyline;
     }
     $result = new Polyline();
     $bearingCalc = new BearingEllipsoidal();
     $points = $polyline->getPoints();
     $index = 0;
     // add the first point to the resulting polyline
     $result->addPoint($points[$index]);
     do {
         $index++;
         // preserve the last point of the original polyline
         if ($index === $counterPoints - 1) {
             $result->addPoint($points[$index]);
             break;
         }
         $bearing1 = $bearingCalc->calculateBearing($points[$index - 1], $points[$index]);
         $bearing2 = $bearingCalc->calculateBearing($points[$index], $points[$index + 1]);
         $bearingDifference = min(fmod($bearing1 - $bearing2 + 360, 360), fmod($bearing2 - $bearing1 + 360, 360));
         if ($bearingDifference > $this->bearingAngle) {
             $result->addPoint($points[$index]);
         }
     } while ($index < $counterPoints);
     return $result;
 }
Exemplo n.º 2
0
 /**
  * @covers Location\Formatter\DecimalDegrees::format
  */
 public function testFormatDefault()
 {
     $polyline = new Polyline();
     $polyline->addPoint(new Coordinate(52.5, 13.5));
     $polyline->addPoint(new Coordinate(62.5, 14.5));
     $json = '{ "type" : "LineString" , "coordinates" : [ [ 13.5, 52.5 ], [ 14.5, 62.5 ] ] }';
     $this->assertJsonStringEqualsJsonString($json, $this->formatter->format($polyline));
 }
Exemplo n.º 3
0
 public function setUp()
 {
     $this->polyline = new Polyline();
     $this->polyline->addPoint(new Coordinate(52.5, 13.5));
     $this->polyline->addPoint(new Coordinate(64.09999999999999, -21.9));
     $this->polyline->addPoint(new Coordinate(40.7, -74.0));
     $this->polyline->addPoint(new Coordinate(33.9, -118.4));
 }
Exemplo n.º 4
0
 public function testSimplifyTwoPointsImpossible()
 {
     $polyline = new Polyline();
     $polyline->addPoint(new Coordinate(10.0, 10.0));
     $polyline->addPoint(new Coordinate(20.0, 20.0));
     $processor = new SimplifyBearing(10);
     $simplified = $processor->simplify($polyline);
     $this->assertEquals($polyline, $simplified);
 }
Exemplo n.º 5
0
 public function testGetReverseWorksAsExpected()
 {
     $reversed = $this->polyline->getReverse();
     $expected = new Polyline();
     $expected->addPoint(new Coordinate(33.9, -118.4));
     $expected->addPoint(new Coordinate(40.7, -74.0));
     $expected->addPoint(new Coordinate(64.09999999999999, -21.9));
     $expected->addPoint(new Coordinate(52.5, 13.5));
     $this->assertEquals($expected, $reversed);
 }
 public function testSimplifyThreePointsImpossible()
 {
     $polyline = new Polyline();
     $polyline->addPoint(new Coordinate(10.0, 10.0));
     $polyline->addPoint(new Coordinate(20.0, 20.0));
     $polyline->addPoint(new Coordinate(30.0, 10.0));
     $processor = new SimplifyDouglasPeucker(1000);
     $simplified = $processor->simplify($polyline);
     $this->assertEquals($polyline, $simplified);
 }
Exemplo n.º 7
0
 /**
  * @param float $tolerance The maximum allowed deviation
  *
  * @return Polyline
  */
 public function simplify($tolerance)
 {
     $simplifiedLine = $this->douglasPeucker($this->polyline->getPoints(), $tolerance);
     $resultPolyline = new Polyline();
     foreach ($simplifiedLine as $point) {
         $resultPolyline->addPoint($point);
     }
     return $resultPolyline;
 }
Exemplo n.º 8
0
 /**
  * calculates trail distance using phpgeo composer package.
  **/
 public static function calculateTrailDistance()
 {
     $pdo = connectToEncryptedMySQL("/var/www/trailquail/encrypted-mysql/trailquail.ini");
     $trails = Trail::getAllTrails($pdo);
     $testNum = 0;
     foreach ($trails as $trail) {
         $testNum++;
         $trailRelationships = TrailRelationship::getTrailRelationshipByTrailId($pdo, $trail->getTrailId());
         $track = new Polyline();
         foreach ($trailRelationships as $trailRelationship) {
             $segment = Segment::getSegmentBySegmentId($pdo, $trailRelationship->getSegmentId());
             $track->addPoint(new Coordinate($segment->getSegmentStart()->getY(), $segment->getSegmentStart()->getX()));
             $track->addPoint(new Coordinate($segment->getSegmentStop()->getY(), $segment->getSegmentStop()->getX()));
         }
         $trailDistanceM = $track->getLength(new Vincenty());
         $trailDistanceMi = $trailDistanceM / 1609.344;
         $trailDistance = $trailDistanceMi;
         $trail->setTrailDistance($trailDistance);
         $trail->update($pdo);
     }
 }
Exemplo n.º 9
0
 public function testIfPolygonContainsGeometryWithPolylineOutsideWorksAsExpected()
 {
     $polygon = new Polygon();
     $polygon->addPoint(new Coordinate(52.221651719883084, 13.661613101139665));
     $polygon->addPoint(new Coordinate(52.21571624279022, 13.662988655269146));
     $polygon->addPoint(new Coordinate(52.21192284487188, 13.662990247830749));
     $polygon->addPoint(new Coordinate(52.20800279639661, 13.664533020928502));
     $polygon->addPoint(new Coordinate(52.20346977934241, 13.664621533825994));
     $polygon->addPoint(new Coordinate(52.19989615492523, 13.665583860129118));
     $polygon->addPoint(new Coordinate(52.19917740672827, 13.665664242580533));
     $polygon->addPoint(new Coordinate(52.197426510974765, 13.664221465587616));
     $polygon->addPoint(new Coordinate(52.19646820798516, 13.674150248989463));
     $polygon->addPoint(new Coordinate(52.20004786737263, 13.674412602558732));
     $polygon->addPoint(new Coordinate(52.20350875519216, 13.676183195784688));
     $polygon->addPoint(new Coordinate(52.206863863393664, 13.678688379004598));
     $polygon->addPoint(new Coordinate(52.21345723606646, 13.67043505422771));
     $polygon->addPoint(new Coordinate(52.21743017435074, 13.66775787435472));
     $polygon->addPoint(new Coordinate(52.22168365493417, 13.661622740328312));
     $outsidePolyline = new Polyline();
     $outsidePolyline->addPoint(new Coordinate(52.2123983502388, 13.677485324442387));
     $outsidePolyline->addPoint(new Coordinate(52.21518684178591, 13.683912232518196));
     $outsidePolyline->addPoint(new Coordinate(52.20702479593456, 13.685344364494085));
     $this->assertFalse($polygon->containsGeometry($outsidePolyline));
 }