3 * Handles the visualization of GIS POINT objects.
5 * @package phpMyAdmin-GIS
7 class PMA_GIS_Point
extends PMA_GIS_Geometry
9 // Hold the singleton instance of the class
10 private static $_instance;
13 * A private constructor; prevents direct creation of object.
15 private function __construct()
20 * Returns the singleton.
22 * @return the singleton
24 public static function singleton()
26 if (!isset(self
::$_instance)) {
28 self
::$_instance = new $class;
31 return self
::$_instance;
37 * @param string $spatial spatial data of a row
39 * @return array containing the min, max values for x and y cordinates
41 public function scaleRow($spatial)
43 // Trim to remove leading 'POINT(' and trailing ')'
44 $point = substr($spatial, 6, (strlen($spatial) - 7));
45 return $this->setMinMax($point, array());
49 * Adds to the PNG image object, the data related to a row in the GIS dataset.
51 * @param string $spatial GIS POINT object
52 * @param string $label Label for the GIS POINT object
53 * @param string $point_color Color for the GIS POINT object
54 * @param array $scale_data Array containing data related to scaling
55 * @param image $image Image object
57 * @return the modified image object
59 public function prepareRowAsPng($spatial, $label, $point_color, $scale_data, $image)
62 $black = imagecolorallocate($image, 0, 0, 0);
63 $red = hexdec(substr($point_color, 1, 2));
64 $green = hexdec(substr($point_color, 3, 2));
65 $blue = hexdec(substr($point_color, 4, 2));
66 $color = imagecolorallocate($image, $red, $green, $blue);
68 // Trim to remove leading 'POINT(' and trailing ')'
69 $point = substr($spatial, 6, (strlen($spatial) - 7));
70 $points_arr = $this->extractPoints($point, $scale_data);
72 // draw a small circle to mark the point
73 if ($points_arr[0][0] != '' && $points_arr[0][1] != '') {
74 imagearc($image, $points_arr[0][0], $points_arr[0][1], 7, 7, 0, 360, $color);
75 // print label if applicable
76 if (isset($label) && trim($label) != '') {
77 imagestring($image, 1, $points_arr[0][0], $points_arr[0][1], trim($label), $black);
84 * Adds to the TCPDF instance, the data related to a row in the GIS dataset.
86 * @param string $spatial GIS POINT object
87 * @param string $label Label for the GIS POINT object
88 * @param string $point_color Color for the GIS POINT object
89 * @param array $scale_data Array containing data related to scaling
90 * @param image $pdf TCPDF instance
92 * @return the modified TCPDF instance
94 public function prepareRowAsPdf($spatial, $label, $point_color, $scale_data, $pdf)
97 $red = hexdec(substr($point_color, 1, 2));
98 $green = hexdec(substr($point_color, 3, 2));
99 $blue = hexdec(substr($point_color, 4, 2));
100 $line = array('width' => 1.25, 'color' => array($red, $green, $blue));
102 // Trim to remove leading 'POINT(' and trailing ')'
103 $point = substr($spatial, 6, (strlen($spatial) - 7));
104 $points_arr = $this->extractPoints($point, $scale_data);
106 // draw a small circle to mark the point
107 if ($points_arr[0][0] != '' && $points_arr[0][1] != '') {
108 $pdf->Circle($points_arr[0][0], $points_arr[0][1], 2, 0, 360, 'D', $line);
109 // print label if applicable
110 if (isset($label) && trim($label) != '') {
111 $pdf->SetXY($points_arr[0][0], $points_arr[0][1]);
112 $pdf->SetFontSize(5);
113 $pdf->Cell(0, 0, trim($label));
120 * Prepares and returns the code related to a row in the GIS dataset as SVG.
122 * @param string $spatial GIS POINT object
123 * @param string $label Label for the GIS POINT object
124 * @param string $point_color Color for the GIS POINT object
125 * @param array $scale_data Array containing data related to scaling
127 * @return the code related to a row in the GIS dataset
129 public function prepareRowAsSvg($spatial, $label, $point_color, $scale_data)
131 $point_options = array(
133 'id' => $label . rand(),
134 'class' => 'point vector',
136 'stroke' => $point_color,
140 // Trim to remove leading 'POINT(' and trailing ')'
141 $point = substr($spatial, 6, (strlen($spatial) - 7));
142 $points_arr = $this->extractPoints($point, $scale_data);
145 if ($points_arr[0][0] != '' && $points_arr[0][1] != '') {
146 $row .= '<circle cx="' . $points_arr[0][0] . '" cy="' . $points_arr[0][1] . '" r="3"';
147 foreach ($point_options as $option => $val) {
148 $row .= ' ' . $option . '="' . trim($val) . '"';
157 * Prepares JavaScript related to a row in the GIS dataset
158 * to visualize it with OpenLayers.
160 * @param string $spatial GIS POINT object
161 * @param int $srid Spatial reference ID
162 * @param string $label Label for the GIS POINT object
163 * @param string $point_color Color for the GIS POINT object
164 * @param array $scale_data Array containing data related to scaling
166 * @return JavaScript related to a row in the GIS dataset
168 public function prepareRowAsOl($spatial, $srid, $label, $point_color, $scale_data)
170 $style_options = array(
172 'fillColor' => '#ffffff',
173 'strokeColor' => $point_color,
176 'labelYOffset' => -8,
182 $result = $this->getBoundsForOl($srid, $scale_data);
184 // Trim to remove leading 'POINT(' and trailing ')'
185 $point = substr($spatial, 6, (strlen($spatial) - 7));
186 $points_arr = $this->extractPoints($point, null);
188 if ($points_arr[0][0] != '' && $points_arr[0][1] != '') {
189 $result .= 'vectorLayer.addFeatures(new OpenLayers.Feature.Vector(('
190 . 'new OpenLayers.Geometry.Point(' . $points_arr[0][0] . ', '
191 . $points_arr[0][1] . ').transform(new OpenLayers.Projection("EPSG:'
192 . $srid . '"), map.getProjectionObject())), null, '
193 . json_encode($style_options) . '));';
199 * Generate the WKT with the set of parameters passed by the GIS editor.
201 * @param array $gis_data GIS data
202 * @param int $index Index into the parameter object
203 * @param string $empty Point deos not adhere to this parameter
205 * @return WKT with the set of parameters passed by the GIS editor
207 public function generateWkt($gis_data, $index, $empty = '')
210 . ((isset($gis_data[$index]['POINT']['x']) && trim($gis_data[$index]['POINT']['x']) != '')
211 ?
$gis_data[$index]['POINT']['x'] : '') . ' '
212 . ((isset($gis_data[$index]['POINT']['y']) && trim($gis_data[$index]['POINT']['y']) != '')
213 ?
$gis_data[$index]['POINT']['y'] : '') . ')';
217 * Generate the WKT for the data from ESRI shape files.
219 * @param array $row_data GIS data
221 * @return the WKT for the data from ESRI shape files
223 public function getShape($row_data)
225 return 'POINT(' . (isset($row_data['x']) ?
$row_data['x'] : '')
226 . ' ' . (isset($row_data['y']) ?
$row_data['y'] : '') . ')';
230 * Generate parameters for the GIS data editor from the value of the GIS column.
232 * @param string $value of the GIS column
233 * @param index $index of the geometry
235 * @return parameters for the GIS data editor from the value of the GIS column
237 public function generateParams($value, $index = -1)
242 $data = PMA_GIS_Geometry
::generateParams($value);
243 $params['srid'] = $data['srid'];
246 $params[$index]['gis_type'] = 'POINT';
250 // Trim to remove leading 'POINT(' and trailing ')'
251 $point = substr($wkt, 6, (strlen($wkt) - 7));
252 $points_arr = $this->extractPoints($point, null);
254 $params[$index]['POINT']['x'] = $points_arr[0][0];
255 $params[$index]['POINT']['y'] = $points_arr[0][1];