Add and Remove operations for between stops
--- /dev/null
+++ b/betweenpoint.add.php
@@ -1,1 +1,50 @@
+<?php
+ /*
+ * GeoPo Encode in PHP
+ * @author : Shintaro Inagaki
+ * @param $location (Array)
+ * @return $geopo (String)
+ */
+ function geopoEncode($lat, $lng)
+ {
+ // 64characters (number + big and small letter + hyphen + underscore)
+ $chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_";
+
+ $geopo = "";
+ $scale = 7;
+
+ // Change a degree measure to a decimal number
+ $lat = ($lat + 90) / 180 * pow(8, 10);
+ $lng = ($lng + 180) / 360 * pow(8, 10);
+ // Compute a GeoPo code from head and concatenate
+ for ($i = 0; $i < $scale; $i++) {
+ $geopo .= substr($chars, floor($lat / pow(8, 9 - $i) % 8) + floor($lng / pow(8, 9 - $i) % 8) * 8, 1);
+ }
+ return $geopo;
+ }
+
+ $conn = pg_connect("dbname=bus user=postgres password=snmc");
+ if (!$conn) {
+ echo "An error occured.\n";
+ exit;
+ }
+ if ($_REQUEST['newlatlng']) {
+ $latlng = explode(";", $_REQUEST['newlatlng']);
+ $lat = (float)$latlng[0];
+ $lng = (float)$latlng[1];
+
+ $geoPo = geopoEncode($lat, $lng);
+ $nodelat = (int)($lat * 10000000);
+ $nodelon = (int)($lng * 10000000);
+ echo($nodelat . "," . $nodelon . "=$geoPo<br>");
+ $sql = "INSERT INTO stops (geohash,lat,lng) VALUES ('$geoPo', '$nodelat', '$nodelon')";
+ $result = pg_query($conn, $sql);
+ if (!$result) {
+ echo("Error in SQL query: " . pg_last_error() . "<br>\n");
+ } else {
+ echo "Inserted new point at $geoPo <br>";
+ }
+ }
+ flush();
+?>
--- /dev/null
+++ b/betweenpoint.delete.php
@@ -1,1 +1,19 @@
-
+<?php
+
+ $conn = pg_connect("dbname=bus user=postgres password=snmc");
+ if (!$conn) {
+ echo "An error occured.\n";
+ exit;
+ }
+ if ($_REQUEST['oldgeopo']) {
+
+ $sql = " DELETE from stops WHERE geohash = '{$_REQUEST['oldgeopo']}'";
+ $result = pg_query($conn, $sql);
+ if (!$result) {
+ echo("Error in SQL query: " . pg_last_error() . "<br>\n");
+ } else {
+ echo "Deleted {$_REQUEST['oldgeopo']}<br>";
+ }
+ }
+ flush();
+?>
--- a/betweenpoint.move.php
+++ b/betweenpoint.move.php
@@ -66,10 +66,12 @@
$nodelat = (int)($lat * 10000000);
$nodelon = (int)($lng * 10000000);
echo($nodelat . "," . $nodelon . "=$geoPo<br>");
- $sql = "UPDATE stops SET geohash='$geoPo', lat='$nodelat', lng='$nodelon' WHERE geohash = '{$_REQUEST['oldgeopo']}'";
+ $sql = "UPDATE stops SET geohash='$geoPo', lat='$nodelat', lng='$nodelon', name=null, suburb=null WHERE geohash = '{$_REQUEST['oldgeopo']}'";
$result = pg_query($conn, $sql);
if (!$result) {
echo("Error in SQL query: " . pg_last_error() . "<br>\n");
+ } else if (pg_affected_rows($result) == 0) {
+ echo ("Error 0 points moved, please refresh page and try again");
} else {
echo $_REQUEST['oldgeopo'] . " replaced with $geoPo <br>";
$updatedroutes = 0;
--- a/betweenpoint.php
+++ b/betweenpoint.php
@@ -95,6 +95,21 @@
function submitMove () {
$.post("betweenpoint.move.php", $("#moveform").serialize(), function(html){
$("#response").html(html);
+ clearForms();
+ return false;
+ });
+};
+function submitDelete () {
+ $.post("betweenpoint.delete.php", $("#moveform").serialize(), function(html){
+ $("#response").html(html);
+ clearForms();
+ return false;
+ });
+};
+function submitAdd () {
+ $.post("betweenpoint.add.php", $("#moveform").serialize(), function(html){
+ $("#response").html(html);
+ clearForms();
return false;
});
};
@@ -224,7 +239,8 @@
oldgeopo <input type="text" name="oldgeopo" id="oldgeopo"/>
newlatlng <input type="text" name="newlatlng" id="newlatlng" size="60"/>
<input type="button" onclick="javascript:submitMove()" value="Move!">
-
+ <input type="button" onclick="javascript:submitAdd()" value="Add!">
+ <input type="button" onclick="javascript:submitDelete()" value="Delete!">
</form>
<div id="response">
<!-- Our message will be echoed out here -->
--- a/display.php
+++ b/display.php
@@ -18,7 +18,7 @@
// create the ol map object
var map = new OpenLayers.Map('map', options);
-var osmtiles = new OpenLayers.Layer.OSM("local", "http://localhost/tiles/${z}/${x}/${y}.png");
+var osmtiles = new OpenLayers.Layer.OSM("local", "http://10.0.1.154/tiles/${z}/${x}/${y}.png");
// use http://open.atlas.free.fr/GMapsTransparenciesImgOver.php and http://code.google.com/p/googletilecutter/ to make tiles
var graphic = new OpenLayers.Layer.Image(
'Weekday Bus Map',
--- a/maxious-canberra-transit-feed/04-locatebetweenpoints.osm.xml.php
+++ b/maxious-canberra-transit-feed/04-locatebetweenpoints.osm.xml.php
@@ -2,7 +2,7 @@
header('Content-Type: application/xml');
echo "<?xml version='1.0' encoding='UTF-8'?>
<osm version='0.6' generator='xapi: OSM Extended API 2.0' xmlns:xapi='http://www.informationfreeway.org/xapi/0.6'
-xapi:uri='/api/0.6/*[bbox=148.98,-35.48,149.25,-35.15]' xapi:planetDate='20100630' xapi:copyright='2010 OpenStreetMap contributors'
+xapi:uri='/api/0.6/*[bbox=148.98,-35.48,149.21,-35.15]' xapi:planetDate='20100630' xapi:copyright='2010 OpenStreetMap contributors'
xapi:license='Creative commons CC-BY-SA 2.0' xapi:bugs='For assistance or to report bugs contact 80n80n@gmail.com' xapi:instance='zappyHyper'>
";
$conn = pg_connect("dbname=openstreetmap user=postgres password=snmc");
--- a/maxious-canberra-transit-feed/04-locatebetweenpoints.reversegeocode.php
+++ b/maxious-canberra-transit-feed/04-locatebetweenpoints.reversegeocode.php
@@ -25,9 +25,8 @@
echo "Processing ".$stop['geohash'] . " streetname ... ";
$url = "http://geocoding.cloudmade.com/daa03470bb8740298d4b10e3f03d63e6/geocoding/v2/find.js?around=".($stop['lat']/10000000).",".($stop['lng']/10000000)."&distance=closest&object_type=road";
$contents = json_decode(getPage($url));
- print_r($contents);
+ //print_r($contents);
$name = $contents->features[0]->properties->name;
- //todo suburb/locality select * from suburbs where the_geom @> 'POINT(149.075704592122 -35.21751569325)'::geometry
echo "Saving $name ! <br>" ;
$result_save = pg_query($conn, "UPDATE stops set name = '".pg_escape_string($name)."' where geohash = '{$stop['geohash']}' ");
if (!$result_save) {