Upgraded phpmyadmin to 4.0.4 (All Languages) - No modifications yet
[openemr.git] / phpmyadmin / libraries / gis / pma_gis_multipoint.php
blobe6b7ef71ada6f5e56a4b90f20fcf2982accff127
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Handles actions related to GIS MULTIPOINT objects
6 * @package PhpMyAdmin-GIS
7 */
9 if (! defined('PHPMYADMIN')) {
10 exit;
13 /**
14 * Handles actions related to GIS MULTIPOINT objects
16 * @package PhpMyAdmin-GIS
18 class PMA_GIS_Multipoint 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 'MULTIPOINT(' and trailing ')'
59 $multipoint = substr($spatial, 11, (strlen($spatial) - 12));
60 return $this->setMinMax($multipoint, array());
63 /**
64 * Adds to the PNG image object, the data related to a row in the GIS dataset.
66 * @param string $spatial GIS MULTIPOINT object
67 * @param string $label Label for the GIS MULTIPOINT object
68 * @param string $point_color Color for the GIS MULTIPOINT 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, $point_color,
76 $scale_data, $image
77 ) {
78 // allocate colors
79 $black = imagecolorallocate($image, 0, 0, 0);
80 $red = hexdec(substr($point_color, 1, 2));
81 $green = hexdec(substr($point_color, 3, 2));
82 $blue = hexdec(substr($point_color, 4, 2));
83 $color = imagecolorallocate($image, $red, $green, $blue);
85 // Trim to remove leading 'MULTIPOINT(' and trailing ')'
86 $multipoint = substr($spatial, 11, (strlen($spatial) - 12));
87 $points_arr = $this->extractPoints($multipoint, $scale_data);
89 foreach ($points_arr as $point) {
90 // draw a small circle to mark the point
91 if ($point[0] != '' && $point[1] != '') {
92 imagearc($image, $point[0], $point[1], 7, 7, 0, 360, $color);
95 // print label for each point
96 if ((isset($label) && trim($label) != '')
97 && ($points_arr[0][0] != '' && $points_arr[0][1] != '')
98 ) {
99 imagestring(
100 $image, 1, $points_arr[0][0], $points_arr[0][1], trim($label), $black
103 return $image;
107 * Adds to the TCPDF instance, the data related to a row in the GIS dataset.
109 * @param string $spatial GIS MULTIPOINT object
110 * @param string $label Label for the GIS MULTIPOINT object
111 * @param string $point_color Color for the GIS MULTIPOINT object
112 * @param array $scale_data Array containing data related to scaling
113 * @param object $pdf TCPDF instance
115 * @return object the modified TCPDF instance
116 * @access public
118 public function prepareRowAsPdf($spatial, $label, $point_color,
119 $scale_data, $pdf
121 // allocate colors
122 $red = hexdec(substr($point_color, 1, 2));
123 $green = hexdec(substr($point_color, 3, 2));
124 $blue = hexdec(substr($point_color, 4, 2));
125 $line = array('width' => 1.25, 'color' => array($red, $green, $blue));
127 // Trim to remove leading 'MULTIPOINT(' and trailing ')'
128 $multipoint = substr($spatial, 11, (strlen($spatial) - 12));
129 $points_arr = $this->extractPoints($multipoint, $scale_data);
131 foreach ($points_arr as $point) {
132 // draw a small circle to mark the point
133 if ($point[0] != '' && $point[1] != '') {
134 $pdf->Circle($point[0], $point[1], 2, 0, 360, 'D', $line);
137 // print label for each point
138 if ((isset($label) && trim($label) != '')
139 && ($points_arr[0][0] != '' && $points_arr[0][1] != '')
141 $pdf->SetXY($points_arr[0][0], $points_arr[0][1]);
142 $pdf->SetFontSize(5);
143 $pdf->Cell(0, 0, trim($label));
145 return $pdf;
149 * Prepares and returns the code related to a row in the GIS dataset as SVG.
151 * @param string $spatial GIS MULTIPOINT object
152 * @param string $label Label for the GIS MULTIPOINT object
153 * @param string $point_color Color for the GIS MULTIPOINT object
154 * @param array $scale_data Array containing data related to scaling
156 * @return string the code related to a row in the GIS dataset
157 * @access public
159 public function prepareRowAsSvg($spatial, $label, $point_color, $scale_data)
161 $point_options = array(
162 'name' => $label,
163 'class' => 'multipoint vector',
164 'fill' => 'white',
165 'stroke' => $point_color,
166 'stroke-width'=> 2,
169 // Trim to remove leading 'MULTIPOINT(' and trailing ')'
170 $multipoint = substr($spatial, 11, (strlen($spatial) - 12));
171 $points_arr = $this->extractPoints($multipoint, $scale_data);
173 $row = '';
174 foreach ($points_arr as $point) {
175 if ($point[0] != '' && $point[1] != '') {
176 $row .= '<circle cx="' . $point[0] . '" cy="'
177 . $point[1] . '" r="3"';
178 $point_options['id'] = $label . rand();
179 foreach ($point_options as $option => $val) {
180 $row .= ' ' . $option . '="' . trim($val) . '"';
182 $row .= '/>';
186 return $row;
190 * Prepares JavaScript related to a row in the GIS dataset
191 * to visualize it with OpenLayers.
193 * @param string $spatial GIS MULTIPOINT object
194 * @param int $srid Spatial reference ID
195 * @param string $label Label for the GIS MULTIPOINT object
196 * @param string $point_color Color for the GIS MULTIPOINT object
197 * @param array $scale_data Array containing data related to scaling
199 * @return string JavaScript related to a row in the GIS dataset
200 * @access public
202 public function prepareRowAsOl($spatial, $srid, $label,
203 $point_color, $scale_data
205 $style_options = array(
206 'pointRadius' => 3,
207 'fillColor' => '#ffffff',
208 'strokeColor' => $point_color,
209 'strokeWidth' => 2,
210 'label' => $label,
211 'labelYOffset' => -8,
212 'fontSize' => 10,
214 if ($srid == 0) {
215 $srid = 4326;
217 $result = $this->getBoundsForOl($srid, $scale_data);
219 // Trim to remove leading 'MULTIPOINT(' and trailing ')'
220 $multipoint = substr($spatial, 11, (strlen($spatial) - 12));
221 $points_arr = $this->extractPoints($multipoint, null);
223 $result .= 'vectorLayer.addFeatures(new OpenLayers.Feature.Vector('
224 . 'new OpenLayers.Geometry.MultiPoint('
225 . $this->getPointsArrayForOpenLayers($points_arr, $srid)
226 . '), null, ' . json_encode($style_options) . '));';
227 return $result;
231 * Generate the WKT with the set of parameters passed by the GIS editor.
233 * @param array $gis_data GIS data
234 * @param int $index Index into the parameter object
235 * @param string $empty Multipoint does not adhere to this
237 * @return string WKT with the set of parameters passed by the GIS editor
238 * @access public
240 public function generateWkt($gis_data, $index, $empty = '')
242 $no_of_points = isset($gis_data[$index]['MULTIPOINT']['no_of_points'])
243 ? $gis_data[$index]['MULTIPOINT']['no_of_points'] : 1;
244 if ($no_of_points < 1) {
245 $no_of_points = 1;
247 $wkt = 'MULTIPOINT(';
248 for ($i = 0; $i < $no_of_points; $i++) {
249 $wkt .= ((isset($gis_data[$index]['MULTIPOINT'][$i]['x'])
250 && trim($gis_data[$index]['MULTIPOINT'][$i]['x']) != '')
251 ? $gis_data[$index]['MULTIPOINT'][$i]['x'] : '')
252 . ' ' . ((isset($gis_data[$index]['MULTIPOINT'][$i]['y'])
253 && trim($gis_data[$index]['MULTIPOINT'][$i]['y']) != '')
254 ? $gis_data[$index]['MULTIPOINT'][$i]['y'] : '') . ',';
256 $wkt = substr($wkt, 0, strlen($wkt) - 1);
257 $wkt .= ')';
258 return $wkt;
262 * Generate the WKT for the data from ESRI shape files.
264 * @param array $row_data GIS data
266 * @return string the WKT for the data from ESRI shape files
267 * @access public
269 public function getShape($row_data)
271 $wkt = 'MULTIPOINT(';
272 for ($i = 0; $i < $row_data['numpoints']; $i++) {
273 $wkt .= $row_data['points'][$i]['x'] . ' '
274 . $row_data['points'][$i]['y'] . ',';
276 $wkt = substr($wkt, 0, strlen($wkt) - 1);
277 $wkt .= ')';
278 return $wkt;
282 * Generate parameters for the GIS data editor from the value of the GIS column.
284 * @param string $value of the GIS column
285 * @param index $index of the geometry
287 * @return array params for the GIS data editor from the value of the GIS column
288 * @access public
290 public function generateParams($value, $index = -1)
292 if ($index == -1) {
293 $index = 0;
294 $params = array();
295 $data = PMA_GIS_Geometry::generateParams($value);
296 $params['srid'] = $data['srid'];
297 $wkt = $data['wkt'];
298 } else {
299 $params[$index]['gis_type'] = 'MULTIPOINT';
300 $wkt = $value;
303 // Trim to remove leading 'MULTIPOINT(' and trailing ')'
304 $points = substr($wkt, 11, (strlen($wkt) - 12));
305 $points_arr = $this->extractPoints($points, null);
307 $no_of_points = count($points_arr);
308 $params[$index]['MULTIPOINT']['no_of_points'] = $no_of_points;
309 for ($i = 0; $i < $no_of_points; $i++) {
310 $params[$index]['MULTIPOINT'][$i]['x'] = $points_arr[$i][0];
311 $params[$index]['MULTIPOINT'][$i]['y'] = $points_arr[$i][1];
314 return $params;
318 * Overidden to make sure that only the points having valid values
319 * for x and y coordinates are added.
321 * @param array $points_arr x and y coordinates for each point
322 * @param string $srid spatial reference id
324 * @return string JavaScript for adding an array of points to OpenLayers
325 * @access protected
327 protected function getPointsArrayForOpenLayers($points_arr, $srid)
329 $ol_array = 'new Array(';
330 foreach ($points_arr as $point) {
331 if ($point[0] != '' && $point[1] != '') {
332 $ol_array .= $this->getPointForOpenLayers($point, $srid) . ', ';
335 if (substr($ol_array, strlen($ol_array) - 2) == ', ') {
336 $ol_array = substr($ol_array, 0, strlen($ol_array) - 2);
338 $ol_array .= ')';
340 return $ol_array;