Merge branch 'master' of git://phpmyadmin.git.sourceforge.net/gitroot/phpmyadmin...
[phpmyadmin/crack.git] / libraries / gis / pma_gis_point.php
blob0b4bff15aa2c194383a0fb53259ca9c7196484b4
1 <?php
2 /**
3 * Handles the visualization of GIS POINT objects.
5 * @package phpMyAdmin-GIS
6 */
7 class PMA_GIS_Point extends PMA_GIS_Geometry
9 // Hold the singleton instance of the class
10 private static $_instance;
12 /**
13 * A private constructor; prevents direct creation of object.
15 private function __construct()
19 /**
20 * Returns the singleton.
22 * @return the singleton
24 public static function singleton()
26 if (!isset(self::$_instance)) {
27 $class = __CLASS__;
28 self::$_instance = new $class;
31 return self::$_instance;
34 /**
35 * Scales each row.
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)
43 // Trim to remove leading 'POINT(' and trailing ')'
44 $point = substr($spatial, 6, (strlen($spatial) - 7));
45 return $this->setMinMax($point, array());
48 /**
49 * Adds to the PNG image object, the data related to a row in the GIS dataset.
51 * @param string $spatial GIS POINT object
52 * @param string $label Label for the GIS POINT object
53 * @param string $point_color Color for the GIS POINT object
54 * @param array $scale_data Array containing data related to scaling
55 * @param image $image Image object
57 * @return the modified image object
59 public function prepareRowAsPng($spatial, $label, $point_color, $scale_data, $image)
61 // allocate colors
62 $red = hexdec(substr($point_color, 1, 2));
63 $green = hexdec(substr($point_color, 3, 2));
64 $blue = hexdec(substr($point_color, 4, 2));
65 $color = imagecolorallocate($image, $red, $green, $blue);
67 // Trim to remove leading 'POINT(' and trailing ')'
68 $point = substr($spatial, 6, (strlen($spatial) - 7));
69 $points_arr = $this->extractPoints($point, $scale_data);
71 // draw a small circle to mark the point
72 imagearc($image, $points_arr[0][0], $points_arr[0][1], 7, 7, 0, 360, $color);
73 return $image;
76 /**
77 * Adds to the TCPDF instance, the data related to a row in the GIS dataset.
79 * @param string $spatial GIS POINT object
80 * @param string $label Label for the GIS POINT object
81 * @param string $point_color Color for the GIS POINT object
82 * @param array $scale_data Array containing data related to scaling
83 * @param image $pdf TCPDF instance
85 * @return the modified TCPDF instance
87 public function prepareRowAsPdf($spatial, $label, $point_color, $scale_data, $pdf)
89 // allocate colors
90 $red = hexdec(substr($point_color, 1, 2));
91 $green = hexdec(substr($point_color, 3, 2));
92 $blue = hexdec(substr($point_color, 4, 2));
93 $line = array('width' => 1.25, 'color' => array($red, $green, $blue));
95 // Trim to remove leading 'POINT(' and trailing ')'
96 $point = substr($spatial, 6, (strlen($spatial) - 7));
97 $points_arr = $this->extractPoints($point, $scale_data);
99 // draw a small circle to mark the point
100 $pdf->Circle($points_arr[0][0], $points_arr[0][1], 2, 0, 360, 'D', $line);
101 return $pdf;
105 * Prepares and returns the code related to a row in the GIS dataset as SVG.
107 * @param string $spatial GIS POINT object
108 * @param string $label Label for the GIS POINT object
109 * @param string $point_color Color for the GIS POINT object
110 * @param array $scale_data Array containing data related to scaling
112 * @return the code related to a row in the GIS dataset
114 public function prepareRowAsSvg($spatial, $label, $point_color, $scale_data)
116 $point_options = array(
117 'name' => $label,
118 'id' => $label . rand(),
119 'class' => 'point vector',
120 'fill' => 'white',
121 'stroke' => $point_color,
122 'stroke-width'=> 2,
125 // Trim to remove leading 'POINT(' and trailing ')'
126 $point = substr($spatial, 6, (strlen($spatial) - 7));
127 $points_arr = $this->extractPoints($point, $scale_data);
129 $row = '<circle cx="' . $points_arr[0][0] . '" cy="' . $points_arr[0][1] . '" r="3"';
130 foreach ($point_options as $option => $val) {
131 $row .= ' ' . $option . '="' . trim($val) . '"';
133 $row .= '/>';
135 return $row;
139 * Prepares JavaScript related to a row in the GIS dataset
140 * to visualize it with OpenLayers.
142 * @param string $spatial GIS POINT object
143 * @param int $srid Spatial reference ID
144 * @param string $label Label for the GIS POINT object
145 * @param string $point_color Color for the GIS POINT object
146 * @param array $scale_data Array containing data related to scaling
148 * @return JavaScript related to a row in the GIS dataset
150 public function prepareRowAsOl($spatial, $srid, $label, $point_color, $scale_data)
152 $style_options = array(
153 'pointRadius' => 3,
154 'fillColor' => '#ffffff',
155 'strokeColor' => $point_color,
156 'strokeWidth' => 2,
157 'label' => $label,
158 'labelYOffset' => -8,
159 'fontSize' => 10,
161 if ($srid == 0) {
162 $srid = 4326;
164 $result = $this->getBoundsForOl($srid, $scale_data);
166 // Trim to remove leading 'POINT(' and trailing ')'
167 $point = substr($spatial, 6, (strlen($spatial) - 7));
168 $points_arr = $this->extractPoints($point, null);
170 $result .= 'vectorLayer.addFeatures(new OpenLayers.Feature.Vector(('
171 . 'new OpenLayers.Geometry.Point(' . $points_arr[0][0] . ', '
172 . $points_arr[0][1] . ').transform(new OpenLayers.Projection("EPSG:'
173 . $srid . '"), map.getProjectionObject())), null, '
174 . json_encode($style_options) . '));';
175 return $result;
179 * Generate the WKT with the set of parameters passed by the GIS editor.
181 * @param array $gis_data GIS data
182 * @param int $index Index into the parameter object
183 * @param string $empty Value for empty points
185 * @return WKT with the set of parameters passed by the GIS editor
187 public function generateWkt($gis_data, $index, $empty = '')
189 return 'POINT('
190 . ((isset($gis_data[$index]['POINT']['x']) && trim($gis_data[$index]['POINT']['x']) != '')
191 ? $gis_data[$index]['POINT']['x'] : $empty) . ' '
192 . ((isset($gis_data[$index]['POINT']['y']) && trim($gis_data[$index]['POINT']['y']) != '')
193 ? $gis_data[$index]['POINT']['y'] : $empty) . ')';
197 * Generate the WKT for the data from ESRI shape files.
199 * @param array $row_data GIS data
201 * @return the WKT for the data from ESRI shape files
203 public function getShape($row_data) {
204 return 'POINT(' . (isset($row_data['x']) ? $row_data['x'] : '')
205 . ' ' . (isset($row_data['y']) ? $row_data['y'] : '') . ')';
209 * Generate parameters for the GIS data editor from the value of the GIS column.
211 * @param string $value of the GIS column
212 * @param index $index of the geometry
214 * @return parameters for the GIS data editor from the value of the GIS column
216 public function generateParams($value, $index = -1)
218 if ($index == -1) {
219 $index = 0;
220 $params = array();
221 $last_comma = strripos($value, ",");
222 $params['srid'] = trim(substr($value, $last_comma + 1));
223 $wkt = trim(substr($value, 1, $last_comma - 2));
224 } else {
225 $params[$index]['gis_type'] = 'POINT';
226 $wkt = $value;
229 // Trim to remove leading 'POINT(' and trailing ')'
230 $point = substr($wkt, 6, (strlen($wkt) - 7));
231 $points_arr = $this->extractPoints($point, null);
233 $params[$index]['POINT']['x'] = $points_arr[0][0];
234 $params[$index]['POINT']['y'] = $points_arr[0][1];
236 return $params;