2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Handles actions related to GIS GEOMETRYCOLLECTION objects
6 * @package PhpMyAdmin-GIS
9 if (! defined('PHPMYADMIN')) {
14 * Handles actions related to GIS GEOMETRYCOLLECTION objects
16 * @package PhpMyAdmin-GIS
18 class PMA_GIS_Geometrycollection
extends PMA_GIS_Geometry
20 // Hold the singleton instance of the class
21 private static $_instance;
24 * A private constructor; prevents direct creation of object.
28 private function __construct()
33 * Returns the singleton.
35 * @return PMA_GIS_Geometrycollection the singleton
38 public static function singleton()
40 if (!isset(self
::$_instance)) {
42 self
::$_instance = new $class;
45 return self
::$_instance;
51 * @param string $spatial spatial data of a row
53 * @return array array containing the min, max values for x and y coordinates
56 public function scaleRow($spatial)
60 // Trim to remove leading 'GEOMETRYCOLLECTION(' and trailing ')'
61 $goem_col = /*overload*/mb_substr(
64 /*overload*/mb_strlen($spatial) - 20
67 // Split the geometry collection object to get its constituents.
68 $sub_parts = $this->_explodeGeomCol($goem_col);
70 foreach ($sub_parts as $sub_part) {
71 $type_pos = /*overload*/mb_stripos($sub_part, '(');
72 $type = /*overload*/mb_substr($sub_part, 0, $type_pos);
74 $gis_obj = PMA_GIS_Factory
::factory($type);
78 $scale_data = $gis_obj->scaleRow($sub_part);
80 // Update minimum/maximum values for x and y coordinates.
81 $c_maxX = (float) $scale_data['maxX'];
82 if (! isset($min_max['maxX']) ||
$c_maxX > $min_max['maxX']) {
83 $min_max['maxX'] = $c_maxX;
86 $c_minX = (float) $scale_data['minX'];
87 if (! isset($min_max['minX']) ||
$c_minX < $min_max['minX']) {
88 $min_max['minX'] = $c_minX;
91 $c_maxY = (float) $scale_data['maxY'];
92 if (! isset($min_max['maxY']) ||
$c_maxY > $min_max['maxY']) {
93 $min_max['maxY'] = $c_maxY;
96 $c_minY = (float) $scale_data['minY'];
97 if (! isset($min_max['minY']) ||
$c_minY < $min_max['minY']) {
98 $min_max['minY'] = $c_minY;
105 * Adds to the PNG image object, the data related to a row in the GIS dataset.
107 * @param string $spatial GIS GEOMETRYCOLLECTION object
108 * @param string $label label for the GIS GEOMETRYCOLLECTION object
109 * @param string $color color for the GIS GEOMETRYCOLLECTION object
110 * @param array $scale_data array containing data related to scaling
111 * @param object $image image object
113 * @return resource the modified image object
116 public function prepareRowAsPng($spatial, $label, $color, $scale_data, $image)
118 // Trim to remove leading 'GEOMETRYCOLLECTION(' and trailing ')'
119 $goem_col = /*overload*/mb_substr(
122 /*overload*/mb_strlen($spatial) - 20
124 // Split the geometry collection object to get its constituents.
125 $sub_parts = $this->_explodeGeomCol($goem_col);
127 foreach ($sub_parts as $sub_part) {
128 $type_pos = /*overload*/mb_stripos($sub_part, '(');
129 $type = /*overload*/mb_substr($sub_part, 0, $type_pos);
131 $gis_obj = PMA_GIS_Factory
::factory($type);
135 $image = $gis_obj->prepareRowAsPng(
136 $sub_part, $label, $color, $scale_data, $image
143 * Adds to the TCPDF instance, the data related to a row in the GIS dataset.
145 * @param string $spatial GIS GEOMETRYCOLLECTION object
146 * @param string $label label for the GIS GEOMETRYCOLLECTION object
147 * @param string $color color for the GIS GEOMETRYCOLLECTION object
148 * @param array $scale_data array containing data related to scaling
149 * @param TCPDF $pdf TCPDF instance
151 * @return TCPDF the modified TCPDF instance
154 public function prepareRowAsPdf($spatial, $label, $color, $scale_data, $pdf)
156 // Trim to remove leading 'GEOMETRYCOLLECTION(' and trailing ')'
157 $goem_col = /*overload*/mb_substr(
160 /*overload*/mb_strlen($spatial) - 20
162 // Split the geometry collection object to get its constituents.
163 $sub_parts = $this->_explodeGeomCol($goem_col);
165 foreach ($sub_parts as $sub_part) {
166 $type_pos = /*overload*/mb_stripos($sub_part, '(');
167 $type = /*overload*/mb_substr($sub_part, 0, $type_pos);
169 $gis_obj = PMA_GIS_Factory
::factory($type);
173 $pdf = $gis_obj->prepareRowAsPdf(
174 $sub_part, $label, $color, $scale_data, $pdf
181 * Prepares and returns the code related to a row in the GIS dataset as SVG.
183 * @param string $spatial GIS GEOMETRYCOLLECTION object
184 * @param string $label label for the GIS GEOMETRYCOLLECTION object
185 * @param string $color color for the GIS GEOMETRYCOLLECTION object
186 * @param array $scale_data array containing data related to scaling
188 * @return string the code related to a row in the GIS dataset
191 public function prepareRowAsSvg($spatial, $label, $color, $scale_data)
195 // Trim to remove leading 'GEOMETRYCOLLECTION(' and trailing ')'
196 $goem_col = /*overload*/mb_substr(
199 /*overload*/mb_strlen($spatial) - 20
201 // Split the geometry collection object to get its constituents.
202 $sub_parts = $this->_explodeGeomCol($goem_col);
204 foreach ($sub_parts as $sub_part) {
205 $type_pos = /*overload*/mb_stripos($sub_part, '(');
206 $type = /*overload*/mb_substr($sub_part, 0, $type_pos);
208 $gis_obj = PMA_GIS_Factory
::factory($type);
212 $row .= $gis_obj->prepareRowAsSvg(
213 $sub_part, $label, $color, $scale_data
220 * Prepares JavaScript related to a row in the GIS dataset
221 * to visualize it with OpenLayers.
223 * @param string $spatial GIS GEOMETRYCOLLECTION object
224 * @param int $srid spatial reference ID
225 * @param string $label label for the GIS GEOMETRYCOLLECTION object
226 * @param string $color color for the GIS GEOMETRYCOLLECTION object
227 * @param array $scale_data array containing data related to scaling
229 * @return string JavaScript related to a row in the GIS dataset
232 public function prepareRowAsOl($spatial, $srid, $label, $color, $scale_data)
236 // Trim to remove leading 'GEOMETRYCOLLECTION(' and trailing ')'
237 $goem_col = /*overload*/mb_substr(
240 /*overload*/mb_strlen($spatial) - 20
242 // Split the geometry collection object to get its constituents.
243 $sub_parts = $this->_explodeGeomCol($goem_col);
245 foreach ($sub_parts as $sub_part) {
246 $type_pos = /*overload*/mb_stripos($sub_part, '(');
247 $type = /*overload*/mb_substr($sub_part, 0, $type_pos);
249 $gis_obj = PMA_GIS_Factory
::factory($type);
253 $row .= $gis_obj->prepareRowAsOl(
254 $sub_part, $srid, $label, $color, $scale_data
261 * Splits the GEOMETRYCOLLECTION object and get its constituents.
263 * @param string $geom_col geometry collection string
265 * @return array the constituents of the geometry collection object
268 private function _explodeGeomCol($geom_col)
270 $sub_parts = array();
274 foreach (str_split($geom_col) as $char) {
277 } elseif ($char == ')') {
279 if ($br_count == 0) {
280 $sub_parts[] = /*overload*/mb_substr(
283 ($count +
1 - $start)
294 * Generates the WKT with the set of parameters passed by the GIS editor.
296 * @param array $gis_data GIS data
297 * @param int $index index into the parameter object
298 * @param string $empty value for empty points
300 * @return string WKT with the set of parameters passed by the GIS editor
303 public function generateWkt($gis_data, $index, $empty = '')
305 $geom_count = (isset($gis_data['GEOMETRYCOLLECTION']['geom_count']))
306 ?
$gis_data['GEOMETRYCOLLECTION']['geom_count'] : 1;
307 $wkt = 'GEOMETRYCOLLECTION(';
308 for ($i = 0; $i < $geom_count; $i++
) {
309 if (isset($gis_data[$i]['gis_type'])) {
310 $type = $gis_data[$i]['gis_type'];
311 $gis_obj = PMA_GIS_Factory
::factory($type);
315 $wkt .= $gis_obj->generateWkt($gis_data, $i, $empty) . ',';
318 if (isset($gis_data[0]['gis_type'])) {
319 $wkt = /*overload*/mb_substr($wkt, 0, /*overload*/mb_strlen($wkt) - 1);
326 * Generates parameters for the GIS data editor from the value of the GIS column.
328 * @param string $value of the GIS column
330 * @return array parameters for the GIS editor from the value of the GIS column
333 public function generateParams($value)
336 $data = PMA_GIS_Geometry
::generateParams($value);
337 $params['srid'] = $data['srid'];
340 // Trim to remove leading 'GEOMETRYCOLLECTION(' and trailing ')'
341 $goem_col = /*overload*/mb_substr(
344 /*overload*/mb_strlen($wkt) - 20
346 // Split the geometry collection object to get its constituents.
347 $sub_parts = $this->_explodeGeomCol($goem_col);
348 $params['GEOMETRYCOLLECTION']['geom_count'] = count($sub_parts);
351 foreach ($sub_parts as $sub_part) {
352 $type_pos = /*overload*/mb_stripos($sub_part, '(');
353 $type = /*overload*/mb_substr($sub_part, 0, $type_pos);
354 $gis_obj = PMA_GIS_Factory
::factory($type);
358 $params = array_merge($params, $gis_obj->generateParams($sub_part, $i));