3 * Handles the visualization of GIS GEOMETRYCOLLECTION objects.
5 * @package phpMyAdmin-GIS
7 class PMA_GIS_Geometrycollection
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)
45 // Trim to remove leading 'GEOMETRYCOLLECTION(' and trailing ')'
46 $goem_col = substr($spatial, 19, (strlen($spatial) - 20));
48 // Split the geometry collection object to get its constituents.
49 $sub_parts = $this->_explodeGeomCol($goem_col);
51 foreach ($sub_parts as $sub_part) {
52 $type_pos = stripos($sub_part, '(');
53 $type = substr($sub_part, 0, $type_pos);
55 $gis_obj = PMA_GIS_Factory
::factory($type);
59 $scale_data = $gis_obj->scaleRow($sub_part);
61 // Upadate minimum/maximum values for x and y cordinates.
62 $c_maxX = (float) $scale_data['maxX'];
63 if (! isset($min_max['maxX']) ||
$c_maxX > $min_max['maxX']) {
64 $min_max['maxX'] = $c_maxX;
67 $c_minX = (float) $scale_data['minX'];
68 if (! isset($min_max['minX']) ||
$c_minX < $min_max['minX']) {
69 $min_max['minX'] = $c_minX;
72 $c_maxY = (float) $scale_data['maxY'];
73 if (! isset($min_max['maxY']) ||
$c_maxY > $min_max['maxY']) {
74 $min_max['maxY'] = $c_maxY;
77 $c_minY = (float) $scale_data['minY'];
78 if (! isset($min_max['minY']) ||
$c_minY < $min_max['minY']) {
79 $min_max['minY'] = $c_minY;
86 * Adds to the PNG image object, the data related to a row in the GIS dataset.
88 * @param string $spatial GIS GEOMETRYCOLLECTION object
89 * @param string $label Label for the GIS GEOMETRYCOLLECTION object
90 * @param string $color Color for the GIS GEOMETRYCOLLECTION object
91 * @param array $scale_data Array containing data related to scaling
92 * @param image $image Image object
94 * @return the modified image object
96 public function prepareRowAsPng($spatial, $label, $color, $scale_data, $image)
98 // Trim to remove leading 'GEOMETRYCOLLECTION(' and trailing ')'
99 $goem_col = substr($spatial, 19, (strlen($spatial) - 20));
100 // Split the geometry collection object to get its constituents.
101 $sub_parts = $this->_explodeGeomCol($goem_col);
103 foreach ($sub_parts as $sub_part) {
104 $type_pos = stripos($sub_part, '(');
105 $type = substr($sub_part, 0, $type_pos);
107 $gis_obj = PMA_GIS_Factory
::factory($type);
111 $image = $gis_obj->prepareRowAsPng($sub_part, $label, $color, $scale_data, $image);
117 * Adds to the TCPDF instance, the data related to a row in the GIS dataset.
119 * @param string $spatial GIS GEOMETRYCOLLECTION object
120 * @param string $label Label for the GIS GEOMETRYCOLLECTION object
121 * @param string $color Color for the GIS GEOMETRYCOLLECTION object
122 * @param array $scale_data Array containing data related to scaling
123 * @param image $pdf TCPDF instance
125 * @return the modified TCPDF instance
127 public function prepareRowAsPdf($spatial, $label, $color, $scale_data, $pdf)
129 // Trim to remove leading 'GEOMETRYCOLLECTION(' and trailing ')'
130 $goem_col = substr($spatial, 19, (strlen($spatial) - 20));
131 // Split the geometry collection object to get its constituents.
132 $sub_parts = $this->_explodeGeomCol($goem_col);
134 foreach ($sub_parts as $sub_part) {
135 $type_pos = stripos($sub_part, '(');
136 $type = substr($sub_part, 0, $type_pos);
138 $gis_obj = PMA_GIS_Factory
::factory($type);
142 $pdf = $gis_obj->prepareRowAsPdf($sub_part, $label, $color, $scale_data, $pdf);
148 * Prepares and returns the code related to a row in the GIS dataset as SVG.
150 * @param string $spatial GIS GEOMETRYCOLLECTION object
151 * @param string $label Label for the GIS GEOMETRYCOLLECTION object
152 * @param string $color Color for the GIS GEOMETRYCOLLECTION object
153 * @param array $scale_data Array containing data related to scaling
155 * @return the code related to a row in the GIS dataset
157 public function prepareRowAsSvg($spatial, $label, $color, $scale_data)
161 // Trim to remove leading 'GEOMETRYCOLLECTION(' and trailing ')'
162 $goem_col = substr($spatial, 19, (strlen($spatial) - 20));
163 // Split the geometry collection object to get its constituents.
164 $sub_parts = $this->_explodeGeomCol($goem_col);
166 foreach ($sub_parts as $sub_part) {
167 $type_pos = stripos($sub_part, '(');
168 $type = substr($sub_part, 0, $type_pos);
170 $gis_obj = PMA_GIS_Factory
::factory($type);
174 $row .= $gis_obj->prepareRowAsSvg($sub_part, $label, $color, $scale_data);
180 * Prepares JavaScript related to a row in the GIS dataset
181 * to visualize it with OpenLayers.
183 * @param string $spatial GIS GEOMETRYCOLLECTION object
184 * @param int $srid Spatial reference ID
185 * @param string $label Label for the GIS GEOMETRYCOLLECTION object
186 * @param string $color Color for the GIS GEOMETRYCOLLECTION object
187 * @param array $scale_data Array containing data related to scaling
189 * @return JavaScript related to a row in the GIS dataset
191 public function prepareRowAsOl($spatial, $srid, $label, $color, $scale_data)
195 // Trim to remove leading 'GEOMETRYCOLLECTION(' and trailing ')'
196 $goem_col = substr($spatial, 19, (strlen($spatial) - 20));
197 // Split the geometry collection object to get its constituents.
198 $sub_parts = $this->_explodeGeomCol($goem_col);
200 foreach ($sub_parts as $sub_part) {
201 $type_pos = stripos($sub_part, '(');
202 $type = substr($sub_part, 0, $type_pos);
204 $gis_obj = PMA_GIS_Factory
::factory($type);
208 $row .= $gis_obj->prepareRowAsOl($sub_part, $srid, $label, $color, $scale_data);
214 * Split the GEOMETRYCOLLECTION object and get its constituents.
216 * @param string $goem_col Geometry collection string
218 * @return the constituents of the geometry collection object
220 private function _explodeGeomCol($goem_col)
222 $sub_parts = array();
226 foreach (str_split($goem_col) as $char) {
229 } elseif ($char == ')') {
231 if ($br_count == 0) {
232 $sub_parts[] = substr($goem_col, $start, ($count +
1 - $start));
242 * Generate the WKT with the set of parameters passed by the GIS editor.
244 * @param array $gis_data GIS data
245 * @param int $index Index into the parameter object
246 * @param string $empty Value for empty points
248 * @return WKT with the set of parameters passed by the GIS editor
250 public function generateWkt($gis_data, $index, $empty = '')
252 $geom_count = (isset($gis_data['GEOMETRYCOLLECTION']['geom_count']))
253 ?
$gis_data['GEOMETRYCOLLECTION']['geom_count'] : 1;
254 $wkt = 'GEOMETRYCOLLECTION(';
255 for ($i = 0; $i < $geom_count; $i++
) {
256 if (isset($gis_data[$i]['gis_type'])) {
257 $type = $gis_data[$i]['gis_type'];
258 $gis_obj = PMA_GIS_Factory
::factory($type);
262 $wkt .= $gis_obj->generateWkt($gis_data, $i, $empty) . ',';
265 if (isset($gis_data[0]['gis_type'])) {
266 $wkt = substr($wkt, 0, strlen($wkt) - 1);
272 /** Generate parameters for the GIS data editor from the value of the GIS column.
274 * @param string $value of the GIS column
275 * @param index $index of the geometry
277 * @return parameters for the GIS data editor from the value of the GIS column
279 public function generateParams($value)
282 $data = PMA_GIS_Geometry
::generateParams($value);
283 $params['srid'] = $data['srid'];
286 // Trim to remove leading 'GEOMETRYCOLLECTION(' and trailing ')'
287 $goem_col = substr($wkt, 19, (strlen($wkt) - 20));
288 // Split the geometry collection object to get its constituents.
289 $sub_parts = $this->_explodeGeomCol($goem_col);
290 $params['GEOMETRYCOLLECTION']['geom_count'] = count($sub_parts);
293 foreach ($sub_parts as $sub_part) {
294 $type_pos = stripos($sub_part, '(');
295 $type = substr($sub_part, 0, $type_pos);
297 $gis_obj = PMA_GIS_Factory
::factory($type);
301 $params = array_merge($params, $gis_obj->generateParams($sub_part, $i));