aboutsummaryrefslogtreecommitdiff
path: root/srcs/phpmyadmin/libraries/classes/Gis
diff options
context:
space:
mode:
Diffstat (limited to 'srcs/phpmyadmin/libraries/classes/Gis')
-rw-r--r--srcs/phpmyadmin/libraries/classes/Gis/GisFactory.php50
-rw-r--r--srcs/phpmyadmin/libraries/classes/Gis/GisGeometry.php407
-rw-r--r--srcs/phpmyadmin/libraries/classes/Gis/GisGeometryCollection.php419
-rw-r--r--srcs/phpmyadmin/libraries/classes/Gis/GisLineString.php360
-rw-r--r--srcs/phpmyadmin/libraries/classes/Gis/GisMultiLineString.php449
-rw-r--r--srcs/phpmyadmin/libraries/classes/Gis/GisMultiPoint.php416
-rw-r--r--srcs/phpmyadmin/libraries/classes/Gis/GisMultiPolygon.php617
-rw-r--r--srcs/phpmyadmin/libraries/classes/Gis/GisPoint.php363
-rw-r--r--srcs/phpmyadmin/libraries/classes/Gis/GisPolygon.php618
-rw-r--r--srcs/phpmyadmin/libraries/classes/Gis/GisVisualization.php726
10 files changed, 4425 insertions, 0 deletions
diff --git a/srcs/phpmyadmin/libraries/classes/Gis/GisFactory.php b/srcs/phpmyadmin/libraries/classes/Gis/GisFactory.php
new file mode 100644
index 0000000..353d7e6
--- /dev/null
+++ b/srcs/phpmyadmin/libraries/classes/Gis/GisFactory.php
@@ -0,0 +1,50 @@
+<?php
+/* vim: set expandtab sw=4 ts=4 sts=4: */
+/**
+ * Contains the factory class that handles the creation of geometric objects
+ *
+ * @package PhpMyAdmin-GIS
+ */
+declare(strict_types=1);
+
+namespace PhpMyAdmin\Gis;
+
+/**
+ * Factory class that handles the creation of geometric objects.
+ *
+ * @package PhpMyAdmin-GIS
+ */
+class GisFactory
+{
+ /**
+ * Returns the singleton instance of geometric class of the given type.
+ *
+ * @param string $type type of the geometric object
+ *
+ * @return GisMultiPolygon|GisPolygon|GisMultiPoint|GisPoint|GisMultiLineString|GisLineString|GisGeometryCollection|false the singleton instance of geometric class of the given type
+ *
+ * @access public
+ * @static
+ */
+ public static function factory($type)
+ {
+ switch (strtoupper($type)) {
+ case 'MULTIPOLYGON':
+ return GisMultiPolygon::singleton();
+ case 'POLYGON':
+ return GisPolygon::singleton();
+ case 'MULTIPOINT':
+ return GisMultiPoint::singleton();
+ case 'POINT':
+ return GisPoint::singleton();
+ case 'MULTILINESTRING':
+ return GisMultiLineString::singleton();
+ case 'LINESTRING':
+ return GisLineString::singleton();
+ case 'GEOMETRYCOLLECTION':
+ return GisGeometryCollection::singleton();
+ default:
+ return false;
+ }
+ }
+}
diff --git a/srcs/phpmyadmin/libraries/classes/Gis/GisGeometry.php b/srcs/phpmyadmin/libraries/classes/Gis/GisGeometry.php
new file mode 100644
index 0000000..a1ce83e
--- /dev/null
+++ b/srcs/phpmyadmin/libraries/classes/Gis/GisGeometry.php
@@ -0,0 +1,407 @@
+<?php
+/* vim: set expandtab sw=4 ts=4 sts=4: */
+/**
+ * Base class for all GIS data type classes
+ *
+ * @package PhpMyAdmin-GIS
+ */
+declare(strict_types=1);
+
+namespace PhpMyAdmin\Gis;
+
+use TCPDF;
+
+/**
+ * Base class for all GIS data type classes.
+ *
+ * @package PhpMyAdmin-GIS
+ */
+abstract class GisGeometry
+{
+ /**
+ * Prepares and returns the code related to a row in the GIS dataset as SVG.
+ *
+ * @param string $spatial GIS data object
+ * @param string $label label for the GIS data object
+ * @param string $color color for the GIS data object
+ * @param array $scale_data data related to scaling
+ *
+ * @return string the code related to a row in the GIS dataset
+ * @access public
+ */
+ abstract public function prepareRowAsSvg($spatial, $label, $color, array $scale_data);
+
+ /**
+ * Adds to the PNG image object, the data related to a row in the GIS dataset.
+ *
+ * @param string $spatial GIS POLYGON object
+ * @param string|null $label Label for the GIS POLYGON object
+ * @param string $color Color for the GIS POLYGON object
+ * @param array $scale_data Array containing data related to scaling
+ * @param resource $image Image object
+ *
+ * @return resource the modified image object
+ * @access public
+ */
+ abstract public function prepareRowAsPng(
+ $spatial,
+ ?string $label,
+ $color,
+ array $scale_data,
+ $image
+ );
+
+ /**
+ * Adds to the TCPDF instance, the data related to a row in the GIS dataset.
+ *
+ * @param string $spatial GIS data object
+ * @param string|null $label label for the GIS data object
+ * @param string $color color for the GIS data object
+ * @param array $scale_data array containing data related to scaling
+ * @param TCPDF $pdf TCPDF instance
+ *
+ * @return TCPDF the modified TCPDF instance
+ * @access public
+ */
+ abstract public function prepareRowAsPdf(
+ $spatial,
+ ?string $label,
+ $color,
+ array $scale_data,
+ $pdf
+ );
+
+ /**
+ * Prepares the JavaScript related to a row in the GIS dataset
+ * to visualize it with OpenLayers.
+ *
+ * @param string $spatial GIS data object
+ * @param int $srid spatial reference ID
+ * @param string $label label for the GIS data object
+ * @param string $color color for the GIS data object
+ * @param array $scale_data array containing data related to scaling
+ *
+ * @return string the JavaScript related to a row in the GIS dataset
+ * @access public
+ */
+ abstract public function prepareRowAsOl(
+ $spatial,
+ $srid,
+ $label,
+ $color,
+ array $scale_data
+ );
+
+ /**
+ * Scales each row.
+ *
+ * @param string $spatial spatial data of a row
+ *
+ * @return array array containing the min, max values for x and y coordinates
+ * @access public
+ */
+ abstract public function scaleRow($spatial);
+
+ /**
+ * Generates the WKT with the set of parameters passed by the GIS editor.
+ *
+ * @param array $gis_data GIS data
+ * @param int $index index into the parameter object
+ * @param string $empty value for empty points
+ *
+ * @return string WKT with the set of parameters passed by the GIS editor
+ * @access public
+ */
+ abstract public function generateWkt(array $gis_data, $index, $empty = '');
+
+ /**
+ * Returns OpenLayers.Bounds object that correspond to the bounds of GIS data.
+ *
+ * @param string $srid spatial reference ID
+ * @param array $scale_data data related to scaling
+ *
+ * @return string OpenLayers.Bounds object that
+ * correspond to the bounds of GIS data
+ * @access protected
+ */
+ protected function getBoundsForOl($srid, array $scale_data)
+ {
+ return 'bound = new OpenLayers.Bounds(); '
+ . 'bound.extend(new OpenLayers.LonLat('
+ . $scale_data['minX'] . ', ' . $scale_data['minY']
+ . ').transform(new OpenLayers.Projection("EPSG:'
+ . intval($srid) . '"), map.getProjectionObject())); '
+ . 'bound.extend(new OpenLayers.LonLat('
+ . $scale_data['maxX'] . ', ' . $scale_data['maxY']
+ . ').transform(new OpenLayers.Projection("EPSG:'
+ . intval($srid) . '"), map.getProjectionObject()));';
+ }
+
+ /**
+ * Updates the min, max values with the given point set.
+ *
+ * @param string $point_set point set
+ * @param array $min_max existing min, max values
+ *
+ * @return array the updated min, max values
+ * @access protected
+ */
+ protected function setMinMax($point_set, array $min_max)
+ {
+ // Separate each point
+ $points = explode(",", $point_set);
+
+ foreach ($points as $point) {
+ // Extract coordinates of the point
+ $cordinates = explode(" ", $point);
+
+ $x = (float) $cordinates[0];
+ if (! isset($min_max['maxX']) || $x > $min_max['maxX']) {
+ $min_max['maxX'] = $x;
+ }
+ if (! isset($min_max['minX']) || $x < $min_max['minX']) {
+ $min_max['minX'] = $x;
+ }
+ $y = (float) $cordinates[1];
+ if (! isset($min_max['maxY']) || $y > $min_max['maxY']) {
+ $min_max['maxY'] = $y;
+ }
+ if (! isset($min_max['minY']) || $y < $min_max['minY']) {
+ $min_max['minY'] = $y;
+ }
+ }
+
+ return $min_max;
+ }
+
+ /**
+ * Generates parameters for the GIS data editor from the value of the GIS column.
+ * This method performs common work.
+ * More specific work is performed by each of the geom classes.
+ *
+ * @param string $value value of the GIS column
+ *
+ * @return array parameters for the GIS editor from the value of the GIS column
+ * @access protected
+ */
+ protected function generateParams($value)
+ {
+ $geom_types = '(POINT|MULTIPOINT|LINESTRING|MULTILINESTRING'
+ . '|POLYGON|MULTIPOLYGON|GEOMETRYCOLLECTION)';
+ $srid = 0;
+ $wkt = '';
+
+ if (preg_match("/^'" . $geom_types . "\(.*\)',[0-9]*$/i", $value)) {
+ $last_comma = mb_strripos($value, ",");
+ $srid = trim(mb_substr($value, $last_comma + 1));
+ $wkt = trim(mb_substr($value, 1, $last_comma - 2));
+ } elseif (preg_match("/^" . $geom_types . "\(.*\)$/i", $value)) {
+ $wkt = $value;
+ }
+
+ return [
+ 'srid' => $srid,
+ 'wkt' => $wkt,
+ ];
+ }
+
+ /**
+ * Extracts points, scales and returns them as an array.
+ *
+ * @param string $point_set string of comma separated points
+ * @param array|null $scale_data data related to scaling
+ * @param boolean $linear if true, as a 1D array, else as a 2D array
+ *
+ * @return array scaled points
+ * @access protected
+ */
+ protected function extractPoints($point_set, $scale_data, $linear = false)
+ {
+ $points_arr = [];
+
+ // Separate each point
+ $points = explode(",", $point_set);
+
+ foreach ($points as $point) {
+ $point = str_replace(['(', ')'], '', $point);
+ // Extract coordinates of the point
+ $cordinates = explode(" ", $point);
+
+ if (isset($cordinates[0]) && trim($cordinates[0]) != ''
+ && isset($cordinates[1])
+ && trim($cordinates[1]) != ''
+ ) {
+ if ($scale_data != null) {
+ $x = ($cordinates[0] - $scale_data['x']) * $scale_data['scale'];
+ $y = $scale_data['height']
+ - ($cordinates[1] - $scale_data['y']) * $scale_data['scale'];
+ } else {
+ $x = floatval(trim($cordinates[0]));
+ $y = floatval(trim($cordinates[1]));
+ }
+ } else {
+ $x = 0;
+ $y = 0;
+ }
+
+ if (! $linear) {
+ $points_arr[] = [
+ $x,
+ $y,
+ ];
+ } else {
+ $points_arr[] = $x;
+ $points_arr[] = $y;
+ }
+ }
+
+ return $points_arr;
+ }
+
+ /**
+ * Generates JavaScript for adding an array of polygons to OpenLayers.
+ *
+ * @param array $polygons x and y coordinates for each polygon
+ * @param string $srid spatial reference id
+ *
+ * @return string JavaScript for adding an array of polygons to OpenLayers
+ * @access protected
+ */
+ protected function getPolygonArrayForOpenLayers(array $polygons, $srid)
+ {
+ $ol_array = 'new Array(';
+ foreach ($polygons as $polygon) {
+ $rings = explode("),(", $polygon);
+ $ol_array .= $this->getPolygonForOpenLayers($rings, $srid) . ', ';
+ }
+
+ $ol_array
+ = mb_substr(
+ $ol_array,
+ 0,
+ mb_strlen($ol_array) - 2
+ );
+ $ol_array .= ')';
+
+ return $ol_array;
+ }
+
+ /**
+ * Generates JavaScript for adding points for OpenLayers polygon.
+ *
+ * @param array $polygon x and y coordinates for each line
+ * @param string $srid spatial reference id
+ *
+ * @return string JavaScript for adding points for OpenLayers polygon
+ * @access protected
+ */
+ protected function getPolygonForOpenLayers(array $polygon, $srid)
+ {
+ return 'new OpenLayers.Geometry.Polygon('
+ . $this->getLineArrayForOpenLayers($polygon, $srid, false)
+ . ')';
+ }
+
+ /**
+ * Generates JavaScript for adding an array of LineString
+ * or LineRing to OpenLayers.
+ *
+ * @param array $lines x and y coordinates for each line
+ * @param string $srid spatial reference id
+ * @param bool $is_line_string whether it's an array of LineString
+ *
+ * @return string JavaScript for adding an array of LineString
+ * or LineRing to OpenLayers
+ * @access protected
+ */
+ protected function getLineArrayForOpenLayers(
+ array $lines,
+ $srid,
+ $is_line_string = true
+ ) {
+ $ol_array = 'new Array(';
+ foreach ($lines as $line) {
+ $points_arr = $this->extractPoints($line, null);
+ $ol_array .= $this->getLineForOpenLayers(
+ $points_arr,
+ $srid,
+ $is_line_string
+ );
+ $ol_array .= ', ';
+ }
+
+ $ol_array
+ = mb_substr(
+ $ol_array,
+ 0,
+ mb_strlen($ol_array) - 2
+ );
+ $ol_array .= ')';
+
+ return $ol_array;
+ }
+
+ /**
+ * Generates JavaScript for adding a LineString or LineRing to OpenLayers.
+ *
+ * @param array $points_arr x and y coordinates for each point
+ * @param string $srid spatial reference id
+ * @param bool $is_line_string whether it's a LineString
+ *
+ * @return string JavaScript for adding a LineString or LineRing to OpenLayers
+ * @access protected
+ */
+ protected function getLineForOpenLayers(
+ array $points_arr,
+ $srid,
+ $is_line_string = true
+ ) {
+ return 'new OpenLayers.Geometry.'
+ . ($is_line_string ? 'LineString' : 'LinearRing') . '('
+ . $this->getPointsArrayForOpenLayers($points_arr, $srid)
+ . ')';
+ }
+
+ /**
+ * Generates JavaScript for adding an array of points to OpenLayers.
+ *
+ * @param array $points_arr x and y coordinates for each point
+ * @param string $srid spatial reference id
+ *
+ * @return string JavaScript for adding an array of points to OpenLayers
+ * @access protected
+ */
+ protected function getPointsArrayForOpenLayers(array $points_arr, $srid)
+ {
+ $ol_array = 'new Array(';
+ foreach ($points_arr as $point) {
+ $ol_array .= $this->getPointForOpenLayers($point, $srid) . ', ';
+ }
+
+ $ol_array
+ = mb_substr(
+ $ol_array,
+ 0,
+ mb_strlen($ol_array) - 2
+ );
+ $ol_array .= ')';
+
+ return $ol_array;
+ }
+
+ /**
+ * Generates JavaScript for adding a point to OpenLayers.
+ *
+ * @param array $point array containing the x and y coordinates of the point
+ * @param string $srid spatial reference id
+ *
+ * @return string JavaScript for adding points to OpenLayers
+ * @access protected
+ */
+ protected function getPointForOpenLayers(array $point, $srid)
+ {
+ return '(new OpenLayers.Geometry.Point(' . $point[0] . ',' . $point[1] . '))'
+ . '.transform(new OpenLayers.Projection("EPSG:'
+ . intval($srid) . '"), map.getProjectionObject())';
+ }
+}
diff --git a/srcs/phpmyadmin/libraries/classes/Gis/GisGeometryCollection.php b/srcs/phpmyadmin/libraries/classes/Gis/GisGeometryCollection.php
new file mode 100644
index 0000000..dfd0cb9
--- /dev/null
+++ b/srcs/phpmyadmin/libraries/classes/Gis/GisGeometryCollection.php
@@ -0,0 +1,419 @@
+<?php
+/* vim: set expandtab sw=4 ts=4 sts=4: */
+/**
+ * Handles actions related to GIS GEOMETRYCOLLECTION objects
+ *
+ * @package PhpMyAdmin-GIS
+ */
+declare(strict_types=1);
+
+namespace PhpMyAdmin\Gis;
+
+use TCPDF;
+
+/**
+ * Handles actions related to GIS GEOMETRYCOLLECTION objects
+ *
+ * @package PhpMyAdmin-GIS
+ */
+class GisGeometryCollection extends GisGeometry
+{
+ // Hold the singleton instance of the class
+ private static $_instance;
+
+ /**
+ * A private constructor; prevents direct creation of object.
+ *
+ * @access private
+ */
+ private function __construct()
+ {
+ }
+
+ /**
+ * Returns the singleton.
+ *
+ * @return GisGeometryCollection the singleton
+ * @access public
+ */
+ public static function singleton()
+ {
+ if (! isset(self::$_instance)) {
+ self::$_instance = new GisGeometryCollection();
+ }
+
+ return self::$_instance;
+ }
+
+ /**
+ * Scales each row.
+ *
+ * @param string $spatial spatial data of a row
+ *
+ * @return array array containing the min, max values for x and y coordinates
+ * @access public
+ */
+ public function scaleRow($spatial)
+ {
+ $min_max = [];
+
+ // Trim to remove leading 'GEOMETRYCOLLECTION(' and trailing ')'
+ $goem_col
+ = mb_substr(
+ $spatial,
+ 19,
+ mb_strlen($spatial) - 20
+ );
+
+ // Split the geometry collection object to get its constituents.
+ $sub_parts = $this->_explodeGeomCol($goem_col);
+
+ foreach ($sub_parts as $sub_part) {
+ $type_pos = mb_strpos($sub_part, '(');
+ if ($type_pos === false) {
+ continue;
+ }
+ $type = mb_substr($sub_part, 0, $type_pos);
+
+ $gis_obj = GisFactory::factory($type);
+ if (! $gis_obj) {
+ continue;
+ }
+ $scale_data = $gis_obj->scaleRow($sub_part);
+
+ // Update minimum/maximum values for x and y coordinates.
+ $c_maxX = (float) $scale_data['maxX'];
+ if (! isset($min_max['maxX']) || $c_maxX > $min_max['maxX']) {
+ $min_max['maxX'] = $c_maxX;
+ }
+
+ $c_minX = (float) $scale_data['minX'];
+ if (! isset($min_max['minX']) || $c_minX < $min_max['minX']) {
+ $min_max['minX'] = $c_minX;
+ }
+
+ $c_maxY = (float) $scale_data['maxY'];
+ if (! isset($min_max['maxY']) || $c_maxY > $min_max['maxY']) {
+ $min_max['maxY'] = $c_maxY;
+ }
+
+ $c_minY = (float) $scale_data['minY'];
+ if (! isset($min_max['minY']) || $c_minY < $min_max['minY']) {
+ $min_max['minY'] = $c_minY;
+ }
+ }
+
+ return $min_max;
+ }
+
+ /**
+ * Adds to the PNG image object, the data related to a row in the GIS dataset.
+ *
+ * @param string $spatial GIS POLYGON object
+ * @param string|null $label Label for the GIS POLYGON object
+ * @param string $color Color for the GIS POLYGON object
+ * @param array $scale_data Array containing data related to scaling
+ * @param resource $image Image object
+ *
+ * @return resource the modified image object
+ * @access public
+ */
+ public function prepareRowAsPng($spatial, ?string $label, $color, array $scale_data, $image)
+ {
+ // Trim to remove leading 'GEOMETRYCOLLECTION(' and trailing ')'
+ $goem_col
+ = mb_substr(
+ $spatial,
+ 19,
+ mb_strlen($spatial) - 20
+ );
+ // Split the geometry collection object to get its constituents.
+ $sub_parts = $this->_explodeGeomCol($goem_col);
+
+ foreach ($sub_parts as $sub_part) {
+ $type_pos = mb_strpos($sub_part, '(');
+ if ($type_pos === false) {
+ continue;
+ }
+ $type = mb_substr($sub_part, 0, $type_pos);
+
+ $gis_obj = GisFactory::factory($type);
+ if (! $gis_obj) {
+ continue;
+ }
+ $image = $gis_obj->prepareRowAsPng(
+ $sub_part,
+ $label,
+ $color,
+ $scale_data,
+ $image
+ );
+ }
+
+ return $image;
+ }
+
+ /**
+ * Adds to the TCPDF instance, the data related to a row in the GIS dataset.
+ *
+ * @param string $spatial GIS GEOMETRYCOLLECTION object
+ * @param string|null $label label for the GIS GEOMETRYCOLLECTION object
+ * @param string $color color for the GIS GEOMETRYCOLLECTION object
+ * @param array $scale_data array containing data related to scaling
+ * @param TCPDF $pdf TCPDF instance
+ *
+ * @return TCPDF the modified TCPDF instance
+ * @access public
+ */
+ public function prepareRowAsPdf($spatial, ?string $label, $color, array $scale_data, $pdf)
+ {
+ // Trim to remove leading 'GEOMETRYCOLLECTION(' and trailing ')'
+ $goem_col
+ = mb_substr(
+ $spatial,
+ 19,
+ mb_strlen($spatial) - 20
+ );
+ // Split the geometry collection object to get its constituents.
+ $sub_parts = $this->_explodeGeomCol($goem_col);
+
+ foreach ($sub_parts as $sub_part) {
+ $type_pos = mb_strpos($sub_part, '(');
+ if ($type_pos === false) {
+ continue;
+ }
+ $type = mb_substr($sub_part, 0, $type_pos);
+
+ $gis_obj = GisFactory::factory($type);
+ if (! $gis_obj) {
+ continue;
+ }
+ $pdf = $gis_obj->prepareRowAsPdf(
+ $sub_part,
+ $label,
+ $color,
+ $scale_data,
+ $pdf
+ );
+ }
+
+ return $pdf;
+ }
+
+ /**
+ * Prepares and returns the code related to a row in the GIS dataset as SVG.
+ *
+ * @param string $spatial GIS GEOMETRYCOLLECTION object
+ * @param string $label label for the GIS GEOMETRYCOLLECTION object
+ * @param string $color color for the GIS GEOMETRYCOLLECTION object
+ * @param array $scale_data array containing data related to scaling
+ *
+ * @return string the code related to a row in the GIS dataset
+ * @access public
+ */
+ public function prepareRowAsSvg($spatial, $label, $color, array $scale_data)
+ {
+ $row = '';
+
+ // Trim to remove leading 'GEOMETRYCOLLECTION(' and trailing ')'
+ $goem_col
+ = mb_substr(
+ $spatial,
+ 19,
+ mb_strlen($spatial) - 20
+ );
+ // Split the geometry collection object to get its constituents.
+ $sub_parts = $this->_explodeGeomCol($goem_col);
+
+ foreach ($sub_parts as $sub_part) {
+ $type_pos = mb_strpos($sub_part, '(');
+ if ($type_pos === false) {
+ continue;
+ }
+ $type = mb_substr($sub_part, 0, $type_pos);
+
+ $gis_obj = GisFactory::factory($type);
+ if (! $gis_obj) {
+ continue;
+ }
+ $row .= $gis_obj->prepareRowAsSvg(
+ $sub_part,
+ $label,
+ $color,
+ $scale_data
+ );
+ }
+
+ return $row;
+ }
+
+ /**
+ * Prepares JavaScript related to a row in the GIS dataset
+ * to visualize it with OpenLayers.
+ *
+ * @param string $spatial GIS GEOMETRYCOLLECTION object
+ * @param int $srid spatial reference ID
+ * @param string $label label for the GIS GEOMETRYCOLLECTION object
+ * @param string $color color for the GIS GEOMETRYCOLLECTION object
+ * @param array $scale_data array containing data related to scaling
+ *
+ * @return string JavaScript related to a row in the GIS dataset
+ * @access public
+ */
+ public function prepareRowAsOl($spatial, $srid, $label, $color, array $scale_data)
+ {
+ $row = '';
+
+ // Trim to remove leading 'GEOMETRYCOLLECTION(' and trailing ')'
+ $goem_col
+ = mb_substr(
+ $spatial,
+ 19,
+ mb_strlen($spatial) - 20
+ );
+ // Split the geometry collection object to get its constituents.
+ $sub_parts = $this->_explodeGeomCol($goem_col);
+
+ foreach ($sub_parts as $sub_part) {
+ $type_pos = mb_strpos($sub_part, '(');
+ if ($type_pos === false) {
+ continue;
+ }
+ $type = mb_substr($sub_part, 0, $type_pos);
+
+ $gis_obj = GisFactory::factory($type);
+ if (! $gis_obj) {
+ continue;
+ }
+ $row .= $gis_obj->prepareRowAsOl(
+ $sub_part,
+ $srid,
+ $label,
+ $color,
+ $scale_data
+ );
+ }
+
+ return $row;
+ }
+
+ /**
+ * Splits the GEOMETRYCOLLECTION object and get its constituents.
+ *
+ * @param string $geom_col geometry collection string
+ *
+ * @return array the constituents of the geometry collection object
+ * @access private
+ */
+ private function _explodeGeomCol($geom_col)
+ {
+ $sub_parts = [];
+ $br_count = 0;
+ $start = 0;
+ $count = 0;
+ foreach (str_split($geom_col) as $char) {
+ if ($char == '(') {
+ $br_count++;
+ } elseif ($char == ')') {
+ $br_count--;
+ if ($br_count == 0) {
+ $sub_parts[]
+ = mb_substr(
+ $geom_col,
+ $start,
+ $count + 1 - $start
+ );
+ $start = $count + 2;
+ }
+ }
+ $count++;
+ }
+
+ return $sub_parts;
+ }
+
+ /**
+ * Generates the WKT with the set of parameters passed by the GIS editor.
+ *
+ * @param array $gis_data GIS data
+ * @param int $index index into the parameter object
+ * @param string $empty value for empty points
+ *
+ * @return string WKT with the set of parameters passed by the GIS editor
+ * @access public
+ */
+ public function generateWkt(array $gis_data, $index, $empty = '')
+ {
+ $geom_count = isset($gis_data['GEOMETRYCOLLECTION']['geom_count'])
+ ? $gis_data['GEOMETRYCOLLECTION']['geom_count'] : 1;
+ $wkt = 'GEOMETRYCOLLECTION(';
+ for ($i = 0; $i < $geom_count; $i++) {
+ if (isset($gis_data[$i]['gis_type'])) {
+ $type = $gis_data[$i]['gis_type'];
+ $gis_obj = GisFactory::factory($type);
+ if (! $gis_obj) {
+ continue;
+ }
+ $wkt .= $gis_obj->generateWkt($gis_data, $i, $empty) . ',';
+ }
+ }
+ if (isset($gis_data[0]['gis_type'])) {
+ $wkt
+ = mb_substr(
+ $wkt,
+ 0,
+ mb_strlen($wkt) - 1
+ );
+ }
+ $wkt .= ')';
+
+ return $wkt;
+ }
+
+ /**
+ * Generates parameters for the GIS data editor from the value of the GIS column.
+ *
+ * @param string $value of the GIS column
+ *
+ * @return array parameters for the GIS editor from the value of the GIS column
+ * @access public
+ */
+ public function generateParams($value)
+ {
+ $params = [];
+ $data = GisGeometry::generateParams($value);
+ $params['srid'] = $data['srid'];
+ $wkt = $data['wkt'];
+
+ // Trim to remove leading 'GEOMETRYCOLLECTION(' and trailing ')'
+ $goem_col
+ = mb_substr(
+ $wkt,
+ 19,
+ mb_strlen($wkt) - 20
+ );
+ // Split the geometry collection object to get its constituents.
+ $sub_parts = $this->_explodeGeomCol($goem_col);
+ $params['GEOMETRYCOLLECTION']['geom_count'] = count($sub_parts);
+
+ $i = 0;
+ foreach ($sub_parts as $sub_part) {
+ $type_pos = mb_strpos($sub_part, '(');
+ if ($type_pos === false) {
+ continue;
+ }
+ $type = mb_substr($sub_part, 0, $type_pos);
+ /**
+ * @var GisMultiPolygon|GisPolygon|GisMultiPoint|GisPoint|GisMultiLineString|GisLineString $gis_obj
+ */
+ $gis_obj = GisFactory::factory($type);
+ if (! $gis_obj) {
+ continue;
+ }
+ $params = array_merge($params, $gis_obj->generateParams($sub_part, $i));
+ $i++;
+ }
+
+ return $params;
+ }
+}
diff --git a/srcs/phpmyadmin/libraries/classes/Gis/GisLineString.php b/srcs/phpmyadmin/libraries/classes/Gis/GisLineString.php
new file mode 100644
index 0000000..f309605
--- /dev/null
+++ b/srcs/phpmyadmin/libraries/classes/Gis/GisLineString.php
@@ -0,0 +1,360 @@
+<?php
+/* vim: set expandtab sw=4 ts=4 sts=4: */
+/**
+ * Handles actions related to GIS LINESTRING objects
+ *
+ * @package PhpMyAdmin-GIS
+ */
+declare(strict_types=1);
+
+namespace PhpMyAdmin\Gis;
+
+use TCPDF;
+
+/**
+ * Handles actions related to GIS LINESTRING objects
+ *
+ * @package PhpMyAdmin-GIS
+ */
+class GisLineString extends GisGeometry
+{
+ // Hold the singleton instance of the class
+ private static $_instance;
+
+ /**
+ * A private constructor; prevents direct creation of object.
+ *
+ * @access private
+ */
+ private function __construct()
+ {
+ }
+
+ /**
+ * Returns the singleton.
+ *
+ * @return GisLineString the singleton
+ * @access public
+ */
+ public static function singleton()
+ {
+ if (! isset(self::$_instance)) {
+ self::$_instance = new GisLineString();
+ }
+
+ return self::$_instance;
+ }
+
+ /**
+ * Scales each row.
+ *
+ * @param string $spatial spatial data of a row
+ *
+ * @return array an array containing the min, max values for x and y coordinates
+ * @access public
+ */
+ public function scaleRow($spatial)
+ {
+ // Trim to remove leading 'LINESTRING(' and trailing ')'
+ $linestring
+ = mb_substr(
+ $spatial,
+ 11,
+ mb_strlen($spatial) - 12
+ );
+
+ return $this->setMinMax($linestring, []);
+ }
+
+ /**
+ * Adds to the PNG image object, the data related to a row in the GIS dataset.
+ *
+ * @param string $spatial GIS POLYGON object
+ * @param string|null $label Label for the GIS POLYGON object
+ * @param string $line_color Color for the GIS POLYGON object
+ * @param array $scale_data Array containing data related to scaling
+ * @param resource $image Image object
+ *
+ * @return resource the modified image object
+ * @access public
+ */
+ public function prepareRowAsPng(
+ $spatial,
+ ?string $label,
+ $line_color,
+ array $scale_data,
+ $image
+ ) {
+ // allocate colors
+ $black = imagecolorallocate($image, 0, 0, 0);
+ $red = hexdec(mb_substr($line_color, 1, 2));
+ $green = hexdec(mb_substr($line_color, 3, 2));
+ $blue = hexdec(mb_substr($line_color, 4, 2));
+ $color = imagecolorallocate($image, $red, $green, $blue);
+
+ // Trim to remove leading 'LINESTRING(' and trailing ')'
+ $linesrting
+ = mb_substr(
+ $spatial,
+ 11,
+ mb_strlen($spatial) - 12
+ );
+ $points_arr = $this->extractPoints($linesrting, $scale_data);
+
+ foreach ($points_arr as $point) {
+ if (! isset($temp_point)) {<