Skip to content

Commit

Permalink
Visualize GIS data with OpenStreetMap as a base layer
Browse files Browse the repository at this point in the history
  • Loading branch information
madhuracj committed Jun 12, 2011
1 parent 7fca97f commit 5f09cf5
Show file tree
Hide file tree
Showing 14 changed files with 416 additions and 12 deletions.
29 changes: 29 additions & 0 deletions js/tbl_gis_visualization.js
Expand Up @@ -62,6 +62,35 @@ function zoomAndPan() {
* Displaying tooltips for GIS objects.
*/
$(document).ready(function() {
var $placeholder = $('#placeholder');
var $openlayersmap = $('#openlayersmap');

if ($('#choice').prop('checked') != true) {
$openlayersmap.hide();
} else {
$placeholder.hide();
}

var cssObj = {
'border' : '1px solid #aaa',
'width' : $placeholder.width(),
'height' : $placeholder.height(),
'float' : 'right'
};
$openlayersmap.css(cssObj);
drawOpenLayers();

$('.choice').show();
$('#choice').bind('click', function() {
if ($(this).prop('checked') == false) {
$placeholder.show();
$openlayersmap.hide();
} else {
$placeholder.hide();
$openlayersmap.show();
}
});

$('#placeholder').svg({
onLoad: function(svg_ref) {
svg = svg_ref;
Expand Down
10 changes: 8 additions & 2 deletions libraries/gis/pma_gis_geometry.php
Expand Up @@ -95,8 +95,14 @@ protected function extractPoints($point_set, $scale_data, $linear = false)
// Extract cordinates of the point
$cordinates = explode(" ", $point);

$x = ($cordinates[0] - $scale_data['x']) * $scale_data['scale'];
$y = $scale_data['height'] - ($cordinates[1] - $scale_data['y']) * $scale_data['scale'];
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 = $cordinates[0];
$y = $cordinates[1];
}

if (! $linear) {
$points_arr[] = array($x, $y);
} else {
Expand Down
29 changes: 29 additions & 0 deletions libraries/gis/pma_gis_geometrycollection.php
Expand Up @@ -164,6 +164,35 @@ public function prepareRowAsSvg($spatial, $label, $color, $scale_data)
return $row;
}

/**
* Prepares the code 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
*
* @return the code related to a row in the GIS dataset
*/
public function prepareRowAsOl($spatial, $srid, $label, $color)
{
$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);
$row .= $gis_obj->prepareRowAsOl($sub_part, $srid, $label, $color);
}
return $row;
}

/**
* Split the GEOMETRYCOLLECTION object and get its constituents.
*
Expand Down
36 changes: 36 additions & 0 deletions libraries/gis/pma_gis_linestring.php
Expand Up @@ -152,5 +152,41 @@ public function prepareRowAsSvg($spatial, $label, $line_color, $scale_data)

return $row;
}

/**
* Prepares the code 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
*
* @return the code related to a row in the GIS dataset
*/
public function prepareRowAsOl($spatial, $srid, $label, $line_color)
{
$style_options = array(
'strokeColor' => $line_color,
'strokeWidth' => 2,
);
if ($srid == 0) {
$srid = 4326;
}
// 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 .= ')';

return 'vectorLayer.addFeatures(new OpenLayers.Feature.Vector('
. 'new OpenLayers.Geometry.LineString(' . $row . '), null, '
. json_encode($style_options) . '));';
}
}
?>
41 changes: 41 additions & 0 deletions libraries/gis/pma_gis_multilinestring.php
Expand Up @@ -177,5 +177,46 @@ public function prepareRowAsSvg($spatial, $label, $line_color, $scale_data)

return $row;
}

/**
* Prepares the code 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
*
* @return the code related to a row in the GIS dataset
*/
public function prepareRowAsOl($spatial, $srid, $label, $line_color)
{
$style_options = array(
'strokeColor' => $line_color,
'strokeWidth' => 2,
);
if ($srid == 0) {
$srid = 4326;
}
// 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;
}
}
?>
38 changes: 38 additions & 0 deletions libraries/gis/pma_gis_multipoint.php
Expand Up @@ -141,5 +141,43 @@ public function prepareRowAsSvg($spatial, $label, $point_color, $scale_data)

return $row;
}

/**
* Prepares the code 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
*
* @return the code related to a row in the GIS dataset
*/
public function prepareRowAsOl($spatial, $srid, $label, $point_color)
{
$style_options = array(
'pointRadius' => 3,
'fillColor' => '#ffffff',
'strokeColor' => $point_color,
'strokeWidth' => 2,
);
if ($srid == 0) {
$srid = 4326;
}
// 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) {
$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 .= ')';

return 'vectorLayer.addFeatures(new OpenLayers.Feature.Vector('
. 'new OpenLayers.Geometry.MultiPoint(' . $row . '), null, '
. json_encode($style_options) . '));';
}
}
?>
63 changes: 63 additions & 0 deletions libraries/gis/pma_gis_multipolygon.php
Expand Up @@ -222,6 +222,69 @@ public function prepareRowAsSvg($spatial, $label, $fill_color, $scale_data)
return $row;
}

/**
* Prepares the code 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
*
* @return the code related to a row in the GIS dataset
*/
public function prepareRowAsOl($spatial, $srid, $label, $fill_color)
{
$style_options = array(
'strokeColor' => '#000000',
'strokeWidth' => 0.5,
'fillColor' => $fill_color,
'fillOpacity' => 0.8,
);
if ($srid == 0) {
$srid = 4326;
}
// 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 .= '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 .= ')), ';
}
$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.
*
Expand Down
31 changes: 31 additions & 0 deletions libraries/gis/pma_gis_point.php
Expand Up @@ -134,5 +134,36 @@ public function prepareRowAsSvg($spatial, $label, $point_color, $scale_data)

return $row;
}

/**
* Prepares the code 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
*
* @return the code related to a row in the GIS dataset
*/
public function prepareRowAsOl($spatial, $srid, $label, $point_color)
{
$style_options = array(
'pointRadius' => 3,
'fillColor' => '#ffffff',
'strokeColor' => $point_color,
'strokeWidth' => 2,
);
if ($srid == 0) {
$srid = 4326;
}
// Trim to remove leading 'POINT(' and trailing ')'
$point = substr($spatial, 6, (strlen($spatial) - 7));
$points_arr = $this->extractPoints($point, null);

return '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) . '));';
}
}
?>
56 changes: 55 additions & 1 deletion libraries/gis/pma_gis_polygon.php
Expand Up @@ -165,7 +165,6 @@ public function prepareRowAsPdf($spatial, $label, $fill_color, $scale_data, $pdf
*/
public function prepareRowAsSvg($spatial, $label, $fill_color, $scale_data)
{
$group_name = 'g';
$polygon_options = array(
'name' => $label,
'id' => $label . rand(),
Expand Down Expand Up @@ -206,6 +205,61 @@ public function prepareRowAsSvg($spatial, $label, $fill_color, $scale_data)
return $row;
}

/**
* Prepares the code 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
*
* @return the code related to a row in the GIS dataset
*/
public function prepareRowAsOl($spatial, $srid, $label, $fill_color)
{
$style_options = array(
'strokeColor' => '#000000',
'strokeWidth' => 0.5,
'fillColor' => $fill_color,
'fillOpacity' => 0.8,
);
if ($srid == 0) {
$srid = 4326;
}
// Trim to remove leading 'POLYGON((' and trailing '))'
$polygon = substr($spatial, 9, (strlen($spatial) - 11));

$row = 'vectorLayer.addFeatures(new OpenLayers.Feature.Vector('
. '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 .= ')), null, ' . json_encode($style_options) . '));';
return $row;
}

/**
* Draws a ring of the polygon using SVG path element.
*
Expand Down

0 comments on commit 5f09cf5

Please sign in to comment.