PMA\libraries\Util::getGISFunctions PHP Method

getGISFunctions() public static method

Returns the names and details of the functions that can be applied on geometry data types.
public static getGISFunctions ( string $geom_type = null, boolean $binary = true, boolean $display = false ) : array
$geom_type string if provided the output is limited to the functions that are applicable to the provided geometry type.
$binary boolean if set to false functions that take two geometries as arguments will not be included.
$display boolean if set to true separators will be added to the output array.
return array names and details of the functions that can be applied on geometry data types.
    public static function getGISFunctions($geom_type = null, $binary = true, $display = false)
    {
        $funcs = array();
        if ($display) {
            $funcs[] = array('display' => ' ');
        }
        // Unary functions common to all geometry types
        $funcs['Dimension'] = array('params' => 1, 'type' => 'int');
        $funcs['Envelope'] = array('params' => 1, 'type' => 'Polygon');
        $funcs['GeometryType'] = array('params' => 1, 'type' => 'text');
        $funcs['SRID'] = array('params' => 1, 'type' => 'int');
        $funcs['IsEmpty'] = array('params' => 1, 'type' => 'int');
        $funcs['IsSimple'] = array('params' => 1, 'type' => 'int');
        $geom_type = trim(mb_strtolower($geom_type));
        if ($display && $geom_type != 'geometry' && $geom_type != 'multipoint') {
            $funcs[] = array('display' => '--------');
        }
        // Unary functions that are specific to each geometry type
        if ($geom_type == 'point') {
            $funcs['X'] = array('params' => 1, 'type' => 'float');
            $funcs['Y'] = array('params' => 1, 'type' => 'float');
        } elseif ($geom_type == 'multipoint') {
            // no functions here
        } elseif ($geom_type == 'linestring') {
            $funcs['EndPoint'] = array('params' => 1, 'type' => 'point');
            $funcs['GLength'] = array('params' => 1, 'type' => 'float');
            $funcs['NumPoints'] = array('params' => 1, 'type' => 'int');
            $funcs['StartPoint'] = array('params' => 1, 'type' => 'point');
            $funcs['IsRing'] = array('params' => 1, 'type' => 'int');
        } elseif ($geom_type == 'multilinestring') {
            $funcs['GLength'] = array('params' => 1, 'type' => 'float');
            $funcs['IsClosed'] = array('params' => 1, 'type' => 'int');
        } elseif ($geom_type == 'polygon') {
            $funcs['Area'] = array('params' => 1, 'type' => 'float');
            $funcs['ExteriorRing'] = array('params' => 1, 'type' => 'linestring');
            $funcs['NumInteriorRings'] = array('params' => 1, 'type' => 'int');
        } elseif ($geom_type == 'multipolygon') {
            $funcs['Area'] = array('params' => 1, 'type' => 'float');
            $funcs['Centroid'] = array('params' => 1, 'type' => 'point');
            // Not yet implemented in MySQL
            //$funcs['PointOnSurface'] = array('params' => 1, 'type' => 'point');
        } elseif ($geom_type == 'geometrycollection') {
            $funcs['NumGeometries'] = array('params' => 1, 'type' => 'int');
        }
        // If we are asked for binary functions as well
        if ($binary) {
            // section separator
            if ($display) {
                $funcs[] = array('display' => '--------');
            }
            if (PMA_MYSQL_INT_VERSION < 50601) {
                $funcs['Crosses'] = array('params' => 2, 'type' => 'int');
                $funcs['Contains'] = array('params' => 2, 'type' => 'int');
                $funcs['Disjoint'] = array('params' => 2, 'type' => 'int');
                $funcs['Equals'] = array('params' => 2, 'type' => 'int');
                $funcs['Intersects'] = array('params' => 2, 'type' => 'int');
                $funcs['Overlaps'] = array('params' => 2, 'type' => 'int');
                $funcs['Touches'] = array('params' => 2, 'type' => 'int');
                $funcs['Within'] = array('params' => 2, 'type' => 'int');
            } else {
                // If MySQl version is greater than or equal 5.6.1,
                // use the ST_ prefix.
                $funcs['ST_Crosses'] = array('params' => 2, 'type' => 'int');
                $funcs['ST_Contains'] = array('params' => 2, 'type' => 'int');
                $funcs['ST_Disjoint'] = array('params' => 2, 'type' => 'int');
                $funcs['ST_Equals'] = array('params' => 2, 'type' => 'int');
                $funcs['ST_Intersects'] = array('params' => 2, 'type' => 'int');
                $funcs['ST_Overlaps'] = array('params' => 2, 'type' => 'int');
                $funcs['ST_Touches'] = array('params' => 2, 'type' => 'int');
                $funcs['ST_Within'] = array('params' => 2, 'type' => 'int');
            }
            if ($display) {
                $funcs[] = array('display' => '--------');
            }
            // Minimum bounding rectangle functions
            $funcs['MBRContains'] = array('params' => 2, 'type' => 'int');
            $funcs['MBRDisjoint'] = array('params' => 2, 'type' => 'int');
            $funcs['MBREquals'] = array('params' => 2, 'type' => 'int');
            $funcs['MBRIntersects'] = array('params' => 2, 'type' => 'int');
            $funcs['MBROverlaps'] = array('params' => 2, 'type' => 'int');
            $funcs['MBRTouches'] = array('params' => 2, 'type' => 'int');
            $funcs['MBRWithin'] = array('params' => 2, 'type' => 'int');
        }
        return $funcs;
    }

Usage Example

コード例 #1
0
 /**
  * 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