3 * Handles the visualization of GIS MULTILINESTRING objects.
5 * @package phpMyAdmin-GIS
7 class PMA_GIS_Multilinestring
extends PMA_GIS_Geometry
9 // Hold the singleton instance of the class
10 private static $_instance;
13 * A private constructor; prevents direct creation of object.
15 private function __construct()
20 * Returns the singleton.
22 * @return the singleton
24 public static function singleton()
26 if (!isset(self
::$_instance)) {
28 self
::$_instance = new $class;
31 return self
::$_instance;
37 * @param string $spatial spatial data of a row
39 * @return array containing the min, max values for x and y cordinates
41 public function scaleRow($spatial)
45 // Trim to remove leading 'MULTILINESTRING((' and trailing '))'
46 $multilinestirng = substr($spatial, 17, (strlen($spatial) - 19));
47 // Seperate each linestring
48 $linestirngs = explode("),(", $multilinestirng);
50 foreach ($linestirngs as $linestring) {
51 $min_max = $this->setMinMax($linestring, $min_max);
58 * Adds to the PNG image object, the data related to a row in the GIS dataset.
60 * @param string $spatial GIS MULTILINESTRING object
61 * @param string $label Label for the GIS MULTILINESTRING object
62 * @param string $line_color Color for the GIS MULTILINESTRING object
63 * @param array $scale_data Array containing data related to scaling
64 * @param image $image Image object
66 * @return the modified image object
68 public function prepareRowAsPng($spatial, $label, $line_color, $scale_data, $image)
71 $black = imagecolorallocate($image, 0, 0, 0);
72 $red = hexdec(substr($line_color, 1, 2));
73 $green = hexdec(substr($line_color, 3, 2));
74 $blue = hexdec(substr($line_color, 4, 2));
75 $color = imagecolorallocate($image, $red, $green, $blue);
77 // Trim to remove leading 'MULTILINESTRING((' and trailing '))'
78 $multilinestirng = substr($spatial, 17, (strlen($spatial) - 19));
79 // Seperate each linestring
80 $linestirngs = explode("),(", $multilinestirng);
83 foreach ($linestirngs as $linestring) {
84 $points_arr = $this->extractPoints($linestring, $scale_data);
85 foreach ($points_arr as $point) {
86 if (! isset($temp_point)) {
90 imageline($image, $temp_point[0], $temp_point[1], $point[0], $point[1], $color);
95 // print label if applicable
96 if (isset($label) && trim($label) != '' && $first_line) {
97 imagestring($image, 1, $points_arr[1][0], $points_arr[1][1], trim($label), $black);
105 * Adds to the TCPDF instance, the data related to a row in the GIS dataset.
107 * @param string $spatial GIS MULTILINESTRING object
108 * @param string $label Label for the GIS MULTILINESTRING object
109 * @param string $line_color Color for the GIS MULTILINESTRING object
110 * @param array $scale_data Array containing data related to scaling
111 * @param image $pdf TCPDF instance
113 * @return the modified TCPDF instance
115 public function prepareRowAsPdf($spatial, $label, $line_color, $scale_data, $pdf)
118 $red = hexdec(substr($line_color, 1, 2));
119 $green = hexdec(substr($line_color, 3, 2));
120 $blue = hexdec(substr($line_color, 4, 2));
121 $line = array('width' => 1.5, 'color' => array($red, $green, $blue));
123 // Trim to remove leading 'MULTILINESTRING((' and trailing '))'
124 $multilinestirng = substr($spatial, 17, (strlen($spatial) - 19));
125 // Seperate each linestring
126 $linestirngs = explode("),(", $multilinestirng);
129 foreach ($linestirngs as $linestring) {
130 $points_arr = $this->extractPoints($linestring, $scale_data);
131 foreach ($points_arr as $point) {
132 if (! isset($temp_point)) {
133 $temp_point = $point;
136 $pdf->Line($temp_point[0], $temp_point[1], $point[0], $point[1], $line);
137 $temp_point = $point;
142 if (isset($label) && trim($label) != '' && $first_line) {
143 $pdf->SetXY($points_arr[1][0], $points_arr[1][1]);
144 $pdf->SetFontSize(5);
145 $pdf->Cell(0, 0, trim($label));
153 * Prepares and returns the code related to a row in the GIS dataset as SVG.
155 * @param string $spatial GIS MULTILINESTRING object
156 * @param string $label Label for the GIS MULTILINESTRING object
157 * @param string $line_color Color for the GIS MULTILINESTRING object
158 * @param array $scale_data Array containing data related to scaling
160 * @return the code related to a row in the GIS dataset
162 public function prepareRowAsSvg($spatial, $label, $line_color, $scale_data)
164 $line_options = array(
166 'class' => 'linestring vector',
168 'stroke' => $line_color,
172 // Trim to remove leading 'MULTILINESTRING((' and trailing '))'
173 $multilinestirng = substr($spatial, 17, (strlen($spatial) - 19));
174 // Seperate each linestring
175 $linestirngs = explode("),(", $multilinestirng);
178 foreach ($linestirngs as $linestring) {
179 $points_arr = $this->extractPoints($linestring, $scale_data);
181 $row .= '<polyline points="';
182 foreach ($points_arr as $point) {
183 $row .= $point[0] . ',' . $point[1] . ' ';
186 $line_options['id'] = $label . rand();
187 foreach ($line_options as $option => $val) {
188 $row .= ' ' . $option . '="' . trim($val) . '"';
197 * Prepares JavaScript related to a row in the GIS dataset
198 * to visualize it with OpenLayers.
200 * @param string $spatial GIS MULTILINESTRING object
201 * @param int $srid Spatial reference ID
202 * @param string $label Label for the GIS MULTILINESTRING object
203 * @param string $line_color Color for the GIS MULTILINESTRING object
204 * @param array $scale_data Array containing data related to scaling
206 * @return JavaScript related to a row in the GIS dataset
208 public function prepareRowAsOl($spatial, $srid, $label, $line_color, $scale_data)
210 $style_options = array(
211 'strokeColor' => $line_color,
219 $row = $this->getBoundsForOl($srid, $scale_data);
221 // Trim to remove leading 'MULTILINESTRING((' and trailing '))'
222 $multilinestirng = substr($spatial, 17, (strlen($spatial) - 19));
223 // Seperate each linestring
224 $linestirngs = explode("),(", $multilinestirng);
226 $row .= 'vectorLayer.addFeatures(new OpenLayers.Feature.Vector('
227 . 'new OpenLayers.Geometry.MultiLineString(new Array(';
228 foreach ($linestirngs as $linestring) {
229 $points_arr = $this->extractPoints($linestring, null);
230 $row .= 'new OpenLayers.Geometry.LineString(new Array(';
231 foreach ($points_arr as $point) {
232 $row .= '(new OpenLayers.Geometry.Point(' . $point[0] . ', '
233 . $point[1] . ')).transform(new OpenLayers.Projection("EPSG:'
234 . $srid . '"), map.getProjectionObject()), ';
236 $row = substr($row, 0, strlen($row) - 2);
239 $row = substr($row, 0, strlen($row) - 2);
240 $row .= ')), null, ' . json_encode($style_options) . '));';
245 * Generate the WKT with the set of parameters passed by the GIS editor.
247 * @param array $gis_data GIS data
248 * @param int $index Index into the parameter object
249 * @param string $empty Value for empty points
251 * @return WKT with the set of parameters passed by the GIS editor
253 public function generateWkt($gis_data, $index, $empty = '')
255 $no_of_lines = isset($gis_data[$index]['MULTILINESTRING']['no_of_lines'])
256 ?
$gis_data[$index]['MULTILINESTRING']['no_of_lines'] : 1;
257 if ($no_of_lines < 1) {
260 $wkt = 'MULTILINESTRING(';
261 for ($i = 0; $i < $no_of_lines; $i++
) {
262 $no_of_points = isset($gis_data[$index]['MULTILINESTRING'][$i]['no_of_points'])
263 ?
$gis_data[$index]['MULTILINESTRING'][$i]['no_of_points'] : 2;
264 if ($no_of_points < 2) {
268 for ($j = 0; $j < $no_of_points; $j++
) {
269 $wkt .= ((isset($gis_data[$index]['MULTILINESTRING'][$i][$j]['x'])
270 && trim($gis_data[$index]['MULTILINESTRING'][$i][$j]['x']) != '')
271 ?
$gis_data[$index]['MULTILINESTRING'][$i][$j]['x'] : $empty)
272 . ' ' . ((isset($gis_data[$index]['MULTILINESTRING'][$i][$j]['y'])
273 && trim($gis_data[$index]['MULTILINESTRING'][$i][$j]['y']) != '')
274 ?
$gis_data[$index]['MULTILINESTRING'][$i][$j]['y'] : $empty) . ',';
276 $wkt = substr($wkt, 0, strlen($wkt) - 1);
279 $wkt = substr($wkt, 0, strlen($wkt) - 1);
285 * Generate the WKT for the data from ESRI shape files.
287 * @param array $row_data GIS data
289 * @return the WKT for the data from ESRI shape files
291 public function getShape($row_data)
293 $wkt = 'MULTILINESTRING(';
294 for ($i = 0; $i < $row_data['numparts']; $i++
) {
296 foreach ($row_data['parts'][$i]['points'] as $point) {
297 $wkt .= $point['x'] . ' ' . $point['y'] . ',';
299 $wkt = substr($wkt, 0, strlen($wkt) - 1);
302 $wkt = substr($wkt, 0, strlen($wkt) - 1);
308 * Generate parameters for the GIS data editor from the value of the GIS column.
310 * @param string $value of the GIS column
311 * @param index $index of the geometry
313 * @return parameters for the GIS data editor from the value of the GIS column
315 public function generateParams($value, $index = -1)
320 $data = PMA_GIS_Geometry
::generateParams($value);
321 $params['srid'] = $data['srid'];
324 $params[$index]['gis_type'] = 'MULTILINESTRING';
328 // Trim to remove leading 'MULTILINESTRING((' and trailing '))'
329 $multilinestirng = substr($wkt, 17, (strlen($wkt) - 19));
330 // Seperate each linestring
331 $linestirngs = explode("),(", $multilinestirng);
332 $params[$index]['MULTILINESTRING']['no_of_lines'] = count($linestirngs);
335 foreach ($linestirngs as $linestring) {
336 $points_arr = $this->extractPoints($linestring, null);
337 $no_of_points = count($points_arr);
338 $params[$index]['MULTILINESTRING'][$j]['no_of_points'] = $no_of_points;
339 for ($i = 0; $i < $no_of_points; $i++
) {
340 $params[$index]['MULTILINESTRING'][$j][$i]['x'] = $points_arr[$i][0];
341 $params[$index]['MULTILINESTRING'][$j][$i]['y'] = $points_arr[$i][1];