1. Check existence of mb_string, mysql and xml extensions before installation.
[openemr.git] / phpmyadmin / libraries / gis / GIS_Linestring.class.php
blob81d025d92d92702c16f3a9ca3f9c26d0c1562805
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Handles actions related to GIS LINESTRING objects
6 * @package PhpMyAdmin-GIS
7 */
9 if (! defined('PHPMYADMIN')) {
10 exit;
13 /**
14 * Handles actions related to GIS LINESTRING objects
16 * @package PhpMyAdmin-GIS
18 class PMA_GIS_Linestring 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 PMA_GIS_Linestring 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 coordinates
54 * @access public
56 public function scaleRow($spatial)
58 // Trim to remove leading 'LINESTRING(' and trailing ')'
59 $linestring = /*overload*/mb_substr(
60 $spatial,
61 11,
62 /*overload*/mb_strlen($spatial) - 12
64 return $this->setMinMax($linestring, array());
67 /**
68 * Adds to the PNG image object, the data related to a row in the GIS dataset.
70 * @param string $spatial GIS LINESTRING object
71 * @param string $label Label for the GIS LINESTRING object
72 * @param string $line_color Color for the GIS LINESTRING object
73 * @param array $scale_data Array containing data related to scaling
74 * @param object $image Image object
76 * @return resource the modified image object
77 * @access public
79 public function prepareRowAsPng($spatial, $label, $line_color,
80 $scale_data, $image
81 ) {
82 // allocate colors
83 $black = imagecolorallocate($image, 0, 0, 0);
84 $red = hexdec(/*overload*/mb_substr($line_color, 1, 2));
85 $green = hexdec(/*overload*/mb_substr($line_color, 3, 2));
86 $blue = hexdec(/*overload*/mb_substr($line_color, 4, 2));
87 $color = imagecolorallocate($image, $red, $green, $blue);
89 // Trim to remove leading 'LINESTRING(' and trailing ')'
90 $linesrting = /*overload*/mb_substr(
91 $spatial,
92 11,
93 /*overload*/mb_strlen($spatial) - 12
95 $points_arr = $this->extractPoints($linesrting, $scale_data);
97 foreach ($points_arr as $point) {
98 if (! isset($temp_point)) {
99 $temp_point = $point;
100 } else {
101 // draw line section
102 imageline(
103 $image, $temp_point[0], $temp_point[1],
104 $point[0], $point[1], $color
106 $temp_point = $point;
109 // print label if applicable
110 if (isset($label) && trim($label) != '') {
111 imagestring(
112 $image, 1, $points_arr[1][0],
113 $points_arr[1][1], trim($label), $black
116 return $image;
120 * Adds to the TCPDF instance, the data related to a row in the GIS dataset.
122 * @param string $spatial GIS LINESTRING object
123 * @param string $label Label for the GIS LINESTRING object
124 * @param string $line_color Color for the GIS LINESTRING object
125 * @param array $scale_data Array containing data related to scaling
126 * @param TCPDF $pdf TCPDF instance
128 * @return TCPDF the modified TCPDF instance
129 * @access public
131 public function prepareRowAsPdf($spatial, $label, $line_color, $scale_data, $pdf)
133 // allocate colors
134 $red = hexdec(/*overload*/mb_substr($line_color, 1, 2));
135 $green = hexdec(/*overload*/mb_substr($line_color, 3, 2));
136 $blue = hexdec(/*overload*/mb_substr($line_color, 4, 2));
137 $line = array('width' => 1.5, 'color' => array($red, $green, $blue));
139 // Trim to remove leading 'LINESTRING(' and trailing ')'
140 $linesrting = /*overload*/mb_substr(
141 $spatial,
143 /*overload*/mb_strlen($spatial) - 12
145 $points_arr = $this->extractPoints($linesrting, $scale_data);
147 foreach ($points_arr as $point) {
148 if (! isset($temp_point)) {
149 $temp_point = $point;
150 } else {
151 // draw line section
152 $pdf->Line(
153 $temp_point[0], $temp_point[1],
154 $point[0], $point[1], $line
156 $temp_point = $point;
159 // print label
160 if (isset($label) && trim($label) != '') {
161 $pdf->SetXY($points_arr[1][0], $points_arr[1][1]);
162 $pdf->SetFontSize(5);
163 $pdf->Cell(0, 0, trim($label));
165 return $pdf;
169 * Prepares and returns the code related to a row in the GIS dataset as SVG.
171 * @param string $spatial GIS LINESTRING object
172 * @param string $label Label for the GIS LINESTRING object
173 * @param string $line_color Color for the GIS LINESTRING object
174 * @param array $scale_data Array containing data related to scaling
176 * @return string the code related to a row in the GIS dataset
177 * @access public
179 public function prepareRowAsSvg($spatial, $label, $line_color, $scale_data)
181 $line_options = array(
182 'name' => $label,
183 'id' => $label . rand(),
184 'class' => 'linestring vector',
185 'fill' => 'none',
186 'stroke' => $line_color,
187 'stroke-width'=> 2,
190 // Trim to remove leading 'LINESTRING(' and trailing ')'
191 $linesrting = /*overload*/mb_substr(
192 $spatial,
194 /*overload*/mb_strlen($spatial) - 12
196 $points_arr = $this->extractPoints($linesrting, $scale_data);
198 $row = '<polyline points="';
199 foreach ($points_arr as $point) {
200 $row .= $point[0] . ',' . $point[1] . ' ';
202 $row .= '"';
203 foreach ($line_options as $option => $val) {
204 $row .= ' ' . $option . '="' . trim($val) . '"';
206 $row .= '/>';
208 return $row;
212 * Prepares JavaScript related to a row in the GIS dataset
213 * to visualize it with OpenLayers.
215 * @param string $spatial GIS LINESTRING object
216 * @param int $srid Spatial reference ID
217 * @param string $label Label for the GIS LINESTRING object
218 * @param string $line_color Color for the GIS LINESTRING object
219 * @param array $scale_data Array containing data related to scaling
221 * @return string JavaScript related to a row in the GIS dataset
222 * @access public
224 public function prepareRowAsOl($spatial, $srid, $label, $line_color, $scale_data)
226 $style_options = array(
227 'strokeColor' => $line_color,
228 'strokeWidth' => 2,
229 'label' => $label,
230 'fontSize' => 10,
232 if ($srid == 0) {
233 $srid = 4326;
235 $result = $this->getBoundsForOl($srid, $scale_data);
237 // Trim to remove leading 'LINESTRING(' and trailing ')'
238 $linesrting = /*overload*/mb_substr(
239 $spatial,
241 /*overload*/mb_strlen($spatial) - 12
243 $points_arr = $this->extractPoints($linesrting, null);
245 $result .= 'vectorLayer.addFeatures(new OpenLayers.Feature.Vector('
246 . $this->getLineForOpenLayers($points_arr, $srid)
247 . ', null, ' . json_encode($style_options) . '));';
248 return $result;
252 * Generate the WKT with the set of parameters passed by the GIS editor.
254 * @param array $gis_data GIS data
255 * @param int $index Index into the parameter object
256 * @param string $empty Value for empty points
258 * @return string WKT with the set of parameters passed by the GIS editor
259 * @access public
261 public function generateWkt($gis_data, $index, $empty = '')
263 $no_of_points = isset($gis_data[$index]['LINESTRING']['no_of_points'])
264 ? $gis_data[$index]['LINESTRING']['no_of_points'] : 2;
265 if ($no_of_points < 2) {
266 $no_of_points = 2;
268 $wkt = 'LINESTRING(';
269 for ($i = 0; $i < $no_of_points; $i++) {
270 $wkt .= ((isset($gis_data[$index]['LINESTRING'][$i]['x'])
271 && trim($gis_data[$index]['LINESTRING'][$i]['x']) != '')
272 ? $gis_data[$index]['LINESTRING'][$i]['x'] : $empty)
273 . ' ' . ((isset($gis_data[$index]['LINESTRING'][$i]['y'])
274 && trim($gis_data[$index]['LINESTRING'][$i]['y']) != '')
275 ? $gis_data[$index]['LINESTRING'][$i]['y'] : $empty) . ',';
278 $wkt = /*overload*/mb_substr($wkt, 0, /*overload*/mb_strlen($wkt) - 1);
279 $wkt .= ')';
280 return $wkt;
284 * Generate parameters for the GIS data editor from the value of the GIS column.
286 * @param string $value of the GIS column
287 * @param int $index of the geometry
289 * @return array params for the GIS data editor from the value of the GIS column
290 * @access public
292 public function generateParams($value, $index = -1)
294 $params = array();
295 if ($index == -1) {
296 $index = 0;
297 $data = PMA_GIS_Geometry::generateParams($value);
298 $params['srid'] = $data['srid'];
299 $wkt = $data['wkt'];
300 } else {
301 $params[$index]['gis_type'] = 'LINESTRING';
302 $wkt = $value;
305 // Trim to remove leading 'LINESTRING(' and trailing ')'
306 $linestring = /*overload*/mb_substr(
307 $wkt,
309 /*overload*/mb_strlen($wkt) - 12
311 $points_arr = $this->extractPoints($linestring, null);
313 $no_of_points = count($points_arr);
314 $params[$index]['LINESTRING']['no_of_points'] = $no_of_points;
315 for ($i = 0; $i < $no_of_points; $i++) {
316 $params[$index]['LINESTRING'][$i]['x'] = $points_arr[$i][0];
317 $params[$index]['LINESTRING'][$i]['y'] = $points_arr[$i][1];
320 return $params;