Upgraded phpmyadmin to 4.0.4 (All Languages) - No modifications yet
[openemr.git] / phpmyadmin / libraries / gis / pma_gis_point.php
blobe1e4d237087d5345f8e87bc3f5fd15462d1b272c
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Handles actions related to GIS POINT objects
6 * @package PhpMyAdmin-GIS
7 */
9 if (! defined('PHPMYADMIN')) {
10 exit;
13 /**
14 * Handles actions related to GIS POINT objects
16 * @package PhpMyAdmin-GIS
18 class PMA_GIS_Point 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 'POINT(' and trailing ')'
59 $point = substr($spatial, 6, (strlen($spatial) - 7));
60 return $this->setMinMax($point, array());
63 /**
64 * Adds to the PNG image object, the data related to a row in the GIS dataset.
66 * @param string $spatial GIS POINT object
67 * @param string $label Label for the GIS POINT object
68 * @param string $point_color Color for the GIS POINT 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 'POINT(' and trailing ')'
86 $point = substr($spatial, 6, (strlen($spatial) - 7));
87 $points_arr = $this->extractPoints($point, $scale_data);
89 // draw a small circle to mark the point
90 if ($points_arr[0][0] != '' && $points_arr[0][1] != '') {
91 imagearc(
92 $image, $points_arr[0][0], $points_arr[0][1], 7, 7, 0, 360, $color
94 // print label if applicable
95 if (isset($label) && trim($label) != '') {
96 imagestring(
97 $image, 1, $points_arr[0][0],
98 $points_arr[0][1], trim($label), $black
102 return $image;
106 * Adds to the TCPDF instance, the data related to a row in the GIS dataset.
108 * @param string $spatial GIS POINT object
109 * @param string $label Label for the GIS POINT object
110 * @param string $point_color Color for the GIS POINT object
111 * @param array $scale_data Array containing data related to scaling
112 * @param object $pdf TCPDF instance
114 * @return object the modified TCPDF instance
115 * @access public
117 public function prepareRowAsPdf($spatial, $label, $point_color,
118 $scale_data, $pdf
120 // allocate colors
121 $red = hexdec(substr($point_color, 1, 2));
122 $green = hexdec(substr($point_color, 3, 2));
123 $blue = hexdec(substr($point_color, 4, 2));
124 $line = array('width' => 1.25, 'color' => array($red, $green, $blue));
126 // Trim to remove leading 'POINT(' and trailing ')'
127 $point = substr($spatial, 6, (strlen($spatial) - 7));
128 $points_arr = $this->extractPoints($point, $scale_data);
130 // draw a small circle to mark the point
131 if ($points_arr[0][0] != '' && $points_arr[0][1] != '') {
132 $pdf->Circle(
133 $points_arr[0][0], $points_arr[0][1], 2, 0, 360, 'D', $line
135 // print label if applicable
136 if (isset($label) && trim($label) != '') {
137 $pdf->SetXY($points_arr[0][0], $points_arr[0][1]);
138 $pdf->SetFontSize(5);
139 $pdf->Cell(0, 0, trim($label));
142 return $pdf;
146 * Prepares and returns the code related to a row in the GIS dataset as SVG.
148 * @param string $spatial GIS POINT object
149 * @param string $label Label for the GIS POINT object
150 * @param string $point_color Color for the GIS POINT object
151 * @param array $scale_data Array containing data related to scaling
153 * @return string the code related to a row in the GIS dataset
154 * @access public
156 public function prepareRowAsSvg($spatial, $label, $point_color, $scale_data)
158 $point_options = array(
159 'name' => $label,
160 'id' => $label . rand(),
161 'class' => 'point vector',
162 'fill' => 'white',
163 'stroke' => $point_color,
164 'stroke-width'=> 2,
167 // Trim to remove leading 'POINT(' and trailing ')'
168 $point = substr($spatial, 6, (strlen($spatial) - 7));
169 $points_arr = $this->extractPoints($point, $scale_data);
171 $row = '';
172 if ($points_arr[0][0] != '' && $points_arr[0][1] != '') {
173 $row .= '<circle cx="' . $points_arr[0][0]
174 . '" cy="' . $points_arr[0][1] . '" r="3"';
175 foreach ($point_options as $option => $val) {
176 $row .= ' ' . $option . '="' . trim($val) . '"';
178 $row .= '/>';
181 return $row;
185 * Prepares JavaScript related to a row in the GIS dataset
186 * to visualize it with OpenLayers.
188 * @param string $spatial GIS POINT object
189 * @param int $srid Spatial reference ID
190 * @param string $label Label for the GIS POINT object
191 * @param string $point_color Color for the GIS POINT object
192 * @param array $scale_data Array containing data related to scaling
194 * @return string JavaScript related to a row in the GIS dataset
195 * @access public
197 public function prepareRowAsOl($spatial, $srid, $label,
198 $point_color, $scale_data
200 $style_options = array(
201 'pointRadius' => 3,
202 'fillColor' => '#ffffff',
203 'strokeColor' => $point_color,
204 'strokeWidth' => 2,
205 'label' => $label,
206 'labelYOffset' => -8,
207 'fontSize' => 10,
209 if ($srid == 0) {
210 $srid = 4326;
212 $result = $this->getBoundsForOl($srid, $scale_data);
214 // Trim to remove leading 'POINT(' and trailing ')'
215 $point = substr($spatial, 6, (strlen($spatial) - 7));
216 $points_arr = $this->extractPoints($point, null);
218 if ($points_arr[0][0] != '' && $points_arr[0][1] != '') {
219 $result .= 'vectorLayer.addFeatures(new OpenLayers.Feature.Vector('
220 . $this->getPointForOpenLayers($points_arr[0], $srid). ', null, '
221 . json_encode($style_options) . '));';
223 return $result;
227 * Generate the WKT with the set of parameters passed by the GIS editor.
229 * @param array $gis_data GIS data
230 * @param int $index Index into the parameter object
231 * @param string $empty Point deos not adhere to this parameter
233 * @return string WKT with the set of parameters passed by the GIS editor
234 * @access public
236 public function generateWkt($gis_data, $index, $empty = '')
238 return 'POINT('
239 . ((isset($gis_data[$index]['POINT']['x'])
240 && trim($gis_data[$index]['POINT']['x']) != '')
241 ? $gis_data[$index]['POINT']['x'] : '')
242 . ' '
243 . ((isset($gis_data[$index]['POINT']['y'])
244 && trim($gis_data[$index]['POINT']['y']) != '')
245 ? $gis_data[$index]['POINT']['y'] : '') . ')';
249 * Generate the WKT for the data from ESRI shape files.
251 * @param array $row_data GIS data
253 * @return string the WKT for the data from ESRI shape files
254 * @access public
256 public function getShape($row_data)
258 return 'POINT(' . (isset($row_data['x']) ? $row_data['x'] : '')
259 . ' ' . (isset($row_data['y']) ? $row_data['y'] : '') . ')';
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 index $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'] = 'POINT';
281 $wkt = $value;
284 // Trim to remove leading 'POINT(' and trailing ')'
285 $point = substr($wkt, 6, (strlen($wkt) - 7));
286 $points_arr = $this->extractPoints($point, null);
288 $params[$index]['POINT']['x'] = $points_arr[0][0];
289 $params[$index]['POINT']['y'] = $points_arr[0][1];
291 return $params;