initial commit

This commit is contained in:
Chris Sewell
2012-11-28 03:55:08 -05:00
parent 7adb399b2e
commit cf140a2e97
3247 changed files with 492437 additions and 0 deletions

View File

@ -0,0 +1,50 @@
<?php
/**
* Factory class that handles the creation of geometric objects.
*
* @package PhpMyAdmin-GIS
*/
class PMA_GIS_Factory
{
/**
* Returns the singleton instance of geometric class of the given type.
*
* @param string $type type of the geometric object
*
* @throws Exception
*
* @return the singleton instance of geometric class of the given type
*/
public static function factory($type)
{
include_once './libraries/gis/pma_gis_geometry.php';
$type_lower = strtolower($type);
if (! file_exists('./libraries/gis/pma_gis_' . $type_lower . '.php')) {
return false;
}
if (include_once './libraries/gis/pma_gis_' . $type_lower . '.php') {
switch($type) {
case 'MULTIPOLYGON' :
return PMA_GIS_Multipolygon::singleton();
case 'POLYGON' :
return PMA_GIS_Polygon::singleton();
case 'MULTIPOINT' :
return PMA_GIS_Multipoint::singleton();
case 'POINT' :
return PMA_GIS_Point::singleton();
case 'MULTILINESTRING' :
return PMA_GIS_Multilinestring::singleton();
case 'LINESTRING' :
return PMA_GIS_Linestring::singleton();
case 'GEOMETRYCOLLECTION' :
return PMA_GIS_Geometrycollection::singleton();
default :
return false;
}
} else {
return false;
}
}
}
?>

View File

@ -0,0 +1,250 @@
<?php
/**
* Base class for all GIS data type classes.
*
* @package PhpMyAdmin-GIS
*/
abstract class PMA_GIS_Geometry
{
/**
* 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 the code related to a row in the GIS dataset
*/
public abstract function prepareRowAsSvg($spatial, $label, $color, $scale_data);
/**
* Adds to the PNG image object, the data related to a row in the GIS dataset.
*
* @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 Array containing data related to scaling
* @param image $image Image object
*
* @return the modified image object
*/
public abstract function prepareRowAsPng($spatial, $label, $color, $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 $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 image $pdf TCPDF instance
*
* @return the modified TCPDF instance
*/
public abstract function prepareRowAsPdf($spatial, $label, $color, $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 the JavaScript related to a row in the GIS dataset
*/
public abstract function prepareRowAsOl($spatial, $srid, $label, $color, $scale_data);
/**
* Scales each row.
*
* @param string $spatial spatial data of a row
*
* @return array containing the min, max values for x and y cordinates
*/
public abstract function scaleRow($spatial);
/**
* Generate 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 WKT with the set of parameters passed by the GIS editor
*/
public abstract function generateWkt($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 OpenLayers.Bounds object that correspond to the bounds of GIS data
*/
protected function getBoundsForOl($srid, $scale_data)
{
return 'bound = new OpenLayers.Bounds(); bound.extend(new OpenLayers.LonLat('
. $scale_data['minX'] . ', ' . $scale_data['minY']
. ').transform(new OpenLayers.Projection("EPSG:'
. $srid . '"), map.getProjectionObject())); bound.extend(new OpenLayers.LonLat('
. $scale_data['maxX'] . ', ' . $scale_data['maxY']
. ').transform(new OpenLayers.Projection("EPSG:'
. $srid . '"), map.getProjectionObject()));';
}
/**
* Update the min, max values with the given point set.
*
* @param string $point_set Point set
* @param array $min_max Existing min, max values
*
* @return the updated min, max values
*/
protected function setMinMax($point_set, $min_max)
{
// Seperate each point
$points = explode(",", $point_set);
foreach ($points as $point) {
// Extract cordinates 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;
}
/**
* Generate 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 $gis_string $value of the GIS column
*
* @return array parameters for the GIS editor from the value of the GIS column
*/
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 = strripos($value, ",");
$srid = trim(substr($value, $last_comma + 1));
$wkt = trim(substr($value, 1, $last_comma - 2));
} elseif (preg_match("/^" . $geom_types . "\(.*\)$/i", $value)) {
$wkt = $value;
}
return array('srid' => $srid, 'wkt' => $wkt);
}
/**
* Extracts points, scales and returns them as an array.
*
* @param string $point_set String of comma sperated points
* @param array $scale_data Data related to scaling
* @param boolean $linear If true, as a 1D array, else as a 2D array
*
* @return scaled points
*/
protected function extractPoints($point_set, $scale_data, $linear = false)
{
$points_arr = array();
// Seperate each point
$points = explode(",", $point_set);
foreach ($points as $point) {
// Extract cordinates 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 = trim($cordinates[0]);
$y = trim($cordinates[1]);
}
} else {
$x = '';
$y = '';
}
if (! $linear) {
$points_arr[] = array($x, $y);
} else {
$points_arr[] = $x;
$points_arr[] = $y;
}
}
return $points_arr;
}
/**
* Generates JavaScriipt for adding points for OpenLayers polygon.
*
* @param string $polygon points of a polygon in WKT form
* @param string $srid spatial reference id
*
* @return JavaScriipt for adding points for OpenLayers polygon
*/
protected function addPointsForOpenLayersPolygon($polygon, $srid)
{
$row = 'new OpenLayers.Geometry.Polygon(new Array(';
// If the polygon doesnt have an inner polygon
if (strpos($polygon, "),(") === false) {
$points_arr = $this->extractPoints($polygon, null);
$row .= 'new OpenLayers.Geometry.LinearRing(new Array(';
foreach ($points_arr as $point) {
$row .= '(new OpenLayers.Geometry.Point('
. $point[0] . ', ' . $point[1] . '))'
. '.transform(new OpenLayers.Projection("EPSG:'
. $srid . '"), map.getProjectionObject()), ';
}
$row = substr($row, 0, strlen($row) - 2);
$row .= '))';
} else {
// Seperate outer and inner polygons
$parts = explode("),(", $polygon);
foreach ($parts as $ring) {
$points_arr = $this->extractPoints($ring, null);
$row .= 'new OpenLayers.Geometry.LinearRing(new Array(';
foreach ($points_arr as $point) {
$row .= '(new OpenLayers.Geometry.Point('
. $point[0] . ', ' . $point[1] . '))'
. '.transform(new OpenLayers.Projection("EPSG:'
. $srid . '"), map.getProjectionObject()), ';
}
$row = substr($row, 0, strlen($row) - 2);
$row .= ')), ';
}
$row = substr($row, 0, strlen($row) - 2);
}
$row .= ')), ';
return $row;
}
}
?>

View File

@ -0,0 +1,307 @@
<?php
/**
* Handles the visualization of GIS GEOMETRYCOLLECTION objects.
*
* @package PhpMyAdmin-GIS
*/
class PMA_GIS_Geometrycollection extends PMA_GIS_Geometry
{
// Hold the singleton instance of the class
private static $_instance;
/**
* A private constructor; prevents direct creation of object.
*/
private function __construct()
{
}
/**
* Returns the singleton.
*
* @return the singleton
*/
public static function singleton()
{
if (!isset(self::$_instance)) {
$class = __CLASS__;
self::$_instance = new $class;
}
return self::$_instance;
}
/**
* Scales each row.
*
* @param string $spatial spatial data of a row
*
* @return array containing the min, max values for x and y cordinates
*/
public function scaleRow($spatial)
{
$min_max = array();
// Trim to remove leading 'GEOMETRYCOLLECTION(' and trailing ')'
$goem_col = substr($spatial, 19, (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 = stripos($sub_part, '(');
$type = substr($sub_part, 0, $type_pos);
$gis_obj = PMA_GIS_Factory::factory($type);
if (! $gis_obj) {
continue;
}
$scale_data = $gis_obj->scaleRow($sub_part);
// Upadate minimum/maximum values for x and y cordinates.
$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 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
* @param image $image Image object
*
* @return the modified image object
*/
public function prepareRowAsPng($spatial, $label, $color, $scale_data, $image)
{
// Trim to remove leading 'GEOMETRYCOLLECTION(' and trailing ')'
$goem_col = substr($spatial, 19, (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 = stripos($sub_part, '(');
$type = substr($sub_part, 0, $type_pos);
$gis_obj = PMA_GIS_Factory::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 $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 image $pdf TCPDF instance
*
* @return the modified TCPDF instance
*/
public function prepareRowAsPdf($spatial, $label, $color, $scale_data, $pdf)
{
// Trim to remove leading 'GEOMETRYCOLLECTION(' and trailing ')'
$goem_col = substr($spatial, 19, (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 = stripos($sub_part, '(');
$type = substr($sub_part, 0, $type_pos);
$gis_obj = PMA_GIS_Factory::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 the code related to a row in the GIS dataset
*/
public function prepareRowAsSvg($spatial, $label, $color, $scale_data)
{
$row = '';
// Trim to remove leading 'GEOMETRYCOLLECTION(' and trailing ')'
$goem_col = substr($spatial, 19, (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 = stripos($sub_part, '(');
$type = substr($sub_part, 0, $type_pos);
$gis_obj = PMA_GIS_Factory::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 JavaScript related to a row in the GIS dataset
*/
public function prepareRowAsOl($spatial, $srid, $label, $color, $scale_data)
{
$row = '';
// Trim to remove leading 'GEOMETRYCOLLECTION(' and trailing ')'
$goem_col = substr($spatial, 19, (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 = stripos($sub_part, '(');
$type = substr($sub_part, 0, $type_pos);
$gis_obj = PMA_GIS_Factory::factory($type);
if (! $gis_obj) {
continue;
}
$row .= $gis_obj->prepareRowAsOl($sub_part, $srid, $label, $color, $scale_data);
}
return $row;
}
/**
* Split the GEOMETRYCOLLECTION object and get its constituents.
*
* @param string $goem_col Geometry collection string
*
* @return the constituents of the geometry collection object
*/
private function _explodeGeomCol($goem_col)
{
$sub_parts = array();
$br_count = 0;
$start = 0;
$count = 0;
foreach (str_split($goem_col) as $char) {
if ($char == '(') {
$br_count++;
} elseif ($char == ')') {
$br_count--;
if ($br_count == 0) {
$sub_parts[] = substr($goem_col, $start, ($count + 1 - $start));
$start = $count + 2;
}
}
$count++;
}
return $sub_parts;
}
/**
* Generate 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 WKT with the set of parameters passed by the GIS editor
*/
public function generateWkt($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 = PMA_GIS_Factory::factory($type);
if (! $gis_obj) {
continue;
}
$wkt .= $gis_obj->generateWkt($gis_data, $i, $empty) . ',';
}
}
if (isset($gis_data[0]['gis_type'])) {
$wkt = substr($wkt, 0, strlen($wkt) - 1);
}
$wkt .= ')';
return $wkt;
}
/** Generate parameters for the GIS data editor from the value of the GIS column.
*
* @param string $value of the GIS column
* @param index $index of the geometry
*
* @return parameters for the GIS data editor from the value of the GIS column
*/
public function generateParams($value)
{
$params = array();
$data = PMA_GIS_Geometry::generateParams($value);
$params['srid'] = $data['srid'];
$wkt = $data['wkt'];
// Trim to remove leading 'GEOMETRYCOLLECTION(' and trailing ')'
$goem_col = substr($wkt, 19, (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 = stripos($sub_part, '(');
$type = substr($sub_part, 0, $type_pos);
$gis_obj = PMA_GIS_Factory::factory($type);
if (! $gis_obj) {
continue;
}
$params = array_merge($params, $gis_obj->generateParams($sub_part, $i));
$i++;
}
return $params;
}
}
?>

View File

@ -0,0 +1,276 @@
<?php
/**
* Handles the visualization of GIS LINESTRING objects.
*
* @package PhpMyAdmin-GIS
*/
class PMA_GIS_Linestring extends PMA_GIS_Geometry
{
// Hold the singleton instance of the class
private static $_instance;
/**
* A private constructor; prevents direct creation of object.
*/
private function __construct()
{
}
/**
* Returns the singleton.
*
* @return the singleton
*/
public static function singleton()
{
if (!isset(self::$_instance)) {
$class = __CLASS__;
self::$_instance = new $class;
}
return self::$_instance;
}
/**
* Scales each row.
*
* @param string $spatial spatial data of a row
*
* @return array containing the min, max values for x and y cordinates
*/
public function scaleRow($spatial)
{
// Trim to remove leading 'LINESTRING(' and trailing ')'
$linesrting = substr($spatial, 11, (strlen($spatial) - 12));
return $this->setMinMax($linesrting, array());
}
/**
* Adds to the PNG image object, the data related to a row in the GIS dataset.
*
* @param string $spatial GIS LINESTRING object
* @param string $label Label for the GIS LINESTRING object
* @param string $line_color Color for the GIS LINESTRING object
* @param array $scale_data Array containing data related to scaling
* @param image $image Image object
*
* @return the modified image object
*/
public function prepareRowAsPng($spatial, $label, $line_color, $scale_data, $image)
{
// allocate colors
$black = imagecolorallocate($image, 0, 0, 0);
$red = hexdec(substr($line_color, 1, 2));
$green = hexdec(substr($line_color, 3, 2));
$blue = hexdec(substr($line_color, 4, 2));
$color = imagecolorallocate($image, $red, $green, $blue);
// Trim to remove leading 'LINESTRING(' and trailing ')'
$linesrting = substr($spatial, 11, (strlen($spatial) - 12));
$points_arr = $this->extractPoints($linesrting, $scale_data);
foreach ($points_arr as $point) {
if (! isset($temp_point)) {
$temp_point = $point;
} else {
// draw line section
imageline($image, $temp_point[0], $temp_point[1], $point[0], $point[1], $color);
$temp_point = $point;
}
}
// print label if applicable
if (isset($label) && trim($label) != '') {
imagestring($image, 1, $points_arr[1][0], $points_arr[1][1], trim($label), $black);
}
return $image;
}
/**
* Adds to the TCPDF instance, the data related to a row in the GIS dataset.
*
* @param string $spatial GIS LINESTRING object
* @param string $label Label for the GIS LINESTRING object
* @param string $line_color Color for the GIS LINESTRING object
* @param array $scale_data Array containing data related to scaling
* @param image $pdf TCPDF instance
*
* @return the modified TCPDF instance
*/
public function prepareRowAsPdf($spatial, $label, $line_color, $scale_data, $pdf)
{
// allocate colors
$red = hexdec(substr($line_color, 1, 2));
$green = hexdec(substr($line_color, 3, 2));
$blue = hexdec(substr($line_color, 4, 2));
$line = array('width' => 1.5, 'color' => array($red, $green, $blue));
// Trim to remove leading 'LINESTRING(' and trailing ')'
$linesrting = substr($spatial, 11, (strlen($spatial) - 12));
$points_arr = $this->extractPoints($linesrting, $scale_data);
foreach ($points_arr as $point) {
if (! isset($temp_point)) {
$temp_point = $point;
} else {
// draw line section
$pdf->Line($temp_point[0], $temp_point[1], $point[0], $point[1], $line);
$temp_point = $point;
}
}
// print label
if (isset($label) && trim($label) != '') {
$pdf->SetXY($points_arr[1][0], $points_arr[1][1]);
$pdf->SetFontSize(5);
$pdf->Cell(0, 0, trim($label));
}
return $pdf;
}
/**
* Prepares and returns the code related to a row in the GIS dataset as SVG.
*
* @param string $spatial GIS LINESTRING object
* @param string $label Label for the GIS LINESTRING object
* @param string $line_color Color for the GIS LINESTRING object
* @param array $scale_data Array containing data related to scaling
*
* @return the code related to a row in the GIS dataset
*/
public function prepareRowAsSvg($spatial, $label, $line_color, $scale_data)
{
$line_options = array(
'name' => $label,
'id' => $label . rand(),
'class' => 'linestring vector',
'fill' => 'none',
'stroke' => $line_color,
'stroke-width'=> 2,
);
// Trim to remove leading 'LINESTRING(' and trailing ')'
$linesrting = substr($spatial, 11, (strlen($spatial) - 12));
$points_arr = $this->extractPoints($linesrting, $scale_data);
$row = '<polyline points="';
foreach ($points_arr as $point) {
$row .= $point[0] . ',' . $point[1] . ' ';
}
$row .= '"';
foreach ($line_options as $option => $val) {
$row .= ' ' . $option . '="' . trim($val) . '"';
}
$row .= '/>';
return $row;
}
/**
* Prepares JavaScript related to a row in the GIS dataset
* to visualize it with OpenLayers.
*
* @param string $spatial GIS LINESTRING object
* @param int $srid Spatial reference ID
* @param string $label Label for the GIS LINESTRING object
* @param string $line_color Color for the GIS LINESTRING object
* @param array $scale_data Array containing data related to scaling
*
* @return JavaScript related to a row in the GIS dataset
*/
public function prepareRowAsOl($spatial, $srid, $label, $line_color, $scale_data)
{
$style_options = array(
'strokeColor' => $line_color,
'strokeWidth' => 2,
'label' => $label,
'fontSize' => 10,
);
if ($srid == 0) {
$srid = 4326;
}
$result = $this->getBoundsForOl($srid, $scale_data);
// Trim to remove leading 'LINESTRING(' and trailing ')'
$linesrting = substr($spatial, 11, (strlen($spatial) - 12));
$points_arr = $this->extractPoints($linesrting, null);
$row = 'new Array(';
foreach ($points_arr as $point) {
$row .= '(new OpenLayers.Geometry.Point(' . $point[0] . ', '
. $point[1] . ')).transform(new OpenLayers.Projection("EPSG:'
. $srid . '"), map.getProjectionObject()), ';
}
$row = substr($row, 0, strlen($row) - 2);
$row .= ')';
$result .= 'vectorLayer.addFeatures(new OpenLayers.Feature.Vector('
. 'new OpenLayers.Geometry.LineString(' . $row . '), null, '
. json_encode($style_options) . '));';
return $result;
}
/**
* Generate 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 WKT with the set of parameters passed by the GIS editor
*/
public function generateWkt($gis_data, $index, $empty = '')
{
$no_of_points = isset($gis_data[$index]['LINESTRING']['no_of_points'])
? $gis_data[$index]['LINESTRING']['no_of_points'] : 2;
if ($no_of_points < 2) {
$no_of_points = 2;
}
$wkt = 'LINESTRING(';
for ($i = 0; $i < $no_of_points; $i++) {
$wkt .= ((isset($gis_data[$index]['LINESTRING'][$i]['x'])
&& trim($gis_data[$index]['LINESTRING'][$i]['x']) != '')
? $gis_data[$index]['LINESTRING'][$i]['x'] : $empty)
. ' ' . ((isset($gis_data[$index]['LINESTRING'][$i]['y'])
&& trim($gis_data[$index]['LINESTRING'][$i]['y']) != '')
? $gis_data[$index]['LINESTRING'][$i]['y'] : $empty) .',';
}
$wkt = substr($wkt, 0, strlen($wkt) - 1);
$wkt .= ')';
return $wkt;
}
/**
* Generate parameters for the GIS data editor from the value of the GIS column.
*
* @param string $value of the GIS column
* @param index $index of the geometry
*
* @return parameters for the GIS data editor from the value of the GIS column
*/
public function generateParams($value, $index = -1)
{
if ($index == -1) {
$index = 0;
$params = array();
$data = PMA_GIS_Geometry::generateParams($value);
$params['srid'] = $data['srid'];
$wkt = $data['wkt'];
} else {
$params[$index]['gis_type'] = 'LINESTRING';
$wkt = $value;
}
// Trim to remove leading 'LINESTRING(' and trailing ')'
$linestring = substr($wkt, 11, (strlen($wkt) - 12));
$points_arr = $this->extractPoints($linestring, null);
$no_of_points = count($points_arr);
$params[$index]['LINESTRING']['no_of_points'] = $no_of_points;
for ($i = 0; $i < $no_of_points; $i++) {
$params[$index]['LINESTRING'][$i]['x'] = $points_arr[$i][0];
$params[$index]['LINESTRING'][$i]['y'] = $points_arr[$i][1];
}
return $params;
}
}
?>

View File

@ -0,0 +1,348 @@
<?php
/**
* Handles the visualization of GIS MULTILINESTRING objects.
*
* @package PhpMyAdmin-GIS
*/
class PMA_GIS_Multilinestring extends PMA_GIS_Geometry
{
// Hold the singleton instance of the class
private static $_instance;
/**
* A private constructor; prevents direct creation of object.
*/
private function __construct()
{
}
/**
* Returns the singleton.
*
* @return the singleton
*/
public static function singleton()
{
if (!isset(self::$_instance)) {
$class = __CLASS__;
self::$_instance = new $class;
}
return self::$_instance;
}
/**
* Scales each row.
*
* @param string $spatial spatial data of a row
*
* @return array containing the min, max values for x and y cordinates
*/
public function scaleRow($spatial)
{
$min_max = array();
// Trim to remove leading 'MULTILINESTRING((' and trailing '))'
$multilinestirng = substr($spatial, 17, (strlen($spatial) - 19));
// Seperate each linestring
$linestirngs = explode("),(", $multilinestirng);
foreach ($linestirngs as $linestring) {
$min_max = $this->setMinMax($linestring, $min_max);
}
return $min_max;
}
/**
* Adds to the PNG image object, the data related to a row in the GIS dataset.
*
* @param string $spatial GIS MULTILINESTRING object
* @param string $label Label for the GIS MULTILINESTRING object
* @param string $line_color Color for the GIS MULTILINESTRING object
* @param array $scale_data Array containing data related to scaling
* @param image $image Image object
*
* @return the modified image object
*/
public function prepareRowAsPng($spatial, $label, $line_color, $scale_data, $image)
{
// allocate colors
$black = imagecolorallocate($image, 0, 0, 0);
$red = hexdec(substr($line_color, 1, 2));
$green = hexdec(substr($line_color, 3, 2));
$blue = hexdec(substr($line_color, 4, 2));
$color = imagecolorallocate($image, $red, $green, $blue);
// Trim to remove leading 'MULTILINESTRING((' and trailing '))'
$multilinestirng = substr($spatial, 17, (strlen($spatial) - 19));
// Seperate each linestring
$linestirngs = explode("),(", $multilinestirng);
$first_line = true;
foreach ($linestirngs as $linestring) {
$points_arr = $this->extractPoints($linestring, $scale_data);
foreach ($points_arr as $point) {
if (! isset($temp_point)) {
$temp_point = $point;
} else {
// draw line section
imageline($image, $temp_point[0], $temp_point[1], $point[0], $point[1], $color);
$temp_point = $point;
}
}
unset($temp_point);
// print label if applicable
if (isset($label) && trim($label) != '' && $first_line) {
imagestring($image, 1, $points_arr[1][0], $points_arr[1][1], trim($label), $black);
}
$first_line = false;
}
return $image;
}
/**
* Adds to the TCPDF instance, the data related to a row in the GIS dataset.
*
* @param string $spatial GIS MULTILINESTRING object
* @param string $label Label for the GIS MULTILINESTRING object
* @param string $line_color Color for the GIS MULTILINESTRING object
* @param array $scale_data Array containing data related to scaling
* @param image $pdf TCPDF instance
*
* @return the modified TCPDF instance
*/
public function prepareRowAsPdf($spatial, $label, $line_color, $scale_data, $pdf)
{
// allocate colors
$red = hexdec(substr($line_color, 1, 2));
$green = hexdec(substr($line_color, 3, 2));
$blue = hexdec(substr($line_color, 4, 2));
$line = array('width' => 1.5, 'color' => array($red, $green, $blue));
// Trim to remove leading 'MULTILINESTRING((' and trailing '))'
$multilinestirng = substr($spatial, 17, (strlen($spatial) - 19));
// Seperate each linestring
$linestirngs = explode("),(", $multilinestirng);
$first_line = true;
foreach ($linestirngs as $linestring) {
$points_arr = $this->extractPoints($linestring, $scale_data);
foreach ($points_arr as $point) {
if (! isset($temp_point)) {
$temp_point = $point;
} else {
// draw line section
$pdf->Line($temp_point[0], $temp_point[1], $point[0], $point[1], $line);
$temp_point = $point;
}
}
unset($temp_point);
// print label
if (isset($label) && trim($label) != '' && $first_line) {
$pdf->SetXY($points_arr[1][0], $points_arr[1][1]);
$pdf->SetFontSize(5);
$pdf->Cell(0, 0, trim($label));
}
$first_line = false;
}
return $pdf;
}
/**
* Prepares and returns the code related to a row in the GIS dataset as SVG.
*
* @param string $spatial GIS MULTILINESTRING object
* @param string $label Label for the GIS MULTILINESTRING object
* @param string $line_color Color for the GIS MULTILINESTRING object
* @param array $scale_data Array containing data related to scaling
*
* @return the code related to a row in the GIS dataset
*/
public function prepareRowAsSvg($spatial, $label, $line_color, $scale_data)
{
$line_options = array(
'name' => $label,
'class' => 'linestring vector',
'fill' => 'none',
'stroke' => $line_color,
'stroke-width'=> 2,
);
// Trim to remove leading 'MULTILINESTRING((' and trailing '))'
$multilinestirng = substr($spatial, 17, (strlen($spatial) - 19));
// Seperate each linestring
$linestirngs = explode("),(", $multilinestirng);
$row = '';
foreach ($linestirngs as $linestring) {
$points_arr = $this->extractPoints($linestring, $scale_data);
$row .= '<polyline points="';
foreach ($points_arr as $point) {
$row .= $point[0] . ',' . $point[1] . ' ';
}
$row .= '"';
$line_options['id'] = $label . rand();
foreach ($line_options as $option => $val) {
$row .= ' ' . $option . '="' . trim($val) . '"';
}
$row .= '/>';
}
return $row;
}
/**
* Prepares JavaScript related to a row in the GIS dataset
* to visualize it with OpenLayers.
*
* @param string $spatial GIS MULTILINESTRING object
* @param int $srid Spatial reference ID
* @param string $label Label for the GIS MULTILINESTRING object
* @param string $line_color Color for the GIS MULTILINESTRING object
* @param array $scale_data Array containing data related to scaling
*
* @return JavaScript related to a row in the GIS dataset
*/
public function prepareRowAsOl($spatial, $srid, $label, $line_color, $scale_data)
{
$style_options = array(
'strokeColor' => $line_color,
'strokeWidth' => 2,
'label' => $label,
'fontSize' => 10,
);
if ($srid == 0) {
$srid = 4326;
}
$row = $this->getBoundsForOl($srid, $scale_data);
// Trim to remove leading 'MULTILINESTRING((' and trailing '))'
$multilinestirng = substr($spatial, 17, (strlen($spatial) - 19));
// Seperate each linestring
$linestirngs = explode("),(", $multilinestirng);
$row .= 'vectorLayer.addFeatures(new OpenLayers.Feature.Vector('
. 'new OpenLayers.Geometry.MultiLineString(new Array(';
foreach ($linestirngs as $linestring) {
$points_arr = $this->extractPoints($linestring, null);
$row .= 'new OpenLayers.Geometry.LineString(new Array(';
foreach ($points_arr as $point) {
$row .= '(new OpenLayers.Geometry.Point(' . $point[0] . ', '
. $point[1] . ')).transform(new OpenLayers.Projection("EPSG:'
. $srid . '"), map.getProjectionObject()), ';
}
$row = substr($row, 0, strlen($row) - 2);
$row .= ')), ';
}
$row = substr($row, 0, strlen($row) - 2);
$row .= ')), null, ' . json_encode($style_options) . '));';
return $row;
}
/**
* Generate 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 WKT with the set of parameters passed by the GIS editor
*/
public function generateWkt($gis_data, $index, $empty = '')
{
$no_of_lines = isset($gis_data[$index]['MULTILINESTRING']['no_of_lines'])
? $gis_data[$index]['MULTILINESTRING']['no_of_lines'] : 1;
if ($no_of_lines < 1) {
$no_of_lines = 1;
}
$wkt = 'MULTILINESTRING(';
for ($i = 0; $i < $no_of_lines; $i++) {
$no_of_points = isset($gis_data[$index]['MULTILINESTRING'][$i]['no_of_points'])
? $gis_data[$index]['MULTILINESTRING'][$i]['no_of_points'] : 2;
if ($no_of_points < 2) {
$no_of_points = 2;
}
$wkt .= '(';
for ($j = 0; $j < $no_of_points; $j++) {
$wkt .= ((isset($gis_data[$index]['MULTILINESTRING'][$i][$j]['x'])
&& trim($gis_data[$index]['MULTILINESTRING'][$i][$j]['x']) != '')
? $gis_data[$index]['MULTILINESTRING'][$i][$j]['x'] : $empty)
. ' ' . ((isset($gis_data[$index]['MULTILINESTRING'][$i][$j]['y'])
&& trim($gis_data[$index]['MULTILINESTRING'][$i][$j]['y']) != '')
? $gis_data[$index]['MULTILINESTRING'][$i][$j]['y'] : $empty) . ',';
}
$wkt = substr($wkt, 0, strlen($wkt) - 1);
$wkt .= '),';
}
$wkt = substr($wkt, 0, strlen($wkt) - 1);
$wkt .= ')';
return $wkt;
}
/**
* Generate the WKT for the data from ESRI shape files.
*
* @param array $row_data GIS data
*
* @return the WKT for the data from ESRI shape files
*/
public function getShape($row_data)
{
$wkt = 'MULTILINESTRING(';
for ($i = 0; $i < $row_data['numparts']; $i++) {
$wkt .= '(';
foreach ($row_data['parts'][$i]['points'] as $point) {
$wkt .= $point['x'] . ' ' . $point['y'] . ',';
}
$wkt = substr($wkt, 0, strlen($wkt) - 1);
$wkt .= '),';
}
$wkt = substr($wkt, 0, strlen($wkt) - 1);
$wkt .= ')';
return $wkt;
}
/**
* Generate parameters for the GIS data editor from the value of the GIS column.
*
* @param string $value of the GIS column
* @param index $index of the geometry
*
* @return parameters for the GIS data editor from the value of the GIS column
*/
public function generateParams($value, $index = -1)
{
if ($index == -1) {
$index = 0;
$params = array();
$data = PMA_GIS_Geometry::generateParams($value);
$params['srid'] = $data['srid'];
$wkt = $data['wkt'];
} else {
$params[$index]['gis_type'] = 'MULTILINESTRING';
$wkt = $value;
}
// Trim to remove leading 'MULTILINESTRING((' and trailing '))'
$multilinestirng = substr($wkt, 17, (strlen($wkt) - 19));
// Seperate each linestring
$linestirngs = explode("),(", $multilinestirng);
$params[$index]['MULTILINESTRING']['no_of_lines'] = count($linestirngs);
$j = 0;
foreach ($linestirngs as $linestring) {
$points_arr = $this->extractPoints($linestring, null);
$no_of_points = count($points_arr);
$params[$index]['MULTILINESTRING'][$j]['no_of_points'] = $no_of_points;
for ($i = 0; $i < $no_of_points; $i++) {
$params[$index]['MULTILINESTRING'][$j][$i]['x'] = $points_arr[$i][0];
$params[$index]['MULTILINESTRING'][$j][$i]['y'] = $points_arr[$i][1];
}
$j++;
}
return $params;
}
}
?>

View File

@ -0,0 +1,300 @@
<?php
/**
* Handles the visualization of GIS MULTIPOINT objects.
*
* @package PhpMyAdmin-GIS
*/
class PMA_GIS_Multipoint extends PMA_GIS_Geometry
{
// Hold the singleton instance of the class
private static $_instance;
/**
* A private constructor; prevents direct creation of object.
*/
private function __construct()
{
}
/**
* Returns the singleton.
*
* @return the singleton
*/
public static function singleton()
{
if (!isset(self::$_instance)) {
$class = __CLASS__;
self::$_instance = new $class;
}
return self::$_instance;
}
/**
* Scales each row.
*
* @param string $spatial spatial data of a row
*
* @return array containing the min, max values for x and y cordinates
*/
public function scaleRow($spatial)
{
// Trim to remove leading 'MULTIPOINT(' and trailing ')'
$multipoint = substr($spatial, 11, (strlen($spatial) - 12));
return $this->setMinMax($multipoint, array());
}
/**
* Adds to the PNG image object, the data related to a row in the GIS dataset.
*
* @param string $spatial GIS MULTIPOINT object
* @param string $label Label for the GIS MULTIPOINT object
* @param string $point_color Color for the GIS MULTIPOINT object
* @param array $scale_data Array containing data related to scaling
* @param image $image Image object
*
* @return the modified image object
*/
public function prepareRowAsPng($spatial, $label, $point_color, $scale_data, $image)
{
// allocate colors
$black = imagecolorallocate($image, 0, 0, 0);
$red = hexdec(substr($point_color, 1, 2));
$green = hexdec(substr($point_color, 3, 2));
$blue = hexdec(substr($point_color, 4, 2));
$color = imagecolorallocate($image, $red, $green, $blue);
// Trim to remove leading 'MULTIPOINT(' and trailing ')'
$multipoint = substr($spatial, 11, (strlen($spatial) - 12));
$points_arr = $this->extractPoints($multipoint, $scale_data);
foreach ($points_arr as $point) {
// draw a small circle to mark the point
if ($point[0] != '' && $point[1] != '') {
imagearc($image, $point[0], $point[1], 7, 7, 0, 360, $color);
}
}
// print label for each point
if ((isset($label) && trim($label) != '')
&& ($points_arr[0][0] != '' && $points_arr[0][1] != '')
) {
imagestring($image, 1, $points_arr[0][0], $points_arr[0][1], trim($label), $black);
}
return $image;
}
/**
* Adds to the TCPDF instance, the data related to a row in the GIS dataset.
*
* @param string $spatial GIS MULTIPOINT object
* @param string $label Label for the GIS MULTIPOINT object
* @param string $point_color Color for the GIS MULTIPOINT object
* @param array $scale_data Array containing data related to scaling
* @param image $pdf TCPDF instance
*
* @return the modified TCPDF instance
*/
public function prepareRowAsPdf($spatial, $label, $point_color, $scale_data, $pdf)
{
// allocate colors
$red = hexdec(substr($point_color, 1, 2));
$green = hexdec(substr($point_color, 3, 2));
$blue = hexdec(substr($point_color, 4, 2));
$line = array('width' => 1.25, 'color' => array($red, $green, $blue));
// Trim to remove leading 'MULTIPOINT(' and trailing ')'
$multipoint = substr($spatial, 11, (strlen($spatial) - 12));
$points_arr = $this->extractPoints($multipoint, $scale_data);
foreach ($points_arr as $point) {
// draw a small circle to mark the point
if ($point[0] != '' && $point[1] != '') {
$pdf->Circle($point[0], $point[1], 2, 0, 360, 'D', $line);
}
}
// print label for each point
if ((isset($label) && trim($label) != '')
&& ($points_arr[0][0] != '' && $points_arr[0][1] != '')
) {
$pdf->SetXY($points_arr[0][0], $points_arr[0][1]);
$pdf->SetFontSize(5);
$pdf->Cell(0, 0, trim($label));
}
return $pdf;
}
/**
* Prepares and returns the code related to a row in the GIS dataset as SVG.
*
* @param string $spatial GIS MULTIPOINT object
* @param string $label Label for the GIS MULTIPOINT object
* @param string $point_color Color for the GIS MULTIPOINT object
* @param array $scale_data Array containing data related to scaling
*
* @return the code related to a row in the GIS dataset
*/
public function prepareRowAsSvg($spatial, $label, $point_color, $scale_data)
{
$point_options = array(
'name' => $label,
'class' => 'multipoint vector',
'fill' => 'white',
'stroke' => $point_color,
'stroke-width'=> 2,
);
// Trim to remove leading 'MULTIPOINT(' and trailing ')'
$multipoint = substr($spatial, 11, (strlen($spatial) - 12));
$points_arr = $this->extractPoints($multipoint, $scale_data);
$row = '';
foreach ($points_arr as $point) {
if ($point[0] != '' && $point[1] != '') {
$row .= '<circle cx="' . $point[0] . '" cy="' . $point[1] . '" r="3"';
$point_options['id'] = $label . rand();
foreach ($point_options as $option => $val) {
$row .= ' ' . $option . '="' . trim($val) . '"';
}
$row .= '/>';
}
}
return $row;
}
/**
* Prepares JavaScript related to a row in the GIS dataset
* to visualize it with OpenLayers.
*
* @param string $spatial GIS MULTIPOINT object
* @param int $srid Spatial reference ID
* @param string $label Label for the GIS MULTIPOINT object
* @param string $point_color Color for the GIS MULTIPOINT object
* @param array $scale_data Array containing data related to scaling
*
* @return JavaScript related to a row in the GIS dataset
*/
public function prepareRowAsOl($spatial, $srid, $label, $point_color, $scale_data)
{
$style_options = array(
'pointRadius' => 3,
'fillColor' => '#ffffff',
'strokeColor' => $point_color,
'strokeWidth' => 2,
'label' => $label,
'labelYOffset' => -8,
'fontSize' => 10,
);
if ($srid == 0) {
$srid = 4326;
}
$result = $this->getBoundsForOl($srid, $scale_data);
// Trim to remove leading 'MULTIPOINT(' and trailing ')'
$multipoint = substr($spatial, 11, (strlen($spatial) - 12));
$points_arr = $this->extractPoints($multipoint, null);
$row = 'new Array(';
foreach ($points_arr as $point) {
if ($point[0] != '' && $point[1] != '') {
$row .= '(new OpenLayers.Geometry.Point(' . $point[0] . ', ' . $point[1]
. ')).transform(new OpenLayers.Projection("EPSG:' . $srid
. '"), map.getProjectionObject()), ';
}
}
if (substr($row, strlen($row) - 2) == ', ') {
$row = substr($row, 0, strlen($row) - 2);
}
$row .= ')';
$result .= 'vectorLayer.addFeatures(new OpenLayers.Feature.Vector('
. 'new OpenLayers.Geometry.MultiPoint(' . $row . '), null, '
. json_encode($style_options) . '));';
return $result;
}
/**
* Generate 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 Multipoint does not adhere to this
*
* @return WKT with the set of parameters passed by the GIS editor
*/
public function generateWkt($gis_data, $index, $empty = '')
{
$no_of_points = isset($gis_data[$index]['MULTIPOINT']['no_of_points'])
? $gis_data[$index]['MULTIPOINT']['no_of_points'] : 1;
if ($no_of_points < 1) {
$no_of_points = 1;
}
$wkt = 'MULTIPOINT(';
for ($i = 0; $i < $no_of_points; $i++) {
$wkt .= ((isset($gis_data[$index]['MULTIPOINT'][$i]['x'])
&& trim($gis_data[$index]['MULTIPOINT'][$i]['x']) != '')
? $gis_data[$index]['MULTIPOINT'][$i]['x'] : '')
. ' ' . ((isset($gis_data[$index]['MULTIPOINT'][$i]['y'])
&& trim($gis_data[$index]['MULTIPOINT'][$i]['y']) != '')
? $gis_data[$index]['MULTIPOINT'][$i]['y'] : '') . ',';
}
$wkt = substr($wkt, 0, strlen($wkt) - 1);
$wkt .= ')';
return $wkt;
}
/**
* Generate the WKT for the data from ESRI shape files.
*
* @param array $row_data GIS data
*
* @return the WKT for the data from ESRI shape files
*/
public function getShape($row_data)
{
$wkt = 'MULTIPOINT(';
for ($i = 0; $i < $row_data['numpoints']; $i++) {
$wkt .= $row_data['points'][$i]['x'] . ' ' . $row_data['points'][$i]['y'] . ',';
}
$wkt = substr($wkt, 0, strlen($wkt) - 1);
$wkt .= ')';
return $wkt;
}
/**
* Generate parameters for the GIS data editor from the value of the GIS column.
*
* @param string $value of the GIS column
* @param index $index of the geometry
*
* @return parameters for the GIS data editor from the value of the GIS column
*/
public function generateParams($value, $index = -1)
{
if ($index == -1) {
$index = 0;
$params = array();
$data = PMA_GIS_Geometry::generateParams($value);
$params['srid'] = $data['srid'];
$wkt = $data['wkt'];
} else {
$params[$index]['gis_type'] = 'MULTIPOINT';
$wkt = $value;
}
// Trim to remove leading 'MULTIPOINT(' and trailing ')'
$points = substr($wkt, 11, (strlen($wkt) - 12));
$points_arr = $this->extractPoints($points, null);
$no_of_points = count($points_arr);
$params[$index]['MULTIPOINT']['no_of_points'] = $no_of_points;
for ($i = 0; $i < $no_of_points; $i++) {
$params[$index]['MULTIPOINT'][$i]['x'] = $points_arr[$i][0];
$params[$index]['MULTIPOINT'][$i]['y'] = $points_arr[$i][1];
}
return $params;
}
}
?>

View File

@ -0,0 +1,498 @@
<?php
/**
* Handles the visualization of GIS MULTIPOLYGON objects.
*
* @package PhpMyAdmin-GIS
*/
class PMA_GIS_Multipolygon extends PMA_GIS_Geometry
{
// Hold the singleton instance of the class
private static $_instance;
/**
* A private constructor; prevents direct creation of object.
*/
private function __construct()
{
}
/**
* Returns the singleton.
*
* @return the singleton
*/
public static function singleton()
{
if (!isset(self::$_instance)) {
$class = __CLASS__;
self::$_instance = new $class;
}
return self::$_instance;
}
/**
* Scales each row.
*
* @param string $spatial spatial data of a row
*
* @return array containing the min, max values for x and y cordinates
*/
public function scaleRow($spatial)
{
$min_max = array();
// Trim to remove leading 'MULTIPOLYGON(((' and trailing ')))'
$multipolygon = substr($spatial, 15, (strlen($spatial) - 18));
// Seperate each polygon
$polygons = explode(")),((", $multipolygon);
foreach ($polygons as $polygon) {
// If the polygon doesn't have an inner ring, use polygon itself
if (strpos($polygon, "),(") === false) {
$ring = $polygon;
} else {
// Seperate outer ring and use it to determin min-max
$parts = explode("),(", $polygon);
$ring = $parts[0];
}
$min_max = $this->setMinMax($ring, $min_max);
}
return $min_max;
}
/**
* Adds to the PNG image object, the data related to a row in the GIS dataset.
*
* @param string $spatial GIS MULTIPOLYGON object
* @param string $label Label for the GIS MULTIPOLYGON object
* @param string $fill_color Color for the GIS MULTIPOLYGON object
* @param array $scale_data Array containing data related to scaling
* @param image $image Image object
*
* @return the modified image object
*/
public function prepareRowAsPng($spatial, $label, $fill_color, $scale_data, $image)
{
// allocate colors
$black = imagecolorallocate($image, 0, 0, 0);
$red = hexdec(substr($fill_color, 1, 2));
$green = hexdec(substr($fill_color, 3, 2));
$blue = hexdec(substr($fill_color, 4, 2));
$color = imagecolorallocate($image, $red, $green, $blue);
// Trim to remove leading 'MULTIPOLYGON(((' and trailing ')))'
$multipolygon = substr($spatial, 15, (strlen($spatial) - 18));
// Seperate each polygon
$polygons = explode(")),((", $multipolygon);
$first_poly = true;
foreach ($polygons as $polygon) {
// If the polygon doesnt have an inner polygon
if (strpos($polygon, "),(") === false) {
$points_arr = $this->extractPoints($polygon, $scale_data, true);
} else {
// Seperate outer and inner polygons
$parts = explode("),(", $polygon);
$outer = $parts[0];
$inner = array_slice($parts, 1);
$points_arr = $this->extractPoints($outer, $scale_data, true);
foreach ($inner as $inner_poly) {
$points_arr = array_merge(
$points_arr, $this->extractPoints($inner_poly, $scale_data, true)
);
}
}
// draw polygon
imagefilledpolygon($image, $points_arr, sizeof($points_arr) / 2, $color);
// mark label point if applicable
if (isset($label) && trim($label) != '' && $first_poly) {
$label_point = array($points_arr[2], $points_arr[3]);
}
$first_poly = false;
}
// print label if applicable
if (isset($label_point)) {
imagestring($image, 1, $points_arr[2], $points_arr[3], trim($label), $black);
}
return $image;
}
/**
* Adds to the TCPDF instance, the data related to a row in the GIS dataset.
*
* @param string $spatial GIS MULTIPOLYGON object
* @param string $label Label for the GIS MULTIPOLYGON object
* @param string $fill_color Color for the GIS MULTIPOLYGON object
* @param array $scale_data Array containing data related to scaling
* @param image $pdf TCPDF instance
*
* @return the modified TCPDF instance
*/
public function prepareRowAsPdf($spatial, $label, $fill_color, $scale_data, $pdf)
{
// allocate colors
$red = hexdec(substr($fill_color, 1, 2));
$green = hexdec(substr($fill_color, 3, 2));
$blue = hexdec(substr($fill_color, 4, 2));
$color = array($red, $green, $blue);
// Trim to remove leading 'MULTIPOLYGON(((' and trailing ')))'
$multipolygon = substr($spatial, 15, (strlen($spatial) - 18));
// Seperate each polygon
$polygons = explode(")),((", $multipolygon);
$first_poly = true;
foreach ($polygons as $polygon) {
// If the polygon doesnt have an inner polygon
if (strpos($polygon, "),(") === false) {
$points_arr = $this->extractPoints($polygon, $scale_data, true);
} else {
// Seperate outer and inner polygons
$parts = explode("),(", $polygon);
$outer = $parts[0];
$inner = array_slice($parts, 1);
$points_arr = $this->extractPoints($outer, $scale_data, true);
foreach ($inner as $inner_poly) {
$points_arr = array_merge(
$points_arr,
$this->extractPoints($inner_poly, $scale_data, true)
);
}
}
// draw polygon
$pdf->Polygon($points_arr, 'F*', array(), $color, true);
// mark label point if applicable
if (isset($label) && trim($label) != '' && $first_poly) {
$label_point = array($points_arr[2], $points_arr[3]);
}
$first_poly = false;
}
// print label if applicable
if (isset($label_point)) {
$pdf->SetXY($label_point[0], $label_point[1]);
$pdf->SetFontSize(5);
$pdf->Cell(0, 0, trim($label));
}
return $pdf;
}
/**
* Prepares and returns the code related to a row in the GIS dataset as SVG.
*
* @param string $spatial GIS MULTIPOLYGON object
* @param string $label Label for the GIS MULTIPOLYGON object
* @param string $fill_color Color for the GIS MULTIPOLYGON object
* @param array $scale_data Array containing data related to scaling
*
* @return the code related to a row in the GIS dataset
*/
public function prepareRowAsSvg($spatial, $label, $fill_color, $scale_data)
{
$polygon_options = array(
'name' => $label,
'class' => 'multipolygon vector',
'stroke' => 'black',
'stroke-width'=> 0.5,
'fill' => $fill_color,
'fill-rule' => 'evenodd',
'fill-opacity'=> 0.8,
);
$row = '';
// Trim to remove leading 'MULTIPOLYGON(((' and trailing ')))'
$multipolygon = substr($spatial, 15, (strlen($spatial) - 18));
// Seperate each polygon
$polygons = explode(")),((", $multipolygon);
foreach ($polygons as $polygon) {
$row .= '<path d="';
// If the polygon doesnt have an inner polygon
if (strpos($polygon, "),(") === false) {
$row .= $this->_drawPath($polygon, $scale_data);
} else {
// Seperate outer and inner polygons
$parts = explode("),(", $polygon);
$outer = $parts[0];
$inner = array_slice($parts, 1);
$row .= $this->_drawPath($outer, $scale_data);
foreach ($inner as $inner_poly) {
$row .= $this->_drawPath($inner_poly, $scale_data);
}
}
$polygon_options['id'] = $label . rand();
$row .= '"';
foreach ($polygon_options as $option => $val) {
$row .= ' ' . $option . '="' . trim($val) . '"';
}
$row .= '/>';
}
return $row;
}
/**
* Prepares JavaScript related to a row in the GIS dataset
* to visualize it with OpenLayers.
*
* @param string $spatial GIS MULTIPOLYGON object
* @param int $srid Spatial reference ID
* @param string $label Label for the GIS MULTIPOLYGON object
* @param string $fill_color Color for the GIS MULTIPOLYGON object
* @param array $scale_data Array containing data related to scaling
*
* @return JavaScript related to a row in the GIS dataset
*/
public function prepareRowAsOl($spatial, $srid, $label, $fill_color, $scale_data)
{
$style_options = array(
'strokeColor' => '#000000',
'strokeWidth' => 0.5,
'fillColor' => $fill_color,
'fillOpacity' => 0.8,
'label' => $label,
'fontSize' => 10,
);
if ($srid == 0) {
$srid = 4326;
}
$row = $this->getBoundsForOl($srid, $scale_data);
// Trim to remove leading 'MULTIPOLYGON(((' and trailing ')))'
$multipolygon = substr($spatial, 15, (strlen($spatial) - 18));
// Seperate each polygon
$polygons = explode(")),((", $multipolygon);
$row .= 'vectorLayer.addFeatures(new OpenLayers.Feature.Vector('
. 'new OpenLayers.Geometry.MultiPolygon(new Array(';
foreach ($polygons as $polygon) {
$row .= $this->addPointsForOpenLayersPolygon($polygon, $srid);
}
$row = substr($row, 0, strlen($row) - 2);
$row .= ')), null, ' . json_encode($style_options) . '));';
return $row;
}
/**
* Draws a ring of the polygon using SVG path element.
*
* @param string $polygon The ring
* @param array $scale_data Array containing data related to scaling
*
* @return the code to draw the ring
*/
private function _drawPath($polygon, $scale_data)
{
$points_arr = $this->extractPoints($polygon, $scale_data);
$row = ' M ' . $points_arr[0][0] . ', ' . $points_arr[0][1];
$other_points = array_slice($points_arr, 1, count($points_arr) - 2);
foreach ($other_points as $point) {
$row .= ' L ' . $point[0] . ', ' . $point[1];
}
$row .= ' Z ';
return $row;
}
/**
* Generate 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 WKT with the set of parameters passed by the GIS editor
*/
public function generateWkt($gis_data, $index, $empty = '')
{
$no_of_polygons = isset($gis_data[$index]['MULTIPOLYGON']['no_of_polygons'])
? $gis_data[$index]['MULTIPOLYGON']['no_of_polygons'] : 1;
if ($no_of_polygons < 1) {
$no_of_polygons = 1;
}
$wkt = 'MULTIPOLYGON(';
for ($k = 0; $k < $no_of_polygons; $k++) {
$no_of_lines = isset($gis_data[$index]['MULTIPOLYGON'][$k]['no_of_lines'])
? $gis_data[$index]['MULTIPOLYGON'][$k]['no_of_lines'] : 1;
if ($no_of_lines < 1) {
$no_of_lines = 1;
}
$wkt .= '(';
for ($i = 0; $i < $no_of_lines; $i++) {
$no_of_points = isset($gis_data[$index]['MULTIPOLYGON'][$k][$i]['no_of_points'])
? $gis_data[$index]['MULTIPOLYGON'][$k][$i]['no_of_points'] : 4;
if ($no_of_points < 4) {
$no_of_points = 4;
}
$wkt .= '(';
for ($j = 0; $j < $no_of_points; $j++) {
$wkt .= ((isset($gis_data[$index]['MULTIPOLYGON'][$k][$i][$j]['x'])
&& trim($gis_data[$index]['MULTIPOLYGON'][$k][$i][$j]['x']) != '')
? $gis_data[$index]['MULTIPOLYGON'][$k][$i][$j]['x'] : $empty)
. ' ' . ((isset($gis_data[$index]['MULTIPOLYGON'][$k][$i][$j]['y'])
&& trim($gis_data[$index]['MULTIPOLYGON'][$k][$i][$j]['y']) != '')
? $gis_data[$index]['MULTIPOLYGON'][$k][$i][$j]['y'] : $empty) .',';
}
$wkt = substr($wkt, 0, strlen($wkt) - 1);
$wkt .= '),';
}
$wkt = substr($wkt, 0, strlen($wkt) - 1);
$wkt .= '),';
}
$wkt = substr($wkt, 0, strlen($wkt) - 1);
$wkt .= ')';
return $wkt;
}
/**
* Generate the WKT for the data from ESRI shape files.
*
* @param array $row_data GIS data
*
* @return the WKT for the data from ESRI shape files
*/
public function getShape($row_data)
{
// Determines whether each line ring is an inner ring or an outer ring.
// If it's an inner ring get a point on the surface which can be used to
// correctly classify inner rings to their respective outer rings.
include_once './libraries/gis/pma_gis_polygon.php';
foreach ($row_data['parts'] as $i => $ring) {
$row_data['parts'][$i]['isOuter'] = PMA_GIS_Polygon::isOuterRing($ring['points']);
}
// Find points on surface for inner rings
foreach ($row_data['parts'] as $i => $ring) {
if (! $ring['isOuter']) {
$row_data['parts'][$i]['pointOnSurface']
= PMA_GIS_Polygon::getPointOnSurface($ring['points']);
}
}
// Classify inner rings to their respective outer rings.
foreach ($row_data['parts'] as $j => $ring1) {
if (! $ring1['isOuter']) {
foreach ($row_data['parts'] as $k => $ring2) {
if ($ring2['isOuter']) {
// If the pointOnSurface of the inner ring
// is also inside the outer ring
if (PMA_GIS_Polygon::isPointInsidePolygon(
$ring1['pointOnSurface'], $ring2['points']
)) {
if (! isset($ring2['inner'])) {
$row_data['parts'][$k]['inner'] = array();
}
$row_data['parts'][$k]['inner'][] = $j;
}
}
}
}
}
$wkt = 'MULTIPOLYGON(';
// for each polygon
foreach ($row_data['parts'] as $ring) {
if ($ring['isOuter']) {
$wkt .= '('; // start of polygon
$wkt .= '('; // start of outer ring
foreach ($ring['points'] as $point) {
$wkt .= $point['x'] . ' ' . $point['y'] . ',';
}
$wkt = substr($wkt, 0, strlen($wkt) - 1);
$wkt .= ')'; // end of outer ring
// inner rings if any
if (isset($ring['inner'])) {
foreach ($ring['inner'] as $j) {
$wkt .= ',('; // start of inner ring
foreach ($row_data['parts'][$j]['points'] as $innerPoint) {
$wkt .= $innerPoint['x'] . ' ' . $innerPoint['y'] . ',';
}
$wkt = substr($wkt, 0, strlen($wkt) - 1);
$wkt .= ')'; // end of inner ring
}
}
$wkt .= '),'; // end of polygon
}
}
$wkt = substr($wkt, 0, strlen($wkt) - 1);
$wkt .= ')'; // end of multipolygon
return $wkt;
}
/**
* Generate parameters for the GIS data editor from the value of the GIS column.
*
* @param string $value of the GIS column
* @param index $index of the geometry
*
* @return parameters for the GIS data editor from the value of the GIS column
*/
public function generateParams($value, $index = -1)
{
if ($index == -1) {
$index = 0;
$params = array();
$data = PMA_GIS_Geometry::generateParams($value);
$params['srid'] = $data['srid'];
$wkt = $data['wkt'];
} else {
$params[$index]['gis_type'] = 'MULTIPOLYGON';
$wkt = $value;
}
// Trim to remove leading 'MULTIPOLYGON(((' and trailing ')))'
$multipolygon = substr($wkt, 15, (strlen($wkt) - 18));
// Seperate each polygon
$polygons = explode(")),((", $multipolygon);
$params[$index]['MULTIPOLYGON']['no_of_polygons'] = count($polygons);
$k = 0;
foreach ($polygons as $polygon) {
// If the polygon doesnt have an inner polygon
if (strpos($polygon, "),(") === false) {
$params[$index]['MULTIPOLYGON'][$k]['no_of_lines'] = 1;
$points_arr = $this->extractPoints($polygon, null);
$no_of_points = count($points_arr);
$params[$index]['MULTIPOLYGON'][$k][0]['no_of_points'] = $no_of_points;
for ($i = 0; $i < $no_of_points; $i++) {
$params[$index]['MULTIPOLYGON'][$k][0][$i]['x'] = $points_arr[$i][0];
$params[$index]['MULTIPOLYGON'][$k][0][$i]['y'] = $points_arr[$i][1];
}
} else {
// Seperate outer and inner polygons
$parts = explode("),(", $polygon);
$params[$index]['MULTIPOLYGON'][$k]['no_of_lines'] = count($parts);
$j = 0;
foreach ($parts as $ring) {
$points_arr = $this->extractPoints($ring, null);
$no_of_points = count($points_arr);
$params[$index]['MULTIPOLYGON'][$k][$j]['no_of_points'] = $no_of_points;
for ($i = 0; $i < $no_of_points; $i++) {
$params[$index]['MULTIPOLYGON'][$k][$j][$i]['x'] = $points_arr[$i][0];
$params[$index]['MULTIPOLYGON'][$k][$j][$i]['y'] = $points_arr[$i][1];
}
$j++;
}
}
$k++;
}
return $params;
}
}
?>

View File

@ -0,0 +1,260 @@
<?php
/**
* Handles the visualization of GIS POINT objects.
*
* @package PhpMyAdmin-GIS
*/
class PMA_GIS_Point extends PMA_GIS_Geometry
{
// Hold the singleton instance of the class
private static $_instance;
/**
* A private constructor; prevents direct creation of object.
*/
private function __construct()
{
}
/**
* Returns the singleton.
*
* @return the singleton
*/
public static function singleton()
{
if (!isset(self::$_instance)) {
$class = __CLASS__;
self::$_instance = new $class;
}
return self::$_instance;
}
/**
* Scales each row.
*
* @param string $spatial spatial data of a row
*
* @return array containing the min, max values for x and y cordinates
*/
public function scaleRow($spatial)
{
// Trim to remove leading 'POINT(' and trailing ')'
$point = substr($spatial, 6, (strlen($spatial) - 7));
return $this->setMinMax($point, array());
}
/**
* Adds to the PNG image object, the data related to a row in the GIS dataset.
*
* @param string $spatial GIS POINT object
* @param string $label Label for the GIS POINT object
* @param string $point_color Color for the GIS POINT object
* @param array $scale_data Array containing data related to scaling
* @param image $image Image object
*
* @return the modified image object
*/
public function prepareRowAsPng($spatial, $label, $point_color, $scale_data, $image)
{
// allocate colors
$black = imagecolorallocate($image, 0, 0, 0);
$red = hexdec(substr($point_color, 1, 2));
$green = hexdec(substr($point_color, 3, 2));
$blue = hexdec(substr($point_color, 4, 2));
$color = imagecolorallocate($image, $red, $green, $blue);
// Trim to remove leading 'POINT(' and trailing ')'
$point = substr($spatial, 6, (strlen($spatial) - 7));
$points_arr = $this->extractPoints($point, $scale_data);
// draw a small circle to mark the point
if ($points_arr[0][0] != '' && $points_arr[0][1] != '') {
imagearc($image, $points_arr[0][0], $points_arr[0][1], 7, 7, 0, 360, $color);
// print label if applicable
if (isset($label) && trim($label) != '') {
imagestring($image, 1, $points_arr[0][0], $points_arr[0][1], trim($label), $black);
}
}
return $image;
}
/**
* Adds to the TCPDF instance, the data related to a row in the GIS dataset.
*
* @param string $spatial GIS POINT object
* @param string $label Label for the GIS POINT object
* @param string $point_color Color for the GIS POINT object
* @param array $scale_data Array containing data related to scaling
* @param image $pdf TCPDF instance
*
* @return the modified TCPDF instance
*/
public function prepareRowAsPdf($spatial, $label, $point_color, $scale_data, $pdf)
{
// allocate colors
$red = hexdec(substr($point_color, 1, 2));
$green = hexdec(substr($point_color, 3, 2));
$blue = hexdec(substr($point_color, 4, 2));
$line = array('width' => 1.25, 'color' => array($red, $green, $blue));
// Trim to remove leading 'POINT(' and trailing ')'
$point = substr($spatial, 6, (strlen($spatial) - 7));
$points_arr = $this->extractPoints($point, $scale_data);
// draw a small circle to mark the point
if ($points_arr[0][0] != '' && $points_arr[0][1] != '') {
$pdf->Circle($points_arr[0][0], $points_arr[0][1], 2, 0, 360, 'D', $line);
// print label if applicable
if (isset($label) && trim($label) != '') {
$pdf->SetXY($points_arr[0][0], $points_arr[0][1]);
$pdf->SetFontSize(5);
$pdf->Cell(0, 0, trim($label));
}
}
return $pdf;
}
/**
* Prepares and returns the code related to a row in the GIS dataset as SVG.
*
* @param string $spatial GIS POINT object
* @param string $label Label for the GIS POINT object
* @param string $point_color Color for the GIS POINT object
* @param array $scale_data Array containing data related to scaling
*
* @return the code related to a row in the GIS dataset
*/
public function prepareRowAsSvg($spatial, $label, $point_color, $scale_data)
{
$point_options = array(
'name' => $label,
'id' => $label . rand(),
'class' => 'point vector',
'fill' => 'white',
'stroke' => $point_color,
'stroke-width'=> 2,
);
// Trim to remove leading 'POINT(' and trailing ')'
$point = substr($spatial, 6, (strlen($spatial) - 7));
$points_arr = $this->extractPoints($point, $scale_data);
$row = '';
if ($points_arr[0][0] != '' && $points_arr[0][1] != '') {
$row .= '<circle cx="' . $points_arr[0][0] . '" cy="' . $points_arr[0][1] . '" r="3"';
foreach ($point_options as $option => $val) {
$row .= ' ' . $option . '="' . trim($val) . '"';
}
$row .= '/>';
}
return $row;
}
/**
* Prepares JavaScript related to a row in the GIS dataset
* to visualize it with OpenLayers.
*
* @param string $spatial GIS POINT object
* @param int $srid Spatial reference ID
* @param string $label Label for the GIS POINT object
* @param string $point_color Color for the GIS POINT object
* @param array $scale_data Array containing data related to scaling
*
* @return JavaScript related to a row in the GIS dataset
*/
public function prepareRowAsOl($spatial, $srid, $label, $point_color, $scale_data)
{
$style_options = array(
'pointRadius' => 3,
'fillColor' => '#ffffff',
'strokeColor' => $point_color,
'strokeWidth' => 2,
'label' => $label,
'labelYOffset' => -8,
'fontSize' => 10,
);
if ($srid == 0) {
$srid = 4326;
}
$result = $this->getBoundsForOl($srid, $scale_data);
// Trim to remove leading 'POINT(' and trailing ')'
$point = substr($spatial, 6, (strlen($spatial) - 7));
$points_arr = $this->extractPoints($point, null);
if ($points_arr[0][0] != '' && $points_arr[0][1] != '') {
$result .= 'vectorLayer.addFeatures(new OpenLayers.Feature.Vector(('
. 'new OpenLayers.Geometry.Point(' . $points_arr[0][0] . ', '
. $points_arr[0][1] . ').transform(new OpenLayers.Projection("EPSG:'
. $srid . '"), map.getProjectionObject())), null, '
. json_encode($style_options) . '));';
}
return $result;
}
/**
* Generate 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 Point deos not adhere to this parameter
*
* @return WKT with the set of parameters passed by the GIS editor
*/
public function generateWkt($gis_data, $index, $empty = '')
{
return 'POINT('
. ((isset($gis_data[$index]['POINT']['x']) && trim($gis_data[$index]['POINT']['x']) != '')
? $gis_data[$index]['POINT']['x'] : '') . ' '
. ((isset($gis_data[$index]['POINT']['y']) && trim($gis_data[$index]['POINT']['y']) != '')
? $gis_data[$index]['POINT']['y'] : '') . ')';
}
/**
* Generate the WKT for the data from ESRI shape files.
*
* @param array $row_data GIS data
*
* @return the WKT for the data from ESRI shape files
*/
public function getShape($row_data)
{
return 'POINT(' . (isset($row_data['x']) ? $row_data['x'] : '')
. ' ' . (isset($row_data['y']) ? $row_data['y'] : '') . ')';
}
/**
* Generate parameters for the GIS data editor from the value of the GIS column.
*
* @param string $value of the GIS column
* @param index $index of the geometry
*
* @return parameters for the GIS data editor from the value of the GIS column
*/
public function generateParams($value, $index = -1)
{
if ($index == -1) {
$index = 0;
$params = array();
$data = PMA_GIS_Geometry::generateParams($value);
$params['srid'] = $data['srid'];
$wkt = $data['wkt'];
} else {
$params[$index]['gis_type'] = 'POINT';
$wkt = $value;
}
// Trim to remove leading 'POINT(' and trailing ')'
$point = substr($wkt, 6, (strlen($wkt) - 7));
$points_arr = $this->extractPoints($point, null);
$params[$index]['POINT']['x'] = $points_arr[0][0];
$params[$index]['POINT']['y'] = $points_arr[0][1];
return $params;
}
}
?>

View File

@ -0,0 +1,511 @@
<?php
/**
* Handles the visualization of GIS POLYGON objects.
*
* @package PhpMyAdmin-GIS
*/
class PMA_GIS_Polygon extends PMA_GIS_Geometry
{
// Hold the singleton instance of the class
private static $_instance;
/**
* A private constructor; prevents direct creation of object.
*/
private function __construct()
{
}
/**
* Returns the singleton.
*
* @return the singleton
*/
public static function singleton()
{
if (!isset(self::$_instance)) {
$class = __CLASS__;
self::$_instance = new $class;
}
return self::$_instance;
}
/**
* Scales each row.
*
* @param string $spatial spatial data of a row
*
* @return array containing the min, max values for x and y cordinates
*/
public function scaleRow($spatial)
{
// Trim to remove leading 'POLYGON((' and trailing '))'
$polygon = substr($spatial, 9, (strlen($spatial) - 11));
// If the polygon doesn't have an inner ring, use polygon itself
if (strpos($polygon, "),(") === false) {
$ring = $polygon;
} else {
// Seperate outer ring and use it to determin min-max
$parts = explode("),(", $polygon);
$ring = $parts[0];
}
return $this->setMinMax($ring, array());
}
/**
* Adds to the PNG image object, the data related to a row in the GIS dataset.
*
* @param string $spatial GIS POLYGON object
* @param string $label Label for the GIS POLYGON object
* @param string $fill_color Color for the GIS POLYGON object
* @param array $scale_data Array containing data related to scaling
* @param image $image Image object
*
* @return the modified image object
*/
public function prepareRowAsPng($spatial, $label, $fill_color, $scale_data, $image)
{
// allocate colors
$black = imagecolorallocate($image, 0, 0, 0);
$red = hexdec(substr($fill_color, 1, 2));
$green = hexdec(substr($fill_color, 3, 2));
$blue = hexdec(substr($fill_color, 4, 2));
$color = imagecolorallocate($image, $red, $green, $blue);
// Trim to remove leading 'POLYGON((' and trailing '))'
$polygon = substr($spatial, 9, (strlen($spatial) - 11));
// If the polygon doesnt have an inner polygon
if (strpos($polygon, "),(") === false) {
$points_arr = $this->extractPoints($polygon, $scale_data, true);
} else {
// Seperate outer and inner polygons
$parts = explode("),(", $polygon);
$outer = $parts[0];
$inner = array_slice($parts, 1);
$points_arr = $this->extractPoints($outer, $scale_data, true);
foreach ($inner as $inner_poly) {
$points_arr = array_merge(
$points_arr, $this->extractPoints($inner_poly, $scale_data, true)
);
}
}
// draw polygon
imagefilledpolygon($image, $points_arr, sizeof($points_arr) / 2, $color);
// print label if applicable
if (isset($label) && trim($label) != '') {
imagestring($image, 1, $points_arr[2], $points_arr[3], trim($label), $black);
}
return $image;
}
/**
* Adds to the TCPDF instance, the data related to a row in the GIS dataset.
*
* @param string $spatial GIS POLYGON object
* @param string $label Label for the GIS POLYGON object
* @param string $fill_color Color for the GIS POLYGON object
* @param array $scale_data Array containing data related to scaling
* @param image $pdf TCPDF instance
*
* @return the modified TCPDF instance
*/
public function prepareRowAsPdf($spatial, $label, $fill_color, $scale_data, $pdf)
{
// allocate colors
$red = hexdec(substr($fill_color, 1, 2));
$green = hexdec(substr($fill_color, 3, 2));
$blue = hexdec(substr($fill_color, 4, 2));
$color = array($red, $green, $blue);
// Trim to remove leading 'POLYGON((' and trailing '))'
$polygon = substr($spatial, 9, (strlen($spatial) - 11));
// If the polygon doesnt have an inner polygon
if (strpos($polygon, "),(") === false) {
$points_arr = $this->extractPoints($polygon, $scale_data, true);
} else {
// Seperate outer and inner polygons
$parts = explode("),(", $polygon);
$outer = $parts[0];
$inner = array_slice($parts, 1);
$points_arr = $this->extractPoints($outer, $scale_data, true);
foreach ($inner as $inner_poly) {
$points_arr = array_merge(
$points_arr, $this->extractPoints($inner_poly, $scale_data, true)
);
}
}
// draw polygon
$pdf->Polygon($points_arr, 'F*', array(), $color, true);
// print label if applicable
if (isset($label) && trim($label) != '') {
$pdf->SetXY($points_arr[2], $points_arr[3]);
$pdf->SetFontSize(5);
$pdf->Cell(0, 0, trim($label));
}
return $pdf;
}
/**
* Prepares and returns the code related to a row in the GIS dataset as SVG.
*
* @param string $spatial GIS POLYGON object
* @param string $label Label for the GIS POLYGON object
* @param string $fill_color Color for the GIS POLYGON object
* @param array $scale_data Array containing data related to scaling
*
* @return the code related to a row in the GIS dataset
*/
public function prepareRowAsSvg($spatial, $label, $fill_color, $scale_data)
{
$polygon_options = array(
'name' => $label,
'id' => $label . rand(),
'class' => 'polygon vector',
'stroke' => 'black',
'stroke-width'=> 0.5,
'fill' => $fill_color,
'fill-rule' => 'evenodd',
'fill-opacity'=> 0.8,
);
// Trim to remove leading 'POLYGON((' and trailing '))'
$polygon = substr($spatial, 9, (strlen($spatial) - 11));
$row = '<path d="';
// If the polygon doesnt have an inner polygon
if (strpos($polygon, "),(") === false) {
$row .= $this->_drawPath($polygon, $scale_data);
} else {
// Seperate outer and inner polygons
$parts = explode("),(", $polygon);
$outer = $parts[0];
$inner = array_slice($parts, 1);
$row .= $this->_drawPath($outer, $scale_data);
foreach ($inner as $inner_poly) {
$row .= $this->_drawPath($inner_poly, $scale_data);
}
}
$row .= '"';
foreach ($polygon_options as $option => $val) {
$row .= ' ' . $option . '="' . trim($val) . '"';
}
$row .= '/>';
return $row;
}
/**
* Prepares JavaScript related to a row in the GIS dataset
* to visualize it with OpenLayers.
*
* @param string $spatial GIS POLYGON object
* @param int $srid Spatial reference ID
* @param string $label Label for the GIS POLYGON object
* @param string $fill_color Color for the GIS POLYGON object
* @param array $scale_data Array containing data related to scaling
*
* @return JavaScript related to a row in the GIS dataset
*/
public function prepareRowAsOl($spatial, $srid, $label, $fill_color, $scale_data)
{
$style_options = array(
'strokeColor' => '#000000',
'strokeWidth' => 0.5,
'fillColor' => $fill_color,
'fillOpacity' => 0.8,
'label' => $label,
'fontSize' => 10,
);
if ($srid == 0) {
$srid = 4326;
}
$row = $this->getBoundsForOl($srid, $scale_data);
// Trim to remove leading 'POLYGON((' and trailing '))'
$polygon = substr($spatial, 9, (strlen($spatial) - 11));
$row .= 'vectorLayer.addFeatures(new OpenLayers.Feature.Vector(';
$row .= $this->addPointsForOpenLayersPolygon($polygon, $srid);
$row .= 'null, ' . json_encode($style_options) . '));';
return $row;
}
/**
* Draws a ring of the polygon using SVG path element.
*
* @param string $polygon The ring
* @param array $scale_data Array containing data related to scaling
*
* @return the code to draw the ring
*/
private function _drawPath($polygon, $scale_data)
{
$points_arr = $this->extractPoints($polygon, $scale_data);
$row = ' M ' . $points_arr[0][0] . ', ' . $points_arr[0][1];
$other_points = array_slice($points_arr, 1, count($points_arr) - 2);
foreach ($other_points as $point) {
$row .= ' L ' . $point[0] . ', ' . $point[1];
}
$row .= ' Z ';
return $row;
}
/**
* Generate 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 WKT with the set of parameters passed by the GIS editor
*/
public function generateWkt($gis_data, $index, $empty = '')
{
$no_of_lines = isset($gis_data[$index]['POLYGON']['no_of_lines'])
? $gis_data[$index]['POLYGON']['no_of_lines'] : 1;
if ($no_of_lines < 1) {
$no_of_lines = 1;
}
$wkt = 'POLYGON(';
for ($i = 0; $i < $no_of_lines; $i++) {
$no_of_points = isset($gis_data[$index]['POLYGON'][$i]['no_of_points'])
? $gis_data[$index]['POLYGON'][$i]['no_of_points'] : 4;
if ($no_of_points < 4) {
$no_of_points = 4;
}
$wkt .= '(';
for ($j = 0; $j < $no_of_points; $j++) {
$wkt .= ((isset($gis_data[$index]['POLYGON'][$i][$j]['x'])
&& trim($gis_data[$index]['POLYGON'][$i][$j]['x']) != '')
? $gis_data[$index]['POLYGON'][$i][$j]['x'] : $empty)
. ' ' . ((isset($gis_data[$index]['POLYGON'][$i][$j]['y'])
&& trim($gis_data[$index]['POLYGON'][$i][$j]['y']) != '')
? $gis_data[$index]['POLYGON'][$i][$j]['y'] : $empty) .',';
}
$wkt = substr($wkt, 0, strlen($wkt) - 1);
$wkt .= '),';
}
$wkt = substr($wkt, 0, strlen($wkt) - 1);
$wkt .= ')';
return $wkt;
}
/**
* Calculates the area of a closed simple polygon.
*
* @param array $ring array of points forming the ring
*
* @return the area of a closed simple polygon.
*/
public static function area($ring)
{
$no_of_points = count($ring);
// If the last point is same as the first point ignore it
$last = count($ring) - 1;
if (($ring[0]['x'] == $ring[$last]['x'])
&& ($ring[0]['y'] == $ring[$last]['y'])
) {
$no_of_points--;
}
// _n-1
// A = _1_ \ (X(i) * Y(i+1)) - (Y(i) * X(i+1))
// 2 /__
// i=0
$area = 0;
for ($i = 0; $i < $no_of_points; $i++) {
$j = ($i + 1) % $no_of_points;
$area += $ring[$i]['x'] * $ring[$j]['y'];
$area -= $ring[$i]['y'] * $ring[$j]['x'];
}
$area /= 2.0;
return $area;
}
/**
* Determines whether a set of points represents an outer ring.
* If points are in clockwise orientation then, they form an outer ring.
*
* @param array $ring array of points forming the ring
*
* @return whether a set of points represents an outer ring.
*/
public static function isOuterRing($ring)
{
// If area is negative then it's in clockwise orientation,
// i.e. it's an outer ring
if (PMA_GIS_Polygon::area($ring) < 0) {
return true;
}
return false;
}
/**
* Determines whether a given point is inside a given polygon.
*
* @param array $point x, y coordinates of the point
* @param array $polygon array of points forming the ring
*
* @return whether a given point is inside a given polygon
*/
public static function isPointInsidePolygon($point, $polygon)
{
// If first point is repeated at the end remove it
$last = count($polygon) - 1;
if (($polygon[0]['x'] == $polygon[$last]['x'])
&& ($polygon[0]['y'] == $polygon[$last]['y'])
) {
$polygon = array_slice($polygon, 0, $last);
}
$no_of_points = count($polygon);
$counter = 0;
// Use ray casting algorithm
$p1 = $polygon[0];
for ($i = 1; $i <= $no_of_points; $i++) {
$p2 = $polygon[$i % $no_of_points];
if ($point['y'] > min(array($p1['y'], $p2['y']))) {
if ($point['y'] <= max(array($p1['y'], $p2['y']))) {
if ($point['x'] <= max(array($p1['x'], $p2['x']))) {
if ($p1['y'] != $p2['y']) {
$xinters = ($point['y'] - $p1['y'])
* ($p2['x'] - $p1['x'])
/ ($p2['y'] - $p1['y']) + $p1['x'];
if ($p1['x'] == $p2['x'] || $point['x'] <= $xinters) {
$counter++;
}
}
}
}
}
$p1 = $p2;
}
if ($counter % 2 == 0) {
return false;
} else {
return true;
}
}
/**
* Returns a point that is guaranteed to be on the surface of the ring.
* (for simple closed rings)
*
* @param array $ring array of points forming the ring
*
* @return a point on the surface of the ring
*/
public static function getPointOnSurface($ring)
{
// Find two consecutive distinct points.
for ($i = 0; $i < count($ring) - 1; $i++) {
if ($ring[$i]['y'] != $ring[$i + 1]['y']) {
$x0 = $ring[$i]['x'];
$x1 = $ring[$i + 1]['x'];
$y0 = $ring[$i]['y'];
$y1 = $ring[$i + 1]['y'];
break;
}
}
if (! isset($x0)) {
return false;
}
// Find the mid point
$x2 = ($x0 + $x1) / 2;
$y2 = ($y0 + $y1) / 2;
// Always keep $epsilon < 1 to go with the reduction logic down here
$epsilon = 0.1;
$denominator = sqrt(pow(($y1 - $y0), 2) + pow(($x0 - $x1), 2));
$pointA = array(); $pointB = array();
while (true) {
// Get the points on either sides of the line
// with a distance of epsilon to the mid point
$pointA['x'] = $x2 + ($epsilon * ($y1 - $y0)) / $denominator;
$pointA['y'] = $y2 + ($pointA['x'] - $x2) * ($x0 - $x1) / ($y1 - $y0);
$pointB['x'] = $x2 + ($epsilon * ($y1 - $y0)) / (0 - $denominator);
$pointB['y'] = $y2 + ($pointB['x'] - $x2) * ($x0 - $x1) / ($y1 - $y0);
// One of the points should be inside the polygon,
// unless epcilon chosen is too large
if (PMA_GIS_Polygon::isPointInsidePolygon($pointA, $ring)) {
return $pointA;
} elseif (PMA_GIS_Polygon::isPointInsidePolygon($pointB, $ring)) {
return $pointB;
} else {
//If both are outside the polygon reduce the epsilon and
//recalculate the points(reduce exponentially for faster convergance)
$epsilon = pow($epsilon, 2);
if ($epsilon == 0) {
return false;
}
}
}
}
/** Generate parameters for the GIS data editor from the value of the GIS column.
*
* @param string $value of the GIS column
* @param index $index of the geometry
*
* @return parameters for the GIS data editor from the value of the GIS column
*/
public function generateParams($value, $index = -1)
{
if ($index == -1) {
$index = 0;
$params = array();
$data = PMA_GIS_Geometry::generateParams($value);
$params['srid'] = $data['srid'];
$wkt = $data['wkt'];
} else {
$params[$index]['gis_type'] = 'POLYGON';
$wkt = $value;
}
// Trim to remove leading 'POLYGON((' and trailing '))'
$polygon = substr($wkt, 9, (strlen($wkt) - 11));
// Seperate each linestring
$linerings = explode("),(", $polygon);
$params[$index]['POLYGON']['no_of_lines'] = count($linerings);
$j = 0;
foreach ($linerings as $linering) {
$points_arr = $this->extractPoints($linering, null);
$no_of_points = count($points_arr);
$params[$index]['POLYGON'][$j]['no_of_points'] = $no_of_points;
for ($i = 0; $i < $no_of_points; $i++) {
$params[$index]['POLYGON'][$j][$i]['x'] = $points_arr[$i][0];
$params[$index]['POLYGON'][$j][$i]['y'] = $points_arr[$i][1];
}
$j++;
}
return $params;
}
}
?>

View File

@ -0,0 +1,464 @@
<?php
/**
* Generates the JavaScripts needed to visualize GIS data.
*
* @package PhpMyAdmin-GIS
*/
class PMA_GIS_Visualization
{
/**
* @var array Raw data for the visualization
*/
private $_data;
/**
* @var array Set of default settigs values are here.
*/
private $_settings = array(
// Array of colors to be used for GIS visualizations.
'colors' => array(
'#B02EE0',
'#E0642E',
'#E0D62E',
'#2E97E0',
'#BCE02E',
'#E02E75',
'#5CE02E',
'#E0B02E',
'#0022E0',
'#726CB1',
'#481A36',
'#BAC658',
'#127224',
'#825119',
'#238C74',
'#4C489B',
'#87C9BF',
),
// The width of the GIS visualization.
'width' => 600,
// The height of the GIS visualization.
'height' => 450,
);
/**
* @var array Options that the user has specified.
*/
private $_userSpecifiedSettings = null;
/**
* Returns the settings array
*
* @return the settings array.
*/
public function getSettings()
{
return $this->_settings;
}
/**
* Constructor. Stores user specified options.
*
* @param array $data Data for the visualization
* @param array $options Users specified options
*/
public function __construct($data, $options)
{
$this->_userSpecifiedSettings = $options;
$this->_data = $data;
}
/**
* All the variable initialization, options handling has to be done here.
*
* @return nothing
*/
protected function init()
{
$this->_handleOptions();
}
/**
* A function which handles passed parameters. Useful if desired
* chart needs to be a little bit different from the default one.
*
* @return nothing
*/
private function _handleOptions()
{
if (! is_null($this->_userSpecifiedSettings)) {
$this->_settings = array_merge($this->_settings, $this->_userSpecifiedSettings);
}
}
/**
* Sanitizes the file name.
*
* @param string $file_name file name
* @param string $ext extension of the file
*
* @return the sanitized file name
*/
private function _sanitizeName($file_name, $ext)
{
$file_name = PMA_sanitize_filename($file_name);
// Check if the user already added extension;
// get the substring where the extension would be if it was included
$extension_start_pos = strlen($file_name) - strlen($ext) - 1;
$user_extension = substr($file_name, $extension_start_pos, strlen($file_name));
$required_extension = "." . $ext;
if (strtolower($user_extension) != $required_extension) {
$file_name .= $required_extension;
}
return $file_name;
}
/**
* Handles common tasks of writing the visualization to file for various formats.
*
* @param string $file_name file name
* @param string $type mime type
* @param string $ext extension of the file
*
* @return nothing
*/
private function _toFile($file_name, $type, $ext)
{
$file_name = $this->_sanitizeName($file_name, $ext);
ob_clean();
PMA_download_header($file_name, $type);
}
/**
* Generate the visualization in SVG format.
*
* @return the generated image resource
*/
private function _svg()
{
$this->init();
$output = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>' . "\n";
$output .= '<svg version="1.1" xmlns:svg="http://www.w3.org/2000/svg"'
. ' xmlns="http://www.w3.org/2000/svg" width="' . $this->_settings['width'] . '"'
. ' height="' . $this->_settings['height'] . '">';
$output .= '<g id="groupPanel">';
$scale_data = $this->_scaleDataSet($this->_data);
$output .= $this->_prepareDataSet($this->_data, $scale_data, 'svg', '');
$output .= '</g>';
$output .= '</svg>';
return $output;
}
/**
* Get the visualization as a SVG.
*
* @return the visualization as a SVG
*/
public function asSVG()
{
$output = $this->_svg();
return $output;
}
/**
* Saves as a SVG image to a file.
*
* @param string $file_name File name
*
* @return nothing
*/
public function toFileAsSvg($file_name)
{
$img = $this->_svg();
$this->_toFile($file_name, 'image/svg+xml', 'svg');
echo($img);
}
/**
* Generate the visualization in PNG format.
*
* @return the generated image resource
*/
private function _png()
{
$this->init();
// create image
$image = imagecreatetruecolor($this->_settings['width'], $this->_settings['height']);
// fill the background
$bg = imagecolorallocate($image, 229, 229, 229);
imagefilledrectangle(
$image, 0, 0, $this->_settings['width'] - 1,
$this->_settings['height'] - 1, $bg
);
$scale_data = $this->_scaleDataSet($this->_data);
$image = $this->_prepareDataSet($this->_data, $scale_data, 'png', $image);
return $image;
}
/**
* Get the visualization as a PNG.
*
* @return the visualization as a PNG
*/
public function asPng()
{
$img = $this->_png();
// render and save it to variable
ob_start();
imagepng($img, null, 9, PNG_ALL_FILTERS);
imagedestroy($img);
$output = ob_get_contents();
ob_end_clean();
// base64 encode
$encoded = base64_encode($output);
return '<img src="data:image/png;base64,'. $encoded .'" />';
}
/**
* Saves as a PNG image to a file.
*
* @param string $file_name File name
*
* @return nothing
*/
public function toFileAsPng($file_name)
{
$img = $this->_png();
$this->_toFile($file_name, 'image/png', 'png');
imagepng($img, null, 9, PNG_ALL_FILTERS);
imagedestroy($img);
}
/**
* Get the code for visualization with OpenLayers.
*
* @return the code for visualization with OpenLayers
*/
public function asOl()
{
$this->init();
$scale_data = $this->_scaleDataSet($this->_data);
$output
= 'var options = {'
. 'projection: new OpenLayers.Projection("EPSG:900913"),'
. 'displayProjection: new OpenLayers.Projection("EPSG:4326"),'
. 'units: "m",'
. 'numZoomLevels: 18,'
. 'maxResolution: 156543.0339,'
. 'maxExtent: new OpenLayers.Bounds(-20037508, -20037508, 20037508, 20037508),'
. 'restrictedExtent: new OpenLayers.Bounds(-20037508, -20037508, 20037508, 20037508)'
. '};'
. 'var map = new OpenLayers.Map("openlayersmap", options);'
. 'var layerNone = new OpenLayers.Layer.Boxes("None", {isBaseLayer: true});'
. 'var layerMapnik = new OpenLayers.Layer.OSM.Mapnik("Mapnik");'
. 'var layerOsmarender = new OpenLayers.Layer.OSM.Osmarender("Osmarender");'
. 'var layerCycleMap = new OpenLayers.Layer.OSM.CycleMap("CycleMap");'
. 'map.addLayers([layerMapnik, layerOsmarender, layerCycleMap, layerNone]);'
. 'var vectorLayer = new OpenLayers.Layer.Vector("Data");'
. 'var bound;';
$output .= $this->_prepareDataSet($this->_data, $scale_data, 'ol', '');
$output .=
'map.addLayer(vectorLayer);'
. 'map.zoomToExtent(bound);'
. 'if (map.getZoom() < 2) {'
. 'map.zoomTo(2);'
. '}'
. 'map.addControl(new OpenLayers.Control.LayerSwitcher());'
. 'map.addControl(new OpenLayers.Control.MousePosition());';
return $output;
}
/**
* Saves as a PDF to a file.
*
* @param string $file_name File name
*
* @return nothing
*/
public function toFileAsPdf($file_name)
{
$this->init();
include_once './libraries/tcpdf/tcpdf.php';
// create pdf
$pdf = new TCPDF('', 'pt', $GLOBALS['cfg']['PDFDefaultPageSize'], true, 'UTF-8', false);
// disable header and footer
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
//set auto page breaks
$pdf->SetAutoPageBreak(false);
// add a page
$pdf->AddPage();
$scale_data = $this->_scaleDataSet($this->_data);
$pdf = $this->_prepareDataSet($this->_data, $scale_data, 'pdf', $pdf);
// sanitize file name
$file_name = $this->_sanitizeName($file_name, 'pdf');
ob_clean();
$pdf->Output($file_name, 'D');
}
/**
* Calculates the scale, horizontal and vertical offset that should be used.
*
* @param array $data Row data
*
* @return an array containing the scale, x and y offsets
*/
private function _scaleDataSet($data)
{
$min_max = array();
$border = 15;
// effective width and height of the plot
$plot_width = $this->_settings['width'] - 2 * $border;
$plot_height = $this->_settings['height'] - 2 * $border;
foreach ($data as $row) {
// Figure out the data type
$ref_data = $row[$this->_settings['spatialColumn']];
$type_pos = stripos($ref_data, '(');
$type = substr($ref_data, 0, $type_pos);
$gis_obj = PMA_GIS_Factory::factory($type);
if (! $gis_obj) {
continue;
}
$scale_data = $gis_obj->scaleRow($row[$this->_settings['spatialColumn']]);
// Upadate minimum/maximum values for x and y cordinates.
$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;
}
}
// scale the visualization
$x_ratio = ($min_max['maxX'] - $min_max['minX']) / $plot_width;
$y_ratio = ($min_max['maxY'] - $min_max['minY']) / $plot_height;
$ratio = ($x_ratio > $y_ratio) ? $x_ratio : $y_ratio;
$scale = ($ratio != 0) ? (1 / $ratio) : 1;
if ($x_ratio < $y_ratio) {
// center horizontally
$x = ($min_max['maxX'] + $min_max['minX'] - $plot_width / $scale) / 2;
// fit vertically
$y = $min_max['minY'] - ($border / $scale);
} else {
// fit horizontally
$x = $min_max['minX'] - ($border / $scale);
// center vertically
$y =($min_max['maxY'] + $min_max['minY'] - $plot_height / $scale) / 2;
}
return array(
'scale' => $scale,
'x' => $x,
'y' => $y,
'minX' => $min_max['minX'],
'maxX' => $min_max['maxX'],
'minY' => $min_max['minY'],
'maxY' => $min_max['maxY'],
'height' => $this->_settings['height'],
);
}
/**
* Prepares and return the dataset as needed by the visualization.
*
* @param array $data Raw data
* @param array $scale_data Data related to scaling
* @param string $format Format of the visulaization
* @param image $results Image object in the case of png
*
* @return the formatted array of data.
*/
private function _prepareDataSet($data, $scale_data, $format, $results)
{
$color_number = 0;
// loop through the rows
foreach ($data as $row) {
$index = $color_number % sizeof($this->_settings['colors']);
// Figure out the data type
$ref_data = $row[$this->_settings['spatialColumn']];
$type_pos = stripos($ref_data, '(');
$type = substr($ref_data, 0, $type_pos);
$gis_obj = PMA_GIS_Factory::factory($type);
if (! $gis_obj) {
continue;
}
$label = '';
if (isset($this->_settings['labelColumn'])
&& isset($row[$this->_settings['labelColumn']])
) {
$label = $row[$this->_settings['labelColumn']];
}
if ($format == 'svg') {
$results .= $gis_obj->prepareRowAsSvg(
$row[$this->_settings['spatialColumn']], $label,
$this->_settings['colors'][$index], $scale_data
);
} elseif ($format == 'png') {
$results = $gis_obj->prepareRowAsPng(
$row[$this->_settings['spatialColumn']], $label,
$this->_settings['colors'][$index], $scale_data, $results
);
} elseif ($format == 'pdf') {
$results = $gis_obj->prepareRowAsPdf(
$row[$this->_settings['spatialColumn']], $label,
$this->_settings['colors'][$index], $scale_data, $results
);
} elseif ($format == 'ol') {
$results .= $gis_obj->prepareRowAsOl(
$row[$this->_settings['spatialColumn']], $row['srid'],
$label, $this->_settings['colors'][$index], $scale_data
);
}
$color_number++;
}
return $results;
}
}
?>