PMA\libraries\Util::createGISData PHP Méthode

createGISData() public static méthode

Generates GIS data based on the string passed.
public static createGISData ( string $gis_string ) : string
$gis_string string GIS string
Résultat string GIS data enclosed in 'GeomFromText' function
    public static function createGISData($gis_string)
    {
        $gis_string = trim($gis_string);
        $geom_types = '(POINT|MULTIPOINT|LINESTRING|MULTILINESTRING|' . 'POLYGON|MULTIPOLYGON|GEOMETRYCOLLECTION)';
        if (preg_match("/^'" . $geom_types . "\\(.*\\)',[0-9]*\$/i", $gis_string)) {
            return 'GeomFromText(' . $gis_string . ')';
        } elseif (preg_match("/^" . $geom_types . "\\(.*\\)\$/i", $gis_string)) {
            return "GeomFromText('" . $gis_string . "')";
        } else {
            return $gis_string;
        }
    }

Usage Example

 /**
  * Return the where clause for a geometrical column.
  *
  * @param mixed  $criteriaValues Search criteria input
  * @param string $names          Name of the column on which search is submitted
  * @param string $func_type      Search function/operator
  * @param string $types          Type of the field
  * @param bool   $geom_func      Whether geometry functions should be applied
  *
  * @return string part of where clause.
  */
 private function _getGeomWhereClause($criteriaValues, $names, $func_type, $types, $geom_func = null)
 {
     $geom_unary_functions = array('IsEmpty' => 1, 'IsSimple' => 1, 'IsRing' => 1, 'IsClosed' => 1);
     $where = '';
     // Get details about the geometry functions
     $geom_funcs = Util::getGISFunctions($types, true, false);
     // If the function takes multiple parameters
     if ($geom_funcs[$geom_func]['params'] > 1) {
         // create gis data from the criteria input
         $gis_data = Util::createGISData($criteriaValues);
         $where = $geom_func . '(' . Util::backquote($names) . ', ' . $gis_data . ')';
         return $where;
     }
     // New output type is the output type of the function being applied
     $type = $geom_funcs[$geom_func]['type'];
     $geom_function_applied = $geom_func . '(' . Util::backquote($names) . ')';
     // If the where clause is something like 'IsEmpty(`spatial_col_name`)'
     if (isset($geom_unary_functions[$geom_func]) && trim($criteriaValues) == '') {
         $where = $geom_function_applied;
     } elseif (in_array($type, Util::getGISDatatypes()) && !empty($criteriaValues)) {
         // create gis data from the criteria input
         $gis_data = Util::createGISData($criteriaValues);
         $where = $geom_function_applied . " " . $func_type . " " . $gis_data;
     } elseif (mb_strlen($criteriaValues) > 0) {
         $where = $geom_function_applied . " " . $func_type . " '" . $criteriaValues . "'";
     }
     return $where;
 }
Util