Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / phpmyadmin / libraries / gis / pma_gis_linestring.php
blob9c4951224b78f3f03eb77ccde244e4c5248b3cad
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 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 // Trim to remove leading 'LINESTRING(' and trailing ')'
59 $linesrting = substr($spatial, 11, (strlen($spatial) - 12));
60 return $this->setMinMax($linesrting, array());
63 /**
64 * Adds to the PNG image object, the data related to a row in the GIS dataset.
66 * @param string $spatial GIS LINESTRING object
67 * @param string $label Label for the GIS LINESTRING object
68 * @param string $line_color Color for the GIS LINESTRING object
69 * @param array $scale_data Array containing data related to scaling
70 * @param object $image Image object
72 * @return object the modified image object
73 * @access public
75 public function prepareRowAsPng($spatial, $label, $line_color,
76 $scale_data, $image
77 ) {
78 // allocate colors
79 $black = imagecolorallocate($image, 0, 0, 0);
80 $red = hexdec(substr($line_color, 1, 2));
81 $green = hexdec(substr($line_color, 3, 2));
82 $blue = hexdec(substr($line_color, 4, 2));
83 $color = imagecolorallocate($image, $red, $green, $blue);
85 // Trim to remove leading 'LINESTRING(' and trailing ')'
86 $linesrting = substr($spatial, 11, (strlen($spatial) - 12));
87 $points_arr = $this->extractPoints($linesrting, $scale_data);
89 foreach ($points_arr as $point) {
90 if (! isset($temp_point)) {
91 $temp_point = $point;
92 } else {
93 // draw line section
94 imageline(
95 $image, $temp_point[0], $temp_point[1],
96 $point[0], $point[1], $color
98 $temp_point = $point;
101 // print label if applicable
102 if (isset($label) && trim($label) != '') {
103 imagestring(
104 $image, 1, $points_arr[1][0],
105 $points_arr[1][1], trim($label), $black
108 return $image;
112 * Adds to the TCPDF instance, the data related to a row in the GIS dataset.
114 * @param string $spatial GIS LINESTRING object
115 * @param string $label Label for the GIS LINESTRING object
116 * @param string $line_color Color for the GIS LINESTRING object
117 * @param array $scale_data Array containing data related to scaling
118 * @param object $pdf TCPDF instance
120 * @return object the modified TCPDF instance
121 * @access public
123 public function prepareRowAsPdf($spatial, $label, $line_color, $scale_data, $pdf)
125 // allocate colors
126 $red = hexdec(substr($line_color, 1, 2));
127 $green = hexdec(substr($line_color, 3, 2));
128 $blue = hexdec(substr($line_color, 4, 2));
129 $line = array('width' => 1.5, 'color' => array($red, $green, $blue));
131 // Trim to remove leading 'LINESTRING(' and trailing ')'
132 $linesrting = substr($spatial, 11, (strlen($spatial) - 12));
133 $points_arr = $this->extractPoints($linesrting, $scale_data);
135 foreach ($points_arr as $point) {
136 if (! isset($temp_point)) {
137 $temp_point = $point;
138 } else {
139 // draw line section
140 $pdf->Line(
141 $temp_point[0], $temp_point[1],
142 $point[0], $point[1], $line
144 $temp_point = $point;
147 // print label
148 if (isset($label) && trim($label) != '') {
149 $pdf->SetXY($points_arr[1][0], $points_arr[1][1]);
150 $pdf->SetFontSize(5);
151 $pdf->Cell(0, 0, trim($label));
153 return $pdf;
157 * Prepares and returns the code related to a row in the GIS dataset as SVG.
159 * @param string $spatial GIS LINESTRING object
160 * @param string $label Label for the GIS LINESTRING object
161 * @param string $line_color Color for the GIS LINESTRING object
162 * @param array $scale_data Array containing data related to scaling
164 * @return string the code related to a row in the GIS dataset
165 * @access public
167 public function prepareRowAsSvg($spatial, $label, $line_color, $scale_data)
169 $line_options = array(
170 'name' => $label,
171 'id' => $label . rand(),
172 'class' => 'linestring vector',
173 'fill' => 'none',
174 'stroke' => $line_color,
175 'stroke-width'=> 2,
178 // Trim to remove leading 'LINESTRING(' and trailing ')'
179 $linesrting = substr($spatial, 11, (strlen($spatial) - 12));
180 $points_arr = $this->extractPoints($linesrting, $scale_data);
182 $row = '<polyline points="';
183 foreach ($points_arr as $point) {
184 $row .= $point[0] . ',' . $point[1] . ' ';
186 $row .= '"';
187 foreach ($line_options as $option => $val) {
188 $row .= ' ' . $option . '="' . trim($val) . '"';
190 $row .= '/>';
192 return $row;
196 * Prepares JavaScript related to a row in the GIS dataset
197 * to visualize it with OpenLayers.
199 * @param string $spatial GIS LINESTRING object
200 * @param int $srid Spatial reference ID
201 * @param string $label Label for the GIS LINESTRING object
202 * @param string $line_color Color for the GIS LINESTRING object
203 * @param array $scale_data Array containing data related to scaling
205 * @return string JavaScript related to a row in the GIS dataset
206 * @access public
208 public function prepareRowAsOl($spatial, $srid, $label, $line_color, $scale_data)
210 $style_options = array(
211 'strokeColor' => $line_color,
212 'strokeWidth' => 2,
213 'label' => $label,
214 'fontSize' => 10,
216 if ($srid == 0) {
217 $srid = 4326;
219 $result = $this->getBoundsForOl($srid, $scale_data);
221 // Trim to remove leading 'LINESTRING(' and trailing ')'
222 $linesrting = substr($spatial, 11, (strlen($spatial) - 12));
223 $points_arr = $this->extractPoints($linesrting, null);
225 $result .= 'vectorLayer.addFeatures(new OpenLayers.Feature.Vector('
226 . $this->getLineForOpenLayers($points_arr, $srid)
227 . ', null, ' . json_encode($style_options) . '));';
228 return $result;
232 * Generate the WKT with the set of parameters passed by the GIS editor.
234 * @param array $gis_data GIS data
235 * @param int $index Index into the parameter object
236 * @param string $empty Value for empty points
238 * @return string WKT with the set of parameters passed by the GIS editor
239 * @access public
241 public function generateWkt($gis_data, $index, $empty = '')
243 $no_of_points = isset($gis_data[$index]['LINESTRING']['no_of_points'])
244 ? $gis_data[$index]['LINESTRING']['no_of_points'] : 2;
245 if ($no_of_points < 2) {
246 $no_of_points = 2;
248 $wkt = 'LINESTRING(';
249 for ($i = 0; $i < $no_of_points; $i++) {
250 $wkt .= ((isset($gis_data[$index]['LINESTRING'][$i]['x'])
251 && trim($gis_data[$index]['LINESTRING'][$i]['x']) != '')
252 ? $gis_data[$index]['LINESTRING'][$i]['x'] : $empty)
253 . ' ' . ((isset($gis_data[$index]['LINESTRING'][$i]['y'])
254 && trim($gis_data[$index]['LINESTRING'][$i]['y']) != '')
255 ? $gis_data[$index]['LINESTRING'][$i]['y'] : $empty) .',';
257 $wkt = substr($wkt, 0, strlen($wkt) - 1);
258 $wkt .= ')';
259 return $wkt;
263 * Generate parameters for the GIS data editor from the value of the GIS column.
265 * @param string $value of the GIS column
266 * @param int $index of the geometry
268 * @return array params for the GIS data editor from the value of the GIS column
269 * @access public
271 public function generateParams($value, $index = -1)
273 if ($index == -1) {
274 $index = 0;
275 $params = array();
276 $data = PMA_GIS_Geometry::generateParams($value);
277 $params['srid'] = $data['srid'];
278 $wkt = $data['wkt'];
279 } else {
280 $params[$index]['gis_type'] = 'LINESTRING';
281 $wkt = $value;
284 // Trim to remove leading 'LINESTRING(' and trailing ')'
285 $linestring = substr($wkt, 11, (strlen($wkt) - 12));
286 $points_arr = $this->extractPoints($linestring, null);
288 $no_of_points = count($points_arr);
289 $params[$index]['LINESTRING']['no_of_points'] = $no_of_points;
290 for ($i = 0; $i < $no_of_points; $i++) {
291 $params[$index]['LINESTRING'][$i]['x'] = $points_arr[$i][0];
292 $params[$index]['LINESTRING'][$i]['y'] = $points_arr[$i][1];
295 return $params;