public function test()
 {
     $this->initContext();
     $this->assertEquals(false, RestoGeometryUtil::isValidGeoJSONFeature(null));
     $this->assertEquals(false, RestoGeometryUtil::isValidGeoJSONFeature(array('type' => 'toto')));
     $this->assertEquals(false, RestoGeometryUtil::isValidGeoJSONFeature(array('type' => 'Feature', 'geometry' => 'toto')));
     $this->assertEquals(false, RestoGeometryUtil::isValidGeoJSONFeature(array('type' => 'Feature', 'geometry' => array())));
     $this->assertEquals(false, RestoGeometryUtil::isValidGeoJSONFeature(array('type' => 'Feature', 'geometry' => array(), 'properties' => 'toto')));
     $this->assertEquals(true, RestoGeometryUtil::isValidGeoJSONFeature(array('type' => 'Feature', 'geometry' => array(), 'properties' => array())));
     $this->assertEquals(null, RestoGeometryUtil::geoJSONGeometryToWKT(array('type' => 'toto', 'coordinates' => array())));
     $this->assertEquals('POINT()', RestoGeometryUtil::geoJSONGeometryToWKT(array('type' => 'POINT', 'coordinates' => array())));
     $this->assertEquals('MULTIPOINT()', RestoGeometryUtil::geoJSONGeometryToWKT(array('type' => 'MULTIPOINT', 'coordinates' => array())));
     $this->assertEquals('LINESTRING()', RestoGeometryUtil::geoJSONGeometryToWKT(array('type' => 'LINESTRING', 'coordinates' => array())));
     $this->assertEquals('MULTILINESTRING()', RestoGeometryUtil::geoJSONGeometryToWKT(array('type' => 'MULTILINESTRING', 'coordinates' => array())));
     $this->assertEquals('POLYGON()', RestoGeometryUtil::geoJSONGeometryToWKT(array('type' => 'POLYGON', 'coordinates' => array())));
     $this->assertEquals('MULTIPOLYGON()', RestoGeometryUtil::geoJSONGeometryToWKT(array('type' => 'MULTIPOLYGON', 'coordinates' => array())));
     $this->assertEquals(8.863358410694E-5, RestoGeometryUtil::radiusInDegrees(10, 10));
     $this->assertEquals(array(8.9831528424457E-5, 0.00017966305685804), RestoGeometryUtil::inverseMercator(array(10, 20)));
     $this->assertEquals(null, RestoGeometryUtil::inverseMercator(array(10)));
     $this->assertEquals(null, RestoGeometryUtil::inverseMercator('toto'));
     $this->assertEquals(null, RestoGeometryUtil::forwardMercator('toto'));
     $this->assertEquals(null, RestoGeometryUtil::forwardMercator(array(90, -90)));
     $this->assertEquals(null, RestoGeometryUtil::forwardMercator(array(90, 90)));
     $this->assertEquals(null, RestoGeometryUtil::bboxToMercator(null));
     $this->assertEquals('1113194.9077778,1118889.9747022,1113194.9077778,1118889.9747022', RestoGeometryUtil::bboxToMercator('10,10,10,10'));
 }
Пример #2
0
 /**
  * Transform EPSG:4326 BBOX to EPSG:3857 bbox
  * 
  * @param {String} $bbox : bbox in EPSG:4326 (i.e. lonmin,latmin,lonmax,latmax) 
  */
 public static function bboxToMercator($bbox)
 {
     if (!$bbox) {
         return null;
     }
     $coords = explode(',', $bbox);
     if (count($coords) !== 4) {
         return null;
     }
     /*
      * Lower left coordinate
      */
     $lowerLeft = RestoGeometryUtil::forwardMercator(array(floatval($coords[0]), floatval($coords[1])));
     if (!$lowerLeft) {
         return null;
     }
     /*
      * Upper right coordinate
      */
     $upperRight = RestoGeometryUtil::forwardMercator(array(floatval($coords[2]), floatval($coords[3])));
     if (!$upperRight) {
         return null;
     }
     return join(',', $lowerLeft) . ',' . join(',', $upperRight);
 }