2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Handles actions related to GIS MULTILINESTRING objects
6 * @package PhpMyAdmin-GIS
9 namespace PMA\libraries\gis
;
14 * Handles actions related to GIS MULTILINESTRING objects
16 * @package PhpMyAdmin-GIS
18 class GISMultilinestring
extends GISGeometry
20 // Hold the singleton instance of the class
21 private static $_instance;
24 * A private constructor; prevents direct creation of object.
28 private function __construct()
33 * Returns the singleton.
35 * @return GISMultilinestring the singleton
38 public static function singleton()
40 if (!isset(self
::$_instance)) {
42 self
::$_instance = new $class;
45 return self
::$_instance;
51 * @param string $spatial spatial data of a row
53 * @return array an array containing the min, max values for x and y coordinates
56 public function scaleRow($spatial)
60 // Trim to remove leading 'MULTILINESTRING((' and trailing '))'
65 mb_strlen($spatial) - 19
67 // Separate each linestring
68 $linestirngs = explode("),(", $multilinestirng);
70 foreach ($linestirngs as $linestring) {
71 $min_max = $this->setMinMax($linestring, $min_max);
78 * Adds to the PNG image object, the data related to a row in the GIS dataset.
80 * @param string $spatial GIS MULTILINESTRING object
81 * @param string $label Label for the GIS MULTILINESTRING object
82 * @param string $line_color Color for the GIS MULTILINESTRING object
83 * @param array $scale_data Array containing data related to scaling
84 * @param object $image Image object
86 * @return object the modified image object
89 public function prepareRowAsPng(
97 $black = imagecolorallocate($image, 0, 0, 0);
98 $red = hexdec(mb_substr($line_color, 1, 2));
99 $green = hexdec(mb_substr($line_color, 3, 2));
100 $blue = hexdec(mb_substr($line_color, 4, 2));
101 $color = imagecolorallocate($image, $red, $green, $blue);
103 // Trim to remove leading 'MULTILINESTRING((' and trailing '))'
108 mb_strlen($spatial) - 19
110 // Separate each linestring
111 $linestirngs = explode("),(", $multilinestirng);
114 foreach ($linestirngs as $linestring) {
115 $points_arr = $this->extractPoints($linestring, $scale_data);
116 foreach ($points_arr as $point) {
117 if (!isset($temp_point)) {
118 $temp_point = $point;
129 $temp_point = $point;
133 // print label if applicable
134 if (isset($label) && trim($label) != '' && $first_line) {
151 * Adds to the TCPDF instance, the data related to a row in the GIS dataset.
153 * @param string $spatial GIS MULTILINESTRING object
154 * @param string $label Label for the GIS MULTILINESTRING object
155 * @param string $line_color Color for the GIS MULTILINESTRING object
156 * @param array $scale_data Array containing data related to scaling
157 * @param TCPDF $pdf TCPDF instance
159 * @return TCPDF the modified TCPDF instance
162 public function prepareRowAsPdf($spatial, $label, $line_color, $scale_data, $pdf)
165 $red = hexdec(mb_substr($line_color, 1, 2));
166 $green = hexdec(mb_substr($line_color, 3, 2));
167 $blue = hexdec(mb_substr($line_color, 4, 2));
168 $line = array('width' => 1.5, 'color' => array($red, $green, $blue));
170 // Trim to remove leading 'MULTILINESTRING((' and trailing '))'
175 mb_strlen($spatial) - 19
177 // Separate each linestring
178 $linestirngs = explode("),(", $multilinestirng);
181 foreach ($linestirngs as $linestring) {
182 $points_arr = $this->extractPoints($linestring, $scale_data);
183 foreach ($points_arr as $point) {
184 if (!isset($temp_point)) {
185 $temp_point = $point;
195 $temp_point = $point;
200 if (isset($label) && trim($label) != '' && $first_line) {
201 $pdf->SetXY($points_arr[1][0], $points_arr[1][1]);
202 $pdf->SetFontSize(5);
203 $pdf->Cell(0, 0, trim($label));
212 * Prepares and returns the code related to a row in the GIS dataset as SVG.
214 * @param string $spatial GIS MULTILINESTRING object
215 * @param string $label Label for the GIS MULTILINESTRING object
216 * @param string $line_color Color for the GIS MULTILINESTRING object
217 * @param array $scale_data Array containing data related to scaling
219 * @return string the code related to a row in the GIS dataset
222 public function prepareRowAsSvg($spatial, $label, $line_color, $scale_data)
224 $line_options = array(
226 'class' => 'linestring vector',
228 'stroke' => $line_color,
232 // Trim to remove leading 'MULTILINESTRING((' and trailing '))'
237 mb_strlen($spatial) - 19
239 // Separate each linestring
240 $linestirngs = explode("),(", $multilinestirng);
243 foreach ($linestirngs as $linestring) {
244 $points_arr = $this->extractPoints($linestring, $scale_data);
246 $row .= '<polyline points="';
247 foreach ($points_arr as $point) {
248 $row .= $point[0] . ',' . $point[1] . ' ';
251 $line_options['id'] = $label . rand();
252 foreach ($line_options as $option => $val) {
253 $row .= ' ' . $option . '="' . trim($val) . '"';
262 * Prepares JavaScript related to a row in the GIS dataset
263 * to visualize it with OpenLayers.
265 * @param string $spatial GIS MULTILINESTRING object
266 * @param int $srid Spatial reference ID
267 * @param string $label Label for the GIS MULTILINESTRING object
268 * @param string $line_color Color for the GIS MULTILINESTRING object
269 * @param array $scale_data Array containing data related to scaling
271 * @return string JavaScript related to a row in the GIS dataset
274 public function prepareRowAsOl($spatial, $srid, $label, $line_color, $scale_data)
276 $style_options = array(
277 'strokeColor' => $line_color,
285 $row = $this->getBoundsForOl($srid, $scale_data);
287 // Trim to remove leading 'MULTILINESTRING((' and trailing '))'
292 mb_strlen($spatial) - 19
294 // Separate each linestring
295 $linestirngs = explode("),(", $multilinestirng);
297 $row .= 'vectorLayer.addFeatures(new OpenLayers.Feature.Vector('
298 . 'new OpenLayers.Geometry.MultiLineString('
299 . $this->getLineArrayForOpenLayers($linestirngs, $srid)
300 . '), null, ' . json_encode($style_options) . '));';
306 * Generate the WKT with the set of parameters passed by the GIS editor.
308 * @param array $gis_data GIS data
309 * @param int $index Index into the parameter object
310 * @param string $empty Value for empty points
312 * @return string WKT with the set of parameters passed by the GIS editor
315 public function generateWkt($gis_data, $index, $empty = '')
317 $data_row = $gis_data[$index]['MULTILINESTRING'];
319 $no_of_lines = isset($data_row['no_of_lines'])
320 ?
$data_row['no_of_lines'] : 1;
321 if ($no_of_lines < 1) {
325 $wkt = 'MULTILINESTRING(';
326 for ($i = 0; $i < $no_of_lines; $i++
) {
327 $no_of_points = isset($data_row[$i]['no_of_points'])
328 ?
$data_row[$i]['no_of_points'] : 2;
329 if ($no_of_points < 2) {
333 for ($j = 0; $j < $no_of_points; $j++
) {
334 $wkt .= ((isset($data_row[$i][$j]['x'])
335 && trim($data_row[$i][$j]['x']) != '')
336 ?
$data_row[$i][$j]['x'] : $empty)
337 . ' ' . ((isset($data_row[$i][$j]['y'])
338 && trim($data_row[$i][$j]['y']) != '')
339 ?
$data_row[$i][$j]['y'] : $empty) . ',';
344 0, mb_strlen($wkt) - 1
360 * Generate the WKT for the data from ESRI shape files.
362 * @param array $row_data GIS data
364 * @return string the WKT for the data from ESRI shape files
367 public function getShape($row_data)
369 $wkt = 'MULTILINESTRING(';
370 for ($i = 0; $i < $row_data['numparts']; $i++
) {
372 foreach ($row_data['parts'][$i]['points'] as $point) {
373 $wkt .= $point['x'] . ' ' . $point['y'] . ',';
395 * Generate parameters for the GIS data editor from the value of the GIS column.
397 * @param string $value Value of the GIS column
398 * @param int $index Index of the geometry
400 * @return array params for the GIS data editor from the value of the GIS column
403 public function generateParams($value, $index = -1)
408 $data = GISGeometry
::generateParams($value);
409 $params['srid'] = $data['srid'];
412 $params[$index]['gis_type'] = 'MULTILINESTRING';
416 // Trim to remove leading 'MULTILINESTRING((' and trailing '))'
423 // Separate each linestring
424 $linestirngs = explode("),(", $multilinestirng);
425 $params[$index]['MULTILINESTRING']['no_of_lines'] = count($linestirngs);
428 foreach ($linestirngs as $linestring) {
429 $points_arr = $this->extractPoints($linestring, null);
430 $no_of_points = count($points_arr);
431 $params[$index]['MULTILINESTRING'][$j]['no_of_points'] = $no_of_points;
432 for ($i = 0; $i < $no_of_points; $i++
) {
433 $params[$index]['MULTILINESTRING'][$j][$i]['x'] = $points_arr[$i][0];
434 $params[$index]['MULTILINESTRING'][$j][$i]['y'] = $points_arr[$i][1];