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 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 cordinates
56 public function scaleRow($spatial)
60 // Trim to remove leading 'GEOMETRYCOLLECTION(' and trailing ')'
61 $goem_col = substr($spatial, 19, (strlen($spatial) - 20));
63 // Split the geometry collection object to get its constituents.
64 $sub_parts = $this->_explodeGeomCol($goem_col);
66 foreach ($sub_parts as $sub_part) {
67 $type_pos = stripos($sub_part, '(');
68 $type = substr($sub_part, 0, $type_pos);
70 $gis_obj = PMA_GIS_Factory
::factory($type);
74 $scale_data = $gis_obj->scaleRow($sub_part);
76 // Upadate minimum/maximum values for x and y cordinates.
77 $c_maxX = (float) $scale_data['maxX'];
78 if (! isset($min_max['maxX']) ||
$c_maxX > $min_max['maxX']) {
79 $min_max['maxX'] = $c_maxX;
82 $c_minX = (float) $scale_data['minX'];
83 if (! isset($min_max['minX']) ||
$c_minX < $min_max['minX']) {
84 $min_max['minX'] = $c_minX;
87 $c_maxY = (float) $scale_data['maxY'];
88 if (! isset($min_max['maxY']) ||
$c_maxY > $min_max['maxY']) {
89 $min_max['maxY'] = $c_maxY;
92 $c_minY = (float) $scale_data['minY'];
93 if (! isset($min_max['minY']) ||
$c_minY < $min_max['minY']) {
94 $min_max['minY'] = $c_minY;
101 * Adds to the PNG image object, the data related to a row in the GIS dataset.
103 * @param string $spatial GIS GEOMETRYCOLLECTION object
104 * @param string $label label for the GIS GEOMETRYCOLLECTION object
105 * @param string $color color for the GIS GEOMETRYCOLLECTION object
106 * @param array $scale_data array containing data related to scaling
107 * @param object $image image object
109 * @return object the modified image object
112 public function prepareRowAsPng($spatial, $label, $color, $scale_data, $image)
114 // Trim to remove leading 'GEOMETRYCOLLECTION(' and trailing ')'
115 $goem_col = substr($spatial, 19, (strlen($spatial) - 20));
116 // Split the geometry collection object to get its constituents.
117 $sub_parts = $this->_explodeGeomCol($goem_col);
119 foreach ($sub_parts as $sub_part) {
120 $type_pos = stripos($sub_part, '(');
121 $type = substr($sub_part, 0, $type_pos);
123 $gis_obj = PMA_GIS_Factory
::factory($type);
127 $image = $gis_obj->prepareRowAsPng(
128 $sub_part, $label, $color, $scale_data, $image
135 * Adds to the TCPDF instance, the data related to a row in the GIS dataset.
137 * @param string $spatial GIS GEOMETRYCOLLECTION object
138 * @param string $label label for the GIS GEOMETRYCOLLECTION object
139 * @param string $color color for the GIS GEOMETRYCOLLECTION object
140 * @param array $scale_data array containing data related to scaling
141 * @param object $pdf TCPDF instance
143 * @return object the modified TCPDF instance
146 public function prepareRowAsPdf($spatial, $label, $color, $scale_data, $pdf)
148 // Trim to remove leading 'GEOMETRYCOLLECTION(' and trailing ')'
149 $goem_col = substr($spatial, 19, (strlen($spatial) - 20));
150 // Split the geometry collection object to get its constituents.
151 $sub_parts = $this->_explodeGeomCol($goem_col);
153 foreach ($sub_parts as $sub_part) {
154 $type_pos = stripos($sub_part, '(');
155 $type = substr($sub_part, 0, $type_pos);
157 $gis_obj = PMA_GIS_Factory
::factory($type);
161 $pdf = $gis_obj->prepareRowAsPdf(
162 $sub_part, $label, $color, $scale_data, $pdf
169 * Prepares and returns the code related to a row in the GIS dataset as SVG.
171 * @param string $spatial GIS GEOMETRYCOLLECTION object
172 * @param string $label label for the GIS GEOMETRYCOLLECTION object
173 * @param string $color color for the GIS GEOMETRYCOLLECTION object
174 * @param array $scale_data array containing data related to scaling
176 * @return string the code related to a row in the GIS dataset
179 public function prepareRowAsSvg($spatial, $label, $color, $scale_data)
183 // Trim to remove leading 'GEOMETRYCOLLECTION(' and trailing ')'
184 $goem_col = substr($spatial, 19, (strlen($spatial) - 20));
185 // Split the geometry collection object to get its constituents.
186 $sub_parts = $this->_explodeGeomCol($goem_col);
188 foreach ($sub_parts as $sub_part) {
189 $type_pos = stripos($sub_part, '(');
190 $type = substr($sub_part, 0, $type_pos);
192 $gis_obj = PMA_GIS_Factory
::factory($type);
196 $row .= $gis_obj->prepareRowAsSvg(
197 $sub_part, $label, $color, $scale_data
204 * Prepares JavaScript related to a row in the GIS dataset
205 * to visualize it with OpenLayers.
207 * @param string $spatial GIS GEOMETRYCOLLECTION object
208 * @param int $srid spatial reference ID
209 * @param string $label label for the GIS GEOMETRYCOLLECTION object
210 * @param string $color color for the GIS GEOMETRYCOLLECTION object
211 * @param array $scale_data array containing data related to scaling
213 * @return string JavaScript related to a row in the GIS dataset
216 public function prepareRowAsOl($spatial, $srid, $label, $color, $scale_data)
220 // Trim to remove leading 'GEOMETRYCOLLECTION(' and trailing ')'
221 $goem_col = substr($spatial, 19, (strlen($spatial) - 20));
222 // Split the geometry collection object to get its constituents.
223 $sub_parts = $this->_explodeGeomCol($goem_col);
225 foreach ($sub_parts as $sub_part) {
226 $type_pos = stripos($sub_part, '(');
227 $type = substr($sub_part, 0, $type_pos);
229 $gis_obj = PMA_GIS_Factory
::factory($type);
233 $row .= $gis_obj->prepareRowAsOl(
234 $sub_part, $srid, $label, $color, $scale_data
241 * Splits the GEOMETRYCOLLECTION object and get its constituents.
243 * @param string $goem_col geometry collection string
245 * @return array the constituents of the geometry collection object
248 private function _explodeGeomCol($goem_col)
250 $sub_parts = array();
254 foreach (str_split($goem_col) as $char) {
257 } elseif ($char == ')') {
259 if ($br_count == 0) {
260 $sub_parts[] = substr($goem_col, $start, ($count +
1 - $start));
270 * Generates the WKT with the set of parameters passed by the GIS editor.
272 * @param array $gis_data GIS data
273 * @param int $index index into the parameter object
274 * @param string $empty value for empty points
276 * @return string WKT with the set of parameters passed by the GIS editor
279 public function generateWkt($gis_data, $index, $empty = '')
281 $geom_count = (isset($gis_data['GEOMETRYCOLLECTION']['geom_count']))
282 ?
$gis_data['GEOMETRYCOLLECTION']['geom_count'] : 1;
283 $wkt = 'GEOMETRYCOLLECTION(';
284 for ($i = 0; $i < $geom_count; $i++
) {
285 if (isset($gis_data[$i]['gis_type'])) {
286 $type = $gis_data[$i]['gis_type'];
287 $gis_obj = PMA_GIS_Factory
::factory($type);
291 $wkt .= $gis_obj->generateWkt($gis_data, $i, $empty) . ',';
294 if (isset($gis_data[0]['gis_type'])) {
295 $wkt = substr($wkt, 0, strlen($wkt) - 1);
302 * Generates parameters for the GIS data editor from the value of the GIS column.
304 * @param string $value of the GIS column
306 * @return array parameters for the GIS editor from the value of the GIS column
309 public function generateParams($value)
312 $data = PMA_GIS_Geometry
::generateParams($value);
313 $params['srid'] = $data['srid'];
316 // Trim to remove leading 'GEOMETRYCOLLECTION(' and trailing ')'
317 $goem_col = substr($wkt, 19, (strlen($wkt) - 20));
318 // Split the geometry collection object to get its constituents.
319 $sub_parts = $this->_explodeGeomCol($goem_col);
320 $params['GEOMETRYCOLLECTION']['geom_count'] = count($sub_parts);
323 foreach ($sub_parts as $sub_part) {
324 $type_pos = stripos($sub_part, '(');
325 $type = substr($sub_part, 0, $type_pos);
326 $gis_obj = PMA_GIS_Factory
::factory($type);
330 $params = array_merge($params, $gis_obj->generateParams($sub_part, $i));