示例#1
0
 public function testFractionAlongLine()
 {
     Location::$useSpatialExtension = false;
     $this->fractionAlongLine();
     Location::$useSpatialExtension = true;
     $this->fractionAlongLine();
 }
示例#2
0
 public function testInitialBearing()
 {
     Location::$useSpatialExtension = false;
     $this->assertEquals(98.50702, round($this->line->getInitialBearing(), 5));
     Location::$useSpatialExtension = true;
     $this->assertEquals(98.50702, round($this->line->getInitialBearing(), 5));
 }
 public function testFromWkt()
 {
     $wkt = 'GEOMETRYCOLLECTION(POINT(4 6),LINESTRING(4 6, 7 10))';
     $geomCollection = Location::fromWkt($wkt);
     $this->assertTrue($geomCollection instanceof GeometryCollection);
     $this->assertEquals([4, 6], $geomCollection->getGeometries()[0]->toArray());
     $this->assertEquals([[4, 6], [7, 10]], $geomCollection->getGeometries()[1]->toArray());
 }
示例#4
0
 public function testWkt()
 {
     $wktv1 = 'MULTIPOINT ((10 40), (40 30), (20 20), (30 10))';
     $wktv2 = 'MULTIPOINT(10 40, 40 30, 20 20, 30 10)';
     $mp1 = Location::fromWkt($wktv1);
     $mp2 = Location::fromWkt($wktv2);
     $this->assertTrue($mp1 instanceof MultiPoint);
     $this->assertTrue($mp2 instanceof MultiPoint);
     $this->assertEquals([10, 40], $mp1->getGeometries()[0]->toArray());
     $this->assertEquals([10, 40], $mp2->getGeometries()[0]->toArray());
     $this->assertEquals($wktv2, $mp2->toWkt());
 }
示例#5
0
 public function testFromWkt()
 {
     $multipolywkt = 'MULTIPOLYGON(((1.432 -1.543, 5 1, 5 5, 1 5, 1.432 -1.543),(2 2, 3 2, 3 3, 2 3, 2 2)),((3 3, 6 2, 6 4, 3 3)))';
     $multilinewkt = 'MULTILINESTRING((3 4, 10 50, 20 25),(-5 -8, -10 -8, -15 -4))';
     $pointwkt = 'POINT(4 5)';
     $multipoly = Location::fromWkt($multipolywkt);
     $multiline = Location::fromWkt($multilinewkt);
     $point = Location::fromWkt($pointwkt);
     $this->assertTrue($point instanceof Geometry\Point);
     $this->assertTrue($multipoly instanceof Geometry\MultiPolygon);
     $this->assertTrue($multiline instanceof Geometry\MultiLineString);
     $this->assertEquals([4, 5], $point->toArray());
     $this->assertEquals($multipolywkt, $multipoly->toWkt());
     $this->assertEquals($multilinewkt, $multiline->toWkt());
 }
 public function testFromGeoJson()
 {
     $initialjson = '{ "type": "FeatureCollection",
 "features": [
   { "type": "Feature",
 "geometry": {
   "type": "Polygon",
   "coordinates": [[
     [-10.0, -10.0], [10.0, -10.0], [10.0, 10.0], [-10.0, 10.0], [-10,-10]
     ]]
   },
   "properties": {
     "foo":"bar"
   }
 }
   ]
 }';
     /** @var FeatureCollection $featureCollection */
     $featureCollection = Location::fromGeoJson($initialjson);
     $this->assertTrue($featureCollection instanceof FeatureCollection);
     $this->assertEquals(json_encode(json_decode($initialjson)), json_encode($featureCollection));
 }
示例#7
0
 public function testGeoJson()
 {
     $initialjson = '{ "type": "Feature",
 "bbox": [-10.0, -10.0, 10.0, 10.0],
 "geometry": {
   "type": "Polygon",
   "coordinates": [[
     [-10.0, -10.0], [10.0, -10.0], [10.0, 10.0], [-10.0, 10.0], [-10,-10]
     ]]
   },
   "properties": {
     "foo":"bar"
   }
 }';
     /** @var Feature $feature */
     $feature = Location::fromGeoJson($initialjson);
     $feature->enableBBox();
     $this->assertTrue($feature instanceof Feature);
     $this->assertTrue($feature->getGeometry() instanceof Polygon);
     $this->assertEquals('bar', $feature['foo']);
     $this->assertEquals(json_encode(json_decode($initialjson)), json_encode($feature));
 }
示例#8
0
 /**
  * @param $radius
  * @param string $unit
  *
  * @return Polygon
  */
 public function getBBoxByRadius($radius, $unit = 'km')
 {
     return Location::getBBoxByRadius($this, $radius, $unit);
 }
示例#9
0
 public function getBBox()
 {
     return Location::getBBox($this);
 }
示例#10
0
 public function setUp()
 {
     Location::$useSpatialExtension = false;
     $this->polygon = new Polygon([new Point(2, 3), new Point(2, 4), new Point(3, 4)]);
 }
示例#11
0
 /**
  * (PHP 5 &gt;= 5.4.0)<br/>
  * Specify data which should be serialized to JSON
  * @link http://php.net/manual/en/jsonserializable.jsonserialize.php
  * @return mixed data which can be serialized by <b>json_encode</b>,
  * which is a value of any type other than a resource.
  */
 function jsonSerialize()
 {
     $array = [];
     if ($this->id !== null) {
         $array['id'] = $this->id;
     }
     $array['type'] = 'Feature';
     if ($this->bbox) {
         $array['bbox'] = Location::getBBoxArray($this->geometry);
     }
     if ($this->geometry instanceof GeometryInterface) {
         $array['geometry'] = $this->geometry->jsonSerialize();
     } else {
         $array['geometry'] = null;
     }
     $array['properties'] = $this->properties;
     return $array;
 }
示例#12
0
 /**
  * @param Point $point the centre of the bounding box
  * @param number $radius minimum radius from $point
  * @param string $unit unit of the radius (default is kilometres)
  *
  * @return Polygon the BBox
  */
 public static function getBBoxByRadius(Point $point, $radius, $unit = 'km')
 {
     $north = $point->getRelativePoint($radius, 0, $unit);
     $south = $point->getRelativePoint($radius, 180, $unit);
     $limits['n'] = $north->getLatitude();
     $limits['s'] = $south->getLatitude();
     $radDist = $radius / Location::getEllipsoid()->radius($unit);
     //   $minLat  = deg2rad( $limits['s'] );
     //   $maxLat  = deg2rad( $limits['n'] );
     $radLon = $point->longitudeToRad();
     //if ($minLat > deg2rad(-90) && $maxLat < deg2rad(90)) {
     $deltaLon = asin(sin($radDist) / cos($point->latitudeToRad()));
     $minLon = $radLon - $deltaLon;
     if ($minLon < deg2rad(-180)) {
         $minLon += 2 * pi();
     }
     $maxLon = $radLon + $deltaLon;
     if ($maxLon > deg2rad(180)) {
         $maxLon -= 2 * pi();
     }
     //}
     $limits['w'] = rad2deg($minLon);
     $limits['e'] = rad2deg($maxLon);
     $nw = new Point($limits['n'], $limits['w']);
     $ne = new Point($limits['n'], $limits['e']);
     $sw = new Point($limits['s'], $limits['w']);
     $se = new Point($limits['s'], $limits['e']);
     $polygon = new Polygon([[$nw, $ne, $se, $sw]]);
     return $polygon;
 }
示例#13
0
 /**
  * (PHP 5 &gt;= 5.4.0)<br/>
  * Specify data which should be serialized to JSON
  * @link http://php.net/manual/en/jsonserializable.jsonserialize.php
  * @return mixed data which can be serialized by <b>json_encode</b>,
  * which is a value of any type other than a resource.
  */
 function jsonSerialize()
 {
     $features = [];
     $points = [];
     foreach ($this->features as $feature) {
         $features[] = $feature->jsonSerialize();
         if ($this->bbox) {
             $points += $feature->getGeometry()->getPoints();
         }
     }
     $return = [];
     $return['type'] = 'FeatureCollection';
     if ($this->bbox) {
         $return['bbox'] = Location::getBBoxArray($points);
     }
     $return['features'] = $features;
     return $return;
 }