Upgraded phpmyadmin to 4.0.4 (All Languages) - No modifications yet
[openemr.git] / phpmyadmin / libraries / gis / pma_gis_multilinestring.php
blobce4a0c94a187fc0d92d5cd73dbe3a679da69b4a7
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Handles actions related to GIS MULTILINESTRING objects
6 * @package PhpMyAdmin-GIS
7 */
9 if (! defined('PHPMYADMIN')) {
10 exit;
13 /**
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;
23 /**
24 * A private constructor; prevents direct creation of object.
26 * @access private
28 private function __construct()
32 /**
33 * Returns the singleton.
35 * @return object the singleton
36 * @access public
38 public static function singleton()
40 if (!isset(self::$_instance)) {
41 $class = __CLASS__;
42 self::$_instance = new $class;
45 return self::$_instance;
48 /**
49 * Scales each row.
51 * @param string $spatial spatial data of a row
53 * @return array an array containing the min, max values for x and y cordinates
54 * @access public
56 public function scaleRow($spatial)
58 $min_max = array();
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);
69 return $min_max;
72 /**
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
82 * @access public
84 public function prepareRowAsPng($spatial, $label, $line_color,
85 $scale_data, $image
86 ) {
87 // allocate colors
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);
99 $first_line = true;
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;
105 } else {
106 // draw line section
107 imageline(
108 $image, $temp_point[0], $temp_point[1],
109 $point[0], $point[1], $color
111 $temp_point = $point;
114 unset($temp_point);
115 // print label if applicable
116 if (isset($label) && trim($label) != '' && $first_line) {
117 imagestring(
118 $image, 1, $points_arr[1][0],
119 $points_arr[1][1], trim($label), $black
122 $first_line = false;
124 return $image;
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
137 * @access public
139 public function prepareRowAsPdf($spatial, $label, $line_color, $scale_data, $pdf)
141 // allocate colors
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);
152 $first_line = true;
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;
158 } else {
159 // draw line section
160 $pdf->Line(
161 $temp_point[0], $temp_point[1], $point[0], $point[1], $line
163 $temp_point = $point;
166 unset($temp_point);
167 // print label
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));
173 $first_line = false;
175 return $pdf;
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
187 * @access public
189 public function prepareRowAsSvg($spatial, $label, $line_color, $scale_data)
191 $line_options = array(
192 'name' => $label,
193 'class' => 'linestring vector',
194 'fill' => 'none',
195 'stroke' => $line_color,
196 'stroke-width'=> 2,
199 // Trim to remove leading 'MULTILINESTRING((' and trailing '))'
200 $multilinestirng = substr($spatial, 17, (strlen($spatial) - 19));
201 // Seperate each linestring
202 $linestirngs = explode("),(", $multilinestirng);
204 $row = '';
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] . ' ';
212 $row .= '"';
213 $line_options['id'] = $label . rand();
214 foreach ($line_options as $option => $val) {
215 $row .= ' ' . $option . '="' . trim($val) . '"';
217 $row .= '/>';
220 return $row;
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
234 * @access public
236 public function prepareRowAsOl($spatial, $srid, $label, $line_color, $scale_data)
238 $style_options = array(
239 'strokeColor' => $line_color,
240 'strokeWidth' => 2,
241 'label' => $label,
242 'fontSize' => 10,
244 if ($srid == 0) {
245 $srid = 4326;
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) . '));';
258 return $row;
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
269 * @access public
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) {
278 $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) {
285 $no_of_points = 2;
287 $wkt .= '(';
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);
297 $wkt .= '),';
299 $wkt = substr($wkt, 0, strlen($wkt) - 1);
300 $wkt .= ')';
301 return $wkt;
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
310 * @access public
312 public function getShape($row_data)
314 $wkt = 'MULTILINESTRING(';
315 for ($i = 0; $i < $row_data['numparts']; $i++) {
316 $wkt .= '(';
317 foreach ($row_data['parts'][$i]['points'] as $point) {
318 $wkt .= $point['x'] . ' ' . $point['y'] . ',';
320 $wkt = substr($wkt, 0, strlen($wkt) - 1);
321 $wkt .= '),';
323 $wkt = substr($wkt, 0, strlen($wkt) - 1);
324 $wkt .= ')';
325 return $wkt;
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
335 * @access public
337 public function generateParams($value, $index = -1)
339 if ($index == -1) {
340 $index = 0;
341 $params = array();
342 $data = PMA_GIS_Geometry::generateParams($value);
343 $params['srid'] = $data['srid'];
344 $wkt = $data['wkt'];
345 } else {
346 $params[$index]['gis_type'] = 'MULTILINESTRING';
347 $wkt = $value;
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);
356 $j = 0;
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];
365 $j++;
367 return $params;