Detect the output type of the functions being applied
This commit is contained in:
parent
47a8dcfc88
commit
e456f22149
@ -3039,84 +3039,92 @@ function PMA_getGISDatatypes($upper_case = false) {
|
||||
* geometry data typess.
|
||||
*/
|
||||
function PMA_getGISFunctions($geom_type = null, $binary = true, $display = false) {
|
||||
// Unary functions common to all geomety types
|
||||
|
||||
$funcs = array();
|
||||
if ($display) {
|
||||
$funcs[] = array('name' => ' ');
|
||||
$funcs[] = array('display' => ' ');
|
||||
}
|
||||
|
||||
$funcs[] = array('name' => 'Dimension', 'params' => 1, 'type' => 'int');
|
||||
//$funcs[] = array('name' => 'Envelope', 'params' => 1, 'type' => 'Polygon');
|
||||
$funcs[] = array('name' => 'GeometryType', 'params' => 1, 'type' => 'text');
|
||||
$funcs[] = array('name' => 'SRID', 'params' => 1, 'type' => 'int');
|
||||
$funcs[] = array('name' => 'IsEmpty', 'params' => 1, 'type' => 'int');
|
||||
$funcs[] = array('name' => 'IsSimple', 'params' => 1, 'type' => 'int');
|
||||
// Unary functions common to all geomety 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(strtolower($geom_type));
|
||||
if ($display && $geom_type != 'geometry' && $geom_type != 'multipoint') {
|
||||
$funcs[] = array('name' => '--------');
|
||||
$funcs[] = array('display' => '--------');
|
||||
}
|
||||
|
||||
// Unary functions that are specific to each geomety type
|
||||
if ($geom_type == 'point') {
|
||||
$funcs[] = array('name' => 'X', 'params' => 1, 'type' => 'float');
|
||||
$funcs[] = array('name' => 'Y', 'params' => 1, 'type' => 'float');
|
||||
$funcs['X'] = array('params' => 1, 'type' => 'float');
|
||||
$funcs['Y'] = array('params' => 1, 'type' => 'float');
|
||||
} elseif ($geom_type == 'multipoint') {
|
||||
// no fucntions here
|
||||
} elseif ($geom_type == 'linestring') {
|
||||
//$funcs[] = array('name' => 'EndPoint', 'params' => 1, 'type' => 'Point');
|
||||
$funcs[] = array('name' => 'GLength', 'params' => 1, 'type' => 'float');
|
||||
$funcs[] = array('name' => 'NumPoints', 'params' => 1, 'type' => 'int');
|
||||
//$funcs[] = array('name' => 'StartPoint', 'params' => 1, 'type' => 'Point');
|
||||
$funcs[] = array('name' => 'IsRing', 'params' => 1, 'type' => 'int');
|
||||
$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[] = array('name' => 'GLength', 'params' => 1, 'type' => 'float');
|
||||
$funcs[] = array('name' => 'IsClosed', 'params' => 1, 'type' => 'int');
|
||||
$funcs['GLength'] = array('params' => 1, 'type' => 'float');
|
||||
$funcs['IsClosed'] = array('params' => 1, 'type' => 'int');
|
||||
} elseif ($geom_type == 'polygon') {
|
||||
$funcs[] = array('name' => 'Area', 'params' => 1, 'type' => 'float');
|
||||
//$funcs[] = array('name' => 'ExteriorRing', 'params' => 1, 'type' => 'Linestring');
|
||||
$funcs[] = array('name' => 'NumInteriorRings', 'params' => 1, 'type' => 'int');
|
||||
$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[] = array('name' => 'Area', 'params' => 1, 'type' => 'float');
|
||||
//$funcs[] = array('name' => 'Centroid', 'params' => 1, 'type' => 'Point');
|
||||
$funcs['Area'] = array('params' => 1, 'type' => 'float');
|
||||
$funcs['Centroid'] = array('params' => 1, 'type' => 'point');
|
||||
// Not yet implemented in MySQL
|
||||
//$funcs[] = array('name' => 'PointOnSurface', 'params' => 1, 'type' => 'Point');
|
||||
//$funcs['PointOnSurface'] = array('params' => 1, 'type' => 'point');
|
||||
} elseif ($geom_type == 'geometrycollection') {
|
||||
$funcs[] = array('name' => 'NumGeometries', 'params' => 1, 'type' => 'int');
|
||||
$funcs['NumGeometries'] = array('params' => 1, 'type' => 'int');
|
||||
}
|
||||
|
||||
// If we are asked for binary functions as well
|
||||
if ($binary) {
|
||||
// section seperator
|
||||
if ($display) {
|
||||
$funcs[] = array('name' => '--------');
|
||||
$funcs[] = array('display' => '--------');
|
||||
}
|
||||
$binary = array(
|
||||
array('name' => 'Crosses', 'params' => 2, 'type' => 'int'),
|
||||
array('name' => 'Contains', 'params' => 2, 'type' => 'int'),
|
||||
array('name' => 'Disjoint', 'params' => 2, 'type' => 'int'),
|
||||
array('name' => 'Equals', 'params' => 2, 'type' => 'int'),
|
||||
array('name' => 'Intersects', 'params' => 2, 'type' => 'int'),
|
||||
array('name' => 'Overlaps', 'params' => 2, 'type' => 'int'),
|
||||
array('name' => 'Touches', 'params' => 2, 'type' => 'int'),
|
||||
array('name' => 'Within', 'params' => 2, 'type' => 'int'),
|
||||
);
|
||||
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 greaeter 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 MySQl version is greaeter than or equal 5.6.1, use the ST_ prefix.
|
||||
if (PMA_MYSQL_INT_VERSION >= 50601) {
|
||||
for ($i = 0; $i < count($binary); $i++) {
|
||||
$binary[$i]['name'] = 'ST_' . $binary[$i]['name'];
|
||||
}
|
||||
}
|
||||
$funcs = array_merge($funcs, $binary);
|
||||
|
||||
if ($display) {
|
||||
$funcs[] = array('name' => '--------');
|
||||
$funcs[] = array('display' => '--------');
|
||||
}
|
||||
$funcs[] = array('name' => 'MBRContains', 'params' => 2, 'type' => 'int');
|
||||
$funcs[] = array('name' => 'MBRDisjoint', 'params' => 2, 'type' => 'int');
|
||||
$funcs[] = array('name' => 'MBREquals', 'params' => 2, 'type' => 'int');
|
||||
$funcs[] = array('name' => 'MBRIntersects', 'params' => 2, 'type' => 'int');
|
||||
$funcs[] = array('name' => 'MBROverlaps', 'params' => 2, 'type' => 'int');
|
||||
$funcs[] = array('name' => 'MBRTouches', 'params' => 2, 'type' => 'int');
|
||||
$funcs[] = array('name' => 'MBRWithin', 'params' => 2, 'type' => 'int');
|
||||
// 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;
|
||||
}
|
||||
|
||||
@ -146,8 +146,8 @@ if (! isset($param) || $param[0] == '') {
|
||||
echo('<select name="geom_func['. $i .']">');
|
||||
// get the relevant list of functions
|
||||
$funcs = PMA_getGISFunctions($fields_type[$i], false, true);
|
||||
foreach ($funcs as $func) {
|
||||
$name = $func['name'];
|
||||
foreach ($funcs as $func_name => $func) {
|
||||
$name = isset($func['display']) ? $func['display'] : $func_name;
|
||||
echo('<option value="' . htmlspecialchars($name) . '">'
|
||||
. htmlspecialchars($name) . '</option>');
|
||||
}
|
||||
@ -402,9 +402,14 @@ else {
|
||||
$cnt_func = count($func);
|
||||
reset($func);
|
||||
while (list($i, $func_type) = each($func)) {
|
||||
// If geometry funciton is set apply it to the field name
|
||||
// If geometry function is set apply it to the field name
|
||||
if (isset($geom_func[$i]) && trim($geom_func[$i]) != '') {
|
||||
$backquoted_name = $geom_func[$i] . '(' . PMA_backquote($names[$i]) . ')';
|
||||
|
||||
// New output type is the output type of the function being applied
|
||||
$geom_funcs = PMA_getGISFunctions($types[$i], false, false);
|
||||
$types[$i] = $geom_funcs[$geom_func[$i]]['type'];
|
||||
|
||||
// If the intended where clause is something like 'IsEmpty(`spatial_col_name`)'
|
||||
if (isset($geom_unary_operators[$geom_func[$i]]) && trim($fields[$i]) == '') {
|
||||
$w[] = $backquoted_name;
|
||||
@ -419,6 +424,8 @@ else {
|
||||
$fields[$i] = '';
|
||||
$w[] = $backquoted_name . ' ' . $func_type;
|
||||
|
||||
} elseif (in_array($types[$i], $geom_types)) {
|
||||
$w[] = $backquoted_name . ' ' . $func_type . " GeomFromText('" . $fields[$i] . "')";
|
||||
} elseif (strncasecmp($types[$i], 'enum', 4) == 0) {
|
||||
if (!empty($fields[$i])) {
|
||||
if (! is_array($fields[$i])) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user