From 1f2ba4e9cc51c2bf2b1c1b96f78f29143e033e36 Mon Sep 17 00:00:00 2001 From: Madhura Jayaratne Date: Sun, 24 Jul 2011 22:17:03 +0530 Subject: [PATCH] Resolves problems with point and multipoint visualizations due to the assumption of empty values as zeros --- libraries/gis/pma_gis_geometry.php | 13 +++++++--- libraries/gis/pma_gis_multipoint.php | 38 ++++++++++++++++++---------- libraries/gis/pma_gis_point.php | 36 ++++++++++++++++---------- 3 files changed, 55 insertions(+), 32 deletions(-) diff --git a/libraries/gis/pma_gis_geometry.php b/libraries/gis/pma_gis_geometry.php index 787eaf3e23..075f77808b 100644 --- a/libraries/gis/pma_gis_geometry.php +++ b/libraries/gis/pma_gis_geometry.php @@ -142,11 +142,16 @@ abstract class PMA_GIS_Geometry $cordinates = explode(" ", $point); if ($scale_data != null) { - $x = ($cordinates[0] - $scale_data['x']) * $scale_data['scale']; - $y = $scale_data['height'] - ($cordinates[1] - $scale_data['y']) * $scale_data['scale']; + if (trim($cordinates[0]) != '' && trim($cordinates[1]) != '') { + $x = ($cordinates[0] - $scale_data['x']) * $scale_data['scale']; + $y = $scale_data['height'] - ($cordinates[1] - $scale_data['y']) * $scale_data['scale']; + } else { + $x = ''; + $y = ''; + } } else { - $x = $cordinates[0]; - $y = $cordinates[1]; + $x = trim($cordinates[0]); + $y = trim($cordinates[1]); } if (! $linear) { diff --git a/libraries/gis/pma_gis_multipoint.php b/libraries/gis/pma_gis_multipoint.php index bbec0f6f51..4c9b3aae49 100644 --- a/libraries/gis/pma_gis_multipoint.php +++ b/libraries/gis/pma_gis_multipoint.php @@ -70,7 +70,9 @@ class PMA_GIS_Multipoint extends PMA_GIS_Geometry foreach ($points_arr as $point) { // draw a small circle to mark the point - imagearc($image, $point[0], $point[1], 7, 7, 0, 360, $color); + if ($point[0] != '' && $point[1] != '') { + imagearc($image, $point[0], $point[1], 7, 7, 0, 360, $color); + } } return $image; } @@ -100,7 +102,9 @@ class PMA_GIS_Multipoint extends PMA_GIS_Geometry foreach ($points_arr as $point) { // draw a small circle to mark the point - $pdf->Circle($point[0], $point[1], 2, 0, 360, 'D', $line); + if ($point[0] != '' && $point[1] != '') { + $pdf->Circle($point[0], $point[1], 2, 0, 360, 'D', $line); + } } return $pdf; } @@ -131,12 +135,14 @@ class PMA_GIS_Multipoint extends PMA_GIS_Geometry $row = ''; foreach ($points_arr as $point) { - $row .= ' $val) { - $row .= ' ' . $option . '="' . trim($val) . '"'; + if ($point[0] != '' && $point[1] != '') { + $row .= ' $val) { + $row .= ' ' . $option . '="' . trim($val) . '"'; + } + $row .= '/>'; } - $row .= '/>'; } return $row; @@ -176,11 +182,15 @@ class PMA_GIS_Multipoint extends PMA_GIS_Geometry $row = 'new Array('; foreach ($points_arr as $point) { - $row .= '(new OpenLayers.Geometry.Point(' . $point[0] . ', ' . $point[1] - . ')).transform(new OpenLayers.Projection("EPSG:' . $srid - . '"), map.getProjectionObject()), '; + if ($point[0] != '' && $point[1] != '') { + $row .= '(new OpenLayers.Geometry.Point(' . $point[0] . ', ' . $point[1] + . ')).transform(new OpenLayers.Projection("EPSG:' . $srid + . '"), map.getProjectionObject()), '; + } + } + if (substr($row, strlen($row) - 2) == ', ') { + $row = substr($row, 0, strlen($row) - 2); } - $row = substr($row, 0, strlen($row) - 2); $row .= ')'; $result .= 'vectorLayer.addFeatures(new OpenLayers.Feature.Vector(' @@ -194,7 +204,7 @@ class PMA_GIS_Multipoint extends PMA_GIS_Geometry * * @param array $gis_data GIS data * @param int $index Index into the parameter object - * @param string $empty Value for empty points + * @param string $empty Multipoint does not adhere to this * * @return WKT with the set of parameters passed by the GIS editor */ @@ -209,10 +219,10 @@ class PMA_GIS_Multipoint extends PMA_GIS_Geometry for ($i = 0; $i < $no_of_points; $i++) { $wkt .= ((isset($gis_data[$index]['MULTIPOINT'][$i]['x']) && trim($gis_data[$index]['MULTIPOINT'][$i]['x']) != '') - ? $gis_data[$index]['MULTIPOINT'][$i]['x'] : $empty) + ? $gis_data[$index]['MULTIPOINT'][$i]['x'] : '') . ' ' . ((isset($gis_data[$index]['MULTIPOINT'][$i]['y']) && trim($gis_data[$index]['MULTIPOINT'][$i]['y']) != '') - ? $gis_data[$index]['MULTIPOINT'][$i]['y'] : $empty) . ','; + ? $gis_data[$index]['MULTIPOINT'][$i]['y'] : '') . ','; } $wkt = substr($wkt, 0, strlen($wkt) - 1); $wkt .= ')'; diff --git a/libraries/gis/pma_gis_point.php b/libraries/gis/pma_gis_point.php index 0b4bff15aa..bca3843c5e 100644 --- a/libraries/gis/pma_gis_point.php +++ b/libraries/gis/pma_gis_point.php @@ -69,7 +69,9 @@ class PMA_GIS_Point extends PMA_GIS_Geometry $points_arr = $this->extractPoints($point, $scale_data); // draw a small circle to mark the point - imagearc($image, $points_arr[0][0], $points_arr[0][1], 7, 7, 0, 360, $color); + if ($points_arr[0][0] != '' && $points_arr[0][1] != '') { + imagearc($image, $points_arr[0][0], $points_arr[0][1], 7, 7, 0, 360, $color); + } return $image; } @@ -97,7 +99,9 @@ class PMA_GIS_Point extends PMA_GIS_Geometry $points_arr = $this->extractPoints($point, $scale_data); // draw a small circle to mark the point - $pdf->Circle($points_arr[0][0], $points_arr[0][1], 2, 0, 360, 'D', $line); + if ($points_arr[0][0] != '' && $points_arr[0][1] != '') { + $pdf->Circle($points_arr[0][0], $points_arr[0][1], 2, 0, 360, 'D', $line); + } return $pdf; } @@ -126,11 +130,13 @@ class PMA_GIS_Point extends PMA_GIS_Geometry $point = substr($spatial, 6, (strlen($spatial) - 7)); $points_arr = $this->extractPoints($point, $scale_data); - $row = ' $val) { - $row .= ' ' . $option . '="' . trim($val) . '"'; + if ($points_arr[0][0] != '' && $points_arr[0][1] != '') { + $row = ' $val) { + $row .= ' ' . $option . '="' . trim($val) . '"'; + } + $row .= '/>'; } - $row .= '/>'; return $row; } @@ -167,11 +173,13 @@ class PMA_GIS_Point extends PMA_GIS_Geometry $point = substr($spatial, 6, (strlen($spatial) - 7)); $points_arr = $this->extractPoints($point, null); - $result .= 'vectorLayer.addFeatures(new OpenLayers.Feature.Vector((' - . 'new OpenLayers.Geometry.Point(' . $points_arr[0][0] . ', ' - . $points_arr[0][1] . ').transform(new OpenLayers.Projection("EPSG:' - . $srid . '"), map.getProjectionObject())), null, ' - . json_encode($style_options) . '));'; + if ($points_arr[0][0] != '' && $points_arr[0][1] != '') { + $result .= 'vectorLayer.addFeatures(new OpenLayers.Feature.Vector((' + . 'new OpenLayers.Geometry.Point(' . $points_arr[0][0] . ', ' + . $points_arr[0][1] . ').transform(new OpenLayers.Projection("EPSG:' + . $srid . '"), map.getProjectionObject())), null, ' + . json_encode($style_options) . '));'; + } return $result; } @@ -180,7 +188,7 @@ class PMA_GIS_Point extends PMA_GIS_Geometry * * @param array $gis_data GIS data * @param int $index Index into the parameter object - * @param string $empty Value for empty points + * @param string $empty Point deos not adhere to this parameter * * @return WKT with the set of parameters passed by the GIS editor */ @@ -188,9 +196,9 @@ class PMA_GIS_Point extends PMA_GIS_Geometry { return 'POINT(' . ((isset($gis_data[$index]['POINT']['x']) && trim($gis_data[$index]['POINT']['x']) != '') - ? $gis_data[$index]['POINT']['x'] : $empty) . ' ' + ? $gis_data[$index]['POINT']['x'] : '') . ' ' . ((isset($gis_data[$index]['POINT']['y']) && trim($gis_data[$index]['POINT']['y']) != '') - ? $gis_data[$index]['POINT']['y'] : $empty) . ')'; + ? $gis_data[$index]['POINT']['y'] : '') . ')'; } /**