|
7 | 7 |
|
8 | 8 | namespace PhpMyAdmin\Gis; |
9 | 9 |
|
| 10 | +use ErrorException; |
10 | 11 | use PhpMyAdmin\Image\ImageWrapper; |
11 | 12 | use TCPDF; |
12 | 13 |
|
13 | | -use function array_merge; |
14 | 14 | use function count; |
15 | 15 | use function mb_strpos; |
16 | 16 | use function mb_substr; |
17 | 17 | use function str_split; |
| 18 | +use function strtoupper; |
18 | 19 |
|
19 | 20 | /** |
20 | 21 | * Handles actions related to GIS GEOMETRYCOLLECTION objects |
@@ -299,44 +300,55 @@ public function generateWkt(array $gis_data, $index, $empty = ''): string |
299 | 300 | return $wkt . ')'; |
300 | 301 | } |
301 | 302 |
|
| 303 | + /** |
| 304 | + * GeometryCollection does not have coordinates of its own |
| 305 | + * |
| 306 | + * @param string $wkt Value of the GIS column |
| 307 | + */ |
| 308 | + protected function getCoordinateParams(string $wkt): array |
| 309 | + { |
| 310 | + throw new ErrorException('Has no own coordinates'); |
| 311 | + } |
| 312 | + |
302 | 313 | /** |
303 | 314 | * Generates parameters for the GIS data editor from the value of the GIS column. |
304 | 315 | * |
305 | 316 | * @param string $value of the GIS column |
306 | 317 | * |
307 | 318 | * @return array parameters for the GIS editor from the value of the GIS column |
308 | 319 | */ |
309 | | - public function generateParams($value): array |
| 320 | + public function generateParams(string $value): array |
310 | 321 | { |
311 | | - $params = []; |
312 | | - $data = GisGeometry::generateParams($value); |
313 | | - $params['srid'] = $data['srid']; |
| 322 | + $data = $this->parseWktAndSrid($value); |
314 | 323 | $wkt = $data['wkt']; |
315 | 324 |
|
316 | 325 | // Trim to remove leading 'GEOMETRYCOLLECTION(' and trailing ')' |
317 | 326 | $goem_col = mb_substr($wkt, 19, -1); |
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); |
| 327 | + $wkt_geometries = $this->explodeGeomCol($goem_col); |
| 328 | + $params = [ |
| 329 | + 'srid' => $data['srid'], |
| 330 | + 'GEOMETRYCOLLECTION' => [ |
| 331 | + 'geom_count' => count($wkt_geometries), |
| 332 | + ], |
| 333 | + ]; |
321 | 334 |
|
322 | 335 | $i = 0; |
323 | | - foreach ($sub_parts as $sub_part) { |
324 | | - $type_pos = mb_strpos($sub_part, '('); |
| 336 | + foreach ($wkt_geometries as $wkt_geometry) { |
| 337 | + $type_pos = mb_strpos($wkt_geometry, '('); |
325 | 338 | if ($type_pos === false) { |
326 | 339 | continue; |
327 | 340 | } |
328 | 341 |
|
329 | | - $type = mb_substr($sub_part, 0, $type_pos); |
330 | | - /** |
331 | | - * @var GisMultiPolygon|GisPolygon|GisMultiPoint|GisPoint|GisMultiLineString|GisLineString $gis_obj |
332 | | - */ |
333 | | - $gis_obj = GisFactory::factory($type); |
| 342 | + $wkt_type = strtoupper(mb_substr($wkt_geometry, 0, $type_pos)); |
| 343 | + $gis_obj = GisFactory::factory($wkt_type); |
334 | 344 | if (! $gis_obj) { |
335 | 345 | continue; |
336 | 346 | } |
337 | 347 |
|
338 | | - $params = array_merge($params, $gis_obj->generateParams($sub_part, $i)); |
339 | | - $i++; |
| 348 | + $params[$i++] = [ |
| 349 | + 'gis_type' => $wkt_type, |
| 350 | + $wkt_type => $gis_obj->getCoordinateParams($wkt_geometry), |
| 351 | + ]; |
340 | 352 | } |
341 | 353 |
|
342 | 354 | return $params; |
|
0 commit comments