Пример #1
0
 public function testCreatePolygon()
 {
     $polygon = Location::fromGeoJson('{"type":"Polygon","coordinates":[[[3,2],[4,2],[4,3],[3,2]]]}');
     $this->assertInstanceOf('Ricklab\\Location\\Geometry\\Polygon', $polygon);
     $retVal = $polygon->toWkt();
     $this->assertEquals('POLYGON((3 2, 4 2, 4 3, 3 2))', $retVal);
 }
Пример #2
0
 public function testGeoJson()
 {
     $geojson = '{ "type": "MultiPoint",
 "coordinates": [ [100.0, 0.0], [101.0, 1.0] ]
 }';
     $multipoint = Location::fromGeoJson($geojson);
     $this->assertTrue($multipoint instanceof MultiPoint);
     $this->assertEquals([100.0, 0.0], $multipoint->getGeometries()[0]->toArray());
     $this->assertEquals([101.0, 1.0], $multipoint->getGeometries()[1]->toArray());
     $geojson = json_encode(json_decode($geojson));
     $this->assertEquals($geojson, json_encode($multipoint));
 }
Пример #3
0
   public function testFromGeoJson()
   {
       $json = '{ "type": "GeometryCollection",
   "geometries": [
     { "type": "Point",
       "coordinates": [100.0, 0.0]
       },
     { "type": "LineString",
       "coordinates": [ [101.0, 0.0], [102.0, 1.0] ]
       }
   ]
 }';
       $geomCollection = Location::fromGeoJson($json);
       $this->assertTrue($geomCollection instanceof GeometryCollection);
       $this->assertEquals([100.0, 0.0], $geomCollection->getGeometries()[0]->toArray());
       $this->assertEquals([[101.0, 0.0], [102.0, 1.0]], $geomCollection->getGeometries()[1]->toArray());
   }
Пример #4
0
 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));
 }
Пример #5
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));
 }