コード例 #1
0
 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
 /**
  * Prepare SQL query for spatial operation ST_Distance (Input bbox or polygon)
  * 
  * @param RestoModel $model
  * @param string $filterName
  * @param array $requestParams
  * @param boolean $exclusion
  * @return type
  */
 private function prepareFilterQuery_distance($model, $filterName, $requestParams, $exclusion)
 {
     /*
      * WARNING ! Quick benchmark show that st_distance is 100x slower than st_intersects
      * TODO - check if st_distance performance can be improved.
      */
     $use_distance = false;
     /*
      * geo:lon and geo:lat have preseance to geo:name
      * (avoid double call to Gazetteer)
      */
     if (isset($requestParams['geo:lon']) && isset($requestParams['geo:lat'])) {
         $radius = RestoGeometryUtil::radiusInDegrees(isset($requestParams['geo:radius']) ? floatval($requestParams['geo:radius']) : 10000, $requestParams['geo:lat']);
         if ($use_distance) {
             return 'ST_distance(' . $model->getDbKey($model->searchFilters[$filterName]['key']) . ', ST_GeomFromText(\'' . pg_escape_string('POINT(' . $requestParams['geo:lon'] . ' ' . ($lat = $requestParams['geo:lat'] . ')')) . '\', 4326)) < ' . $radius;
         } else {
             $lonmin = $requestParams['geo:lon'] - $radius;
             $latmin = $requestParams['geo:lat'] - $radius;
             $lonmax = $requestParams['geo:lon'] + $radius;
             $latmax = $requestParams['geo:lat'] + $radius;
             return ($exclusion ? 'NOT ' : '') . 'ST_intersects(' . $model->getDbKey($model->searchFilters[$filterName]['key']) . ", ST_GeomFromText('" . pg_escape_string('POLYGON((' . $lonmin . ' ' . $latmin . ',' . $lonmin . ' ' . $latmax . ',' . $lonmax . ' ' . $latmax . ',' . $lonmax . ' ' . $latmin . ',' . $lonmin . ' ' . $latmin . '))') . "', 4326))";
         }
     }
 }