Translated using Weblate.
[phpmyadmin.git] / libraries / gis / pma_gis_multipoint.php
blob7b1285d2f85c400ce8f01328aaf3267254d711d8
1 <?php
2 /**
3 * Handles the visualization of GIS MULTIPOINT objects.
5 * @package PhpMyAdmin-GIS
6 */
7 class PMA_GIS_Multipoint 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 'MULTIPOINT(' and trailing ')'
44 $multipoint = substr($spatial, 11, (strlen($spatial) - 12));
45 return $this->setMinMax($multipoint, array());
48 /**
49 * Adds to the PNG image object, the data related to a row in the GIS dataset.
51 * @param string $spatial GIS MULTIPOINT object
52 * @param string $label Label for the GIS MULTIPOINT object
53 * @param string $point_color Color for the GIS MULTIPOINT 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 'MULTIPOINT(' and trailing ')'
69 $multipoint = substr($spatial, 11, (strlen($spatial) - 12));
70 $points_arr = $this->extractPoints($multipoint, $scale_data);
72 foreach ($points_arr as $point) {
73 // draw a small circle to mark the point
74 if ($point[0] != '' && $point[1] != '') {
75 imagearc($image, $point[0], $point[1], 7, 7, 0, 360, $color);
78 // print label for each point
79 if ((isset($label) && trim($label) != '')
80 && ($points_arr[0][0] != '' && $points_arr[0][1] != '')
81 ) {
82 imagestring($image, 1, $points_arr[0][0], $points_arr[0][1], trim($label), $black);
84 return $image;
87 /**
88 * Adds to the TCPDF instance, the data related to a row in the GIS dataset.
90 * @param string $spatial GIS MULTIPOINT object
91 * @param string $label Label for the GIS MULTIPOINT object
92 * @param string $point_color Color for the GIS MULTIPOINT object
93 * @param array $scale_data Array containing data related to scaling
94 * @param image $pdf TCPDF instance
96 * @return the modified TCPDF instance
98 public function prepareRowAsPdf($spatial, $label, $point_color, $scale_data, $pdf)
100 // allocate colors
101 $red = hexdec(substr($point_color, 1, 2));
102 $green = hexdec(substr($point_color, 3, 2));
103 $blue = hexdec(substr($point_color, 4, 2));
104 $line = array('width' => 1.25, 'color' => array($red, $green, $blue));
106 // Trim to remove leading 'MULTIPOINT(' and trailing ')'
107 $multipoint = substr($spatial, 11, (strlen($spatial) - 12));
108 $points_arr = $this->extractPoints($multipoint, $scale_data);
110 foreach ($points_arr as $point) {
111 // draw a small circle to mark the point
112 if ($point[0] != '' && $point[1] != '') {
113 $pdf->Circle($point[0], $point[1], 2, 0, 360, 'D', $line);
116 // print label for each point
117 if ((isset($label) && trim($label) != '')
118 && ($points_arr[0][0] != '' && $points_arr[0][1] != '')
120 $pdf->SetXY($points_arr[0][0], $points_arr[0][1]);
121 $pdf->SetFontSize(5);
122 $pdf->Cell(0, 0, trim($label));
124 return $pdf;
128 * Prepares and returns the code related to a row in the GIS dataset as SVG.
130 * @param string $spatial GIS MULTIPOINT object
131 * @param string $label Label for the GIS MULTIPOINT object
132 * @param string $point_color Color for the GIS MULTIPOINT object
133 * @param array $scale_data Array containing data related to scaling
135 * @return the code related to a row in the GIS dataset
137 public function prepareRowAsSvg($spatial, $label, $point_color, $scale_data)
139 $point_options = array(
140 'name' => $label,
141 'class' => 'multipoint vector',
142 'fill' => 'white',
143 'stroke' => $point_color,
144 'stroke-width'=> 2,
147 // Trim to remove leading 'MULTIPOINT(' and trailing ')'
148 $multipoint = substr($spatial, 11, (strlen($spatial) - 12));
149 $points_arr = $this->extractPoints($multipoint, $scale_data);
151 $row = '';
152 foreach ($points_arr as $point) {
153 if ($point[0] != '' && $point[1] != '') {
154 $row .= '<circle cx="' . $point[0] . '" cy="' . $point[1] . '" r="3"';
155 $point_options['id'] = $label . rand();
156 foreach ($point_options as $option => $val) {
157 $row .= ' ' . $option . '="' . trim($val) . '"';
159 $row .= '/>';
163 return $row;
167 * Prepares JavaScript related to a row in the GIS dataset
168 * to visualize it with OpenLayers.
170 * @param string $spatial GIS MULTIPOINT object
171 * @param int $srid Spatial reference ID
172 * @param string $label Label for the GIS MULTIPOINT object
173 * @param string $point_color Color for the GIS MULTIPOINT object
174 * @param array $scale_data Array containing data related to scaling
176 * @return JavaScript related to a row in the GIS dataset
178 public function prepareRowAsOl($spatial, $srid, $label, $point_color, $scale_data)
180 $style_options = array(
181 'pointRadius' => 3,
182 'fillColor' => '#ffffff',
183 'strokeColor' => $point_color,
184 'strokeWidth' => 2,
185 'label' => $label,
186 'labelYOffset' => -8,
187 'fontSize' => 10,
189 if ($srid == 0) {
190 $srid = 4326;
192 $result = $this->getBoundsForOl($srid, $scale_data);
194 // Trim to remove leading 'MULTIPOINT(' and trailing ')'
195 $multipoint = substr($spatial, 11, (strlen($spatial) - 12));
196 $points_arr = $this->extractPoints($multipoint, null);
198 $row = 'new Array(';
199 foreach ($points_arr as $point) {
200 if ($point[0] != '' && $point[1] != '') {
201 $row .= '(new OpenLayers.Geometry.Point(' . $point[0] . ', ' . $point[1]
202 . ')).transform(new OpenLayers.Projection("EPSG:' . $srid
203 . '"), map.getProjectionObject()), ';
206 if (substr($row, strlen($row) - 2) == ', ') {
207 $row = substr($row, 0, strlen($row) - 2);
209 $row .= ')';
211 $result .= 'vectorLayer.addFeatures(new OpenLayers.Feature.Vector('
212 . 'new OpenLayers.Geometry.MultiPoint(' . $row . '), null, '
213 . json_encode($style_options) . '));';
214 return $result;
218 * Generate the WKT with the set of parameters passed by the GIS editor.
220 * @param array $gis_data GIS data
221 * @param int $index Index into the parameter object
222 * @param string $empty Multipoint does not adhere to this
224 * @return WKT with the set of parameters passed by the GIS editor
226 public function generateWkt($gis_data, $index, $empty = '')
228 $no_of_points = isset($gis_data[$index]['MULTIPOINT']['no_of_points'])
229 ? $gis_data[$index]['MULTIPOINT']['no_of_points'] : 1;
230 if ($no_of_points < 1) {
231 $no_of_points = 1;
233 $wkt = 'MULTIPOINT(';
234 for ($i = 0; $i < $no_of_points; $i++) {
235 $wkt .= ((isset($gis_data[$index]['MULTIPOINT'][$i]['x'])
236 && trim($gis_data[$index]['MULTIPOINT'][$i]['x']) != '')
237 ? $gis_data[$index]['MULTIPOINT'][$i]['x'] : '')
238 . ' ' . ((isset($gis_data[$index]['MULTIPOINT'][$i]['y'])
239 && trim($gis_data[$index]['MULTIPOINT'][$i]['y']) != '')
240 ? $gis_data[$index]['MULTIPOINT'][$i]['y'] : '') . ',';
242 $wkt = substr($wkt, 0, strlen($wkt) - 1);
243 $wkt .= ')';
244 return $wkt;
248 * Generate the WKT for the data from ESRI shape files.
250 * @param array $row_data GIS data
252 * @return the WKT for the data from ESRI shape files
254 public function getShape($row_data)
256 $wkt = 'MULTIPOINT(';
257 for ($i = 0; $i < $row_data['numpoints']; $i++) {
258 $wkt .= $row_data['points'][$i]['x'] . ' ' . $row_data['points'][$i]['y'] . ',';
260 $wkt = substr($wkt, 0, strlen($wkt) - 1);
261 $wkt .= ')';
262 return $wkt;
266 * Generate parameters for the GIS data editor from the value of the GIS column.
268 * @param string $value of the GIS column
269 * @param index $index of the geometry
271 * @return parameters for the GIS data editor from the value of the GIS column
273 public function generateParams($value, $index = -1)
275 if ($index == -1) {
276 $index = 0;
277 $params = array();
278 $data = PMA_GIS_Geometry::generateParams($value);
279 $params['srid'] = $data['srid'];
280 $wkt = $data['wkt'];
281 } else {
282 $params[$index]['gis_type'] = 'MULTIPOINT';
283 $wkt = $value;
286 // Trim to remove leading 'MULTIPOINT(' and trailing ')'
287 $points = substr($wkt, 11, (strlen($wkt) - 12));
288 $points_arr = $this->extractPoints($points, null);
290 $no_of_points = count($points_arr);
291 $params[$index]['MULTIPOINT']['no_of_points'] = $no_of_points;
292 for ($i = 0; $i < $no_of_points; $i++) {
293 $params[$index]['MULTIPOINT'][$i]['x'] = $points_arr[$i][0];
294 $params[$index]['MULTIPOINT'][$i]['y'] = $points_arr[$i][1];
297 return $params;