2
/* vim: set expandtab sw=4 ts=4 sts=4: */
4
* Handles actions related to GIS MULTILINESTRING objects
6
* @package PhpMyAdmin-GIS
9
if (! defined('PHPMYADMIN')) {
14
* Handles actions related to GIS MULTILINESTRING objects
16
* @package PhpMyAdmin-GIS
18
class PMA_GIS_Multilinestring extends PMA_GIS_Geometry
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 object 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 cordinates
56
public function scaleRow($spatial)
60
// Trim to remove leading 'MULTILINESTRING((' and trailing '))'
61
$multilinestirng = substr($spatial, 17, (strlen($spatial) - 19));
62
// Seperate each linestring
63
$linestirngs = explode("),(", $multilinestirng);
65
foreach ($linestirngs as $linestring) {
66
$min_max = $this->setMinMax($linestring, $min_max);
73
* Adds to the PNG image object, the data related to a row in the GIS dataset.
75
* @param string $spatial GIS MULTILINESTRING object
76
* @param string $label Label for the GIS MULTILINESTRING object
77
* @param string $line_color Color for the GIS MULTILINESTRING object
78
* @param array $scale_data Array containing data related to scaling
79
* @param object $image Image object
81
* @return object the modified image object
84
public function prepareRowAsPng($spatial, $label, $line_color,
88
$black = imagecolorallocate($image, 0, 0, 0);
89
$red = hexdec(substr($line_color, 1, 2));
90
$green = hexdec(substr($line_color, 3, 2));
91
$blue = hexdec(substr($line_color, 4, 2));
92
$color = imagecolorallocate($image, $red, $green, $blue);
94
// Trim to remove leading 'MULTILINESTRING((' and trailing '))'
95
$multilinestirng = substr($spatial, 17, (strlen($spatial) - 19));
96
// Seperate each linestring
97
$linestirngs = explode("),(", $multilinestirng);
100
foreach ($linestirngs as $linestring) {
101
$points_arr = $this->extractPoints($linestring, $scale_data);
102
foreach ($points_arr as $point) {
103
if (! isset($temp_point)) {
104
$temp_point = $point;
108
$image, $temp_point[0], $temp_point[1],
109
$point[0], $point[1], $color
111
$temp_point = $point;
115
// print label if applicable
116
if (isset($label) && trim($label) != '' && $first_line) {
118
$image, 1, $points_arr[1][0],
119
$points_arr[1][1], trim($label), $black
128
* Adds to the TCPDF instance, the data related to a row in the GIS dataset.
130
* @param string $spatial GIS MULTILINESTRING object
131
* @param string $label Label for the GIS MULTILINESTRING object
132
* @param string $line_color Color for the GIS MULTILINESTRING object
133
* @param array $scale_data Array containing data related to scaling
134
* @param object $pdf TCPDF instance
136
* @return object the modified TCPDF instance
139
public function prepareRowAsPdf($spatial, $label, $line_color, $scale_data, $pdf)
142
$red = hexdec(substr($line_color, 1, 2));
143
$green = hexdec(substr($line_color, 3, 2));
144
$blue = hexdec(substr($line_color, 4, 2));
145
$line = array('width' => 1.5, 'color' => array($red, $green, $blue));
147
// Trim to remove leading 'MULTILINESTRING((' and trailing '))'
148
$multilinestirng = substr($spatial, 17, (strlen($spatial) - 19));
149
// Seperate each linestring
150
$linestirngs = explode("),(", $multilinestirng);
153
foreach ($linestirngs as $linestring) {
154
$points_arr = $this->extractPoints($linestring, $scale_data);
155
foreach ($points_arr as $point) {
156
if (! isset($temp_point)) {
157
$temp_point = $point;
161
$temp_point[0], $temp_point[1], $point[0], $point[1], $line
163
$temp_point = $point;
168
if (isset($label) && trim($label) != '' && $first_line) {
169
$pdf->SetXY($points_arr[1][0], $points_arr[1][1]);
170
$pdf->SetFontSize(5);
171
$pdf->Cell(0, 0, trim($label));
179
* Prepares and returns the code related to a row in the GIS dataset as SVG.
181
* @param string $spatial GIS MULTILINESTRING object
182
* @param string $label Label for the GIS MULTILINESTRING object
183
* @param string $line_color Color for the GIS MULTILINESTRING object
184
* @param array $scale_data Array containing data related to scaling
186
* @return string the code related to a row in the GIS dataset
189
public function prepareRowAsSvg($spatial, $label, $line_color, $scale_data)
191
$line_options = array(
193
'class' => 'linestring vector',
195
'stroke' => $line_color,
199
// Trim to remove leading 'MULTILINESTRING((' and trailing '))'
200
$multilinestirng = substr($spatial, 17, (strlen($spatial) - 19));
201
// Seperate each linestring
202
$linestirngs = explode("),(", $multilinestirng);
205
foreach ($linestirngs as $linestring) {
206
$points_arr = $this->extractPoints($linestring, $scale_data);
208
$row .= '<polyline points="';
209
foreach ($points_arr as $point) {
210
$row .= $point[0] . ',' . $point[1] . ' ';
213
$line_options['id'] = $label . rand();
214
foreach ($line_options as $option => $val) {
215
$row .= ' ' . $option . '="' . trim($val) . '"';
224
* Prepares JavaScript related to a row in the GIS dataset
225
* to visualize it with OpenLayers.
227
* @param string $spatial GIS MULTILINESTRING object
228
* @param int $srid Spatial reference ID
229
* @param string $label Label for the GIS MULTILINESTRING object
230
* @param string $line_color Color for the GIS MULTILINESTRING object
231
* @param array $scale_data Array containing data related to scaling
233
* @return string JavaScript related to a row in the GIS dataset
236
public function prepareRowAsOl($spatial, $srid, $label, $line_color, $scale_data)
238
$style_options = array(
239
'strokeColor' => $line_color,
247
$row = $this->getBoundsForOl($srid, $scale_data);
249
// Trim to remove leading 'MULTILINESTRING((' and trailing '))'
250
$multilinestirng = substr($spatial, 17, (strlen($spatial) - 19));
251
// Seperate each linestring
252
$linestirngs = explode("),(", $multilinestirng);
254
$row .= 'vectorLayer.addFeatures(new OpenLayers.Feature.Vector('
255
. 'new OpenLayers.Geometry.MultiLineString('
256
. $this->getLineArrayForOpenLayers($linestirngs, $srid)
257
. '), null, ' . json_encode($style_options) . '));';
262
* Generate the WKT with the set of parameters passed by the GIS editor.
264
* @param array $gis_data GIS data
265
* @param int $index Index into the parameter object
266
* @param string $empty Value for empty points
268
* @return string WKT with the set of parameters passed by the GIS editor
271
public function generateWkt($gis_data, $index, $empty = '')
273
$data_row = $gis_data[$index]['MULTILINESTRING'];
275
$no_of_lines = isset($data_row['no_of_lines'])
276
? $data_row['no_of_lines'] : 1;
277
if ($no_of_lines < 1) {
280
$wkt = 'MULTILINESTRING(';
281
for ($i = 0; $i < $no_of_lines; $i++) {
282
$no_of_points = isset($data_row[$i]['no_of_points'])
283
? $data_row[$i]['no_of_points'] : 2;
284
if ($no_of_points < 2) {
288
for ($j = 0; $j < $no_of_points; $j++) {
289
$wkt .= ((isset($data_row[$i][$j]['x'])
290
&& trim($data_row[$i][$j]['x']) != '')
291
? $data_row[$i][$j]['x'] : $empty)
292
. ' ' . ((isset($data_row[$i][$j]['y'])
293
&& trim($data_row[$i][$j]['y']) != '')
294
? $data_row[$i][$j]['y'] : $empty) . ',';
296
$wkt = substr($wkt, 0, strlen($wkt) - 1);
299
$wkt = substr($wkt, 0, strlen($wkt) - 1);
305
* Generate the WKT for the data from ESRI shape files.
307
* @param array $row_data GIS data
309
* @return string the WKT for the data from ESRI shape files
312
public function getShape($row_data)
314
$wkt = 'MULTILINESTRING(';
315
for ($i = 0; $i < $row_data['numparts']; $i++) {
317
foreach ($row_data['parts'][$i]['points'] as $point) {
318
$wkt .= $point['x'] . ' ' . $point['y'] . ',';
320
$wkt = substr($wkt, 0, strlen($wkt) - 1);
323
$wkt = substr($wkt, 0, strlen($wkt) - 1);
329
* Generate parameters for the GIS data editor from the value of the GIS column.
331
* @param string $value of the GIS column
332
* @param index $index of the geometry
334
* @return array params for the GIS data editor from the value of the GIS column
337
public function generateParams($value, $index = -1)
342
$data = PMA_GIS_Geometry::generateParams($value);
343
$params['srid'] = $data['srid'];
346
$params[$index]['gis_type'] = 'MULTILINESTRING';
350
// Trim to remove leading 'MULTILINESTRING((' and trailing '))'
351
$multilinestirng = substr($wkt, 17, (strlen($wkt) - 19));
352
// Seperate each linestring
353
$linestirngs = explode("),(", $multilinestirng);
354
$params[$index]['MULTILINESTRING']['no_of_lines'] = count($linestirngs);
357
foreach ($linestirngs as $linestring) {
358
$points_arr = $this->extractPoints($linestring, null);
359
$no_of_points = count($points_arr);
360
$params[$index]['MULTILINESTRING'][$j]['no_of_points'] = $no_of_points;
361
for ($i = 0; $i < $no_of_points; $i++) {
362
$params[$index]['MULTILINESTRING'][$j][$i]['x'] = $points_arr[$i][0];
363
$params[$index]['MULTILINESTRING'][$j][$i]['y'] = $points_arr[$i][1];