Translated using Weblate.
[phpmyadmin.git] / libraries / gis / pma_gis_point.php
blobf32cb4a3fda582c99001fd9e5bdde6f552659525
1 <?php
2 /**
3 * Handles the visualization of GIS POINT objects.
5 * @package PhpMyAdmin-GIS
6 */
7 class PMA_GIS_Point extends PMA_GIS_Geometry
9 // Hold the singleton instance of the class
10 private static $_instance;
12 /**
13 * A private constructor; prevents direct creation of object.
15 private function __construct()
19 /**
20 * Returns the singleton.
22 * @return the singleton
24 public static function singleton()
26 if (!isset(self::$_instance)) {
27 $class = __CLASS__;
28 self::$_instance = new $class;
31 return self::$_instance;
34 /**
35 * Scales each row.
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());
48 /**
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)
61 // allocate colors
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);
80 return $image;
83 /**
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)
96 // allocate colors
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));
116 return $pdf;
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(
132 'name' => $label,
133 'id' => $label . rand(),
134 'class' => 'point vector',
135 'fill' => 'white',
136 'stroke' => $point_color,
137 'stroke-width'=> 2,
140 // Trim to remove leading 'POINT(' and trailing ')'
141 $point = substr($spatial, 6, (strlen($spatial) - 7));
142 $points_arr = $this->extractPoints($point, $scale_data);
144 $row = '';
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) . '"';
150 $row .= '/>';
153 return $row;
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(
171 'pointRadius' => 3,
172 'fillColor' => '#ffffff',
173 'strokeColor' => $point_color,
174 'strokeWidth' => 2,
175 'label' => $label,
176 'labelYOffset' => -8,
177 'fontSize' => 10,
179 if ($srid == 0) {
180 $srid = 4326;
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) . '));';
195 return $result;
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 = '')
209 return 'POINT('
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)
239 if ($index == -1) {
240 $index = 0;
241 $params = array();
242 $data = PMA_GIS_Geometry::generateParams($value);
243 $params['srid'] = $data['srid'];
244 $wkt = $data['wkt'];
245 } else {
246 $params[$index]['gis_type'] = 'POINT';
247 $wkt = $value;
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];
257 return $params;