1

I'm working with this source code. Html file (Openlayers + GeoExt) seems to work fine - everything shows up correctly but when I click on map nothing happend. I use my OSM data loaded to postregsql by osm2po. I think the problem is PHP file. I have changed it by myself but I'm almost sure I have made some mistake. Maybe somebody can help me to figured out what's wrong? Maybe the sql queries did errors? Any sugestions? I use PostgreSQL 9.5.3, PostGIS 2.2 and pgRouting 2.3.2. I'm not sure if my software version is comaptibile with used tutorial

PHP file:

<? php   

// Database connection settings
   define("PG_DB", "ble");
  define("PG_HOST", "localhost"); 
  define("PG_USER", "postgres");
  define("PG_PSSWD", "db_pass");
  define("PG_PORT", "5432"); 
  define("TABLE",   "aa_2po_4pgr");

// Retrieve start point $start = split(' ',$_REQUEST['startpoint']); $startPoint = array($start[0], $start1);

// Retrieve end point $end = split(' ',$_REQUEST['finalpoint']); $endPoint = array($end[0], $end1);

?>

// Find the nearest edge $startEdge = findNearestEdge($startPoint); $endEdge = findNearestEdge($endPoint); // FUNCTION findNearestEdge function findNearestEdge($lonlat) { // Connect to database $con = pg_connect("dbname=".PG_DB." host=".PG_HOST." port=".PG_PORT." user=".PG_USER." password=".PG_PSSWD) or die("nie udalo sie polaczyc z baza danych"); $sql = "SELECT id, source, target, geom_way, ST_distance(geom_way, ST_GeometryFromText( 'POINT(".$lonlat[0]." ".$lonlat[1].")', 4326)) AS dist FROM ".TABLE." WHERE geom_way( '(".($lonlat[0]-0.1)." ".($lonlat[1]-0.1).", ".($lonlat[0]+0.1)." ".($lonlat[1]+0.1).")') ORDER BY dist LIMIT 1"; $query = pg_query($con,$sql); $edge['id'] = pg_fetch_result($query, 0, 0); $edge['source'] = pg_fetch_result($query, 0, 1); $edge['target'] = pg_fetch_result($query, 0, 2); $edge['geom_way'] = pg_fetch_result($query, 0, 3); // Close database connection pg_close($con); return $edge; } ?>


// Select the routing algorithm switch($_REQUEST['method']) {

case 'SPD' : // Shortest Path Dijkstra $sql = "SELECT rt.id, ST_AsGeoJSON(rt.geom_way) AS geojson, length(rt.geom_way) AS length, ".TABLE.".id FROM ".TABLE.", (SELECT id, geom_way FROM pgr_dijkstra( '".TABLE."', ".$startEdge['source'].", ".$endEdge['target'].", 0.1) ) as rt WHERE ".TABLE.".id=rt.gid;"; break;

} // close switch

// Connect to database $dbcon = pg_connect("dbname=".PG_DB." host=".PG_HOST." port=".PG_PORT." user=".PG_USER." password=".PG_PSSWD);

// Perform database query $query = pg_query($dbcon,$sql);

?>

'FeatureCollection', 'features' => array() ); // Add edges to GeoJSON array while($edge=pg_fetch_assoc($query)) { $feature = array( 'type' => 'Feature', 'geometry' => json_decode($edge['geojson'], true), 'crs' => array( 'type' => 'EPSG', 'properties' => array('code' => '4326') ), 'properties' => array( 'id' => $edge['id'], 'length' => $edge['length'] ) ); // Add feature array to feature collection array array_push($geojson['features'], $feature); } // Close database connection pg_close($dbcon); // Return routing result header('Content-type: application/json',true); echo json_encode($geojson); ?>

After I lunch it in localhost (xampp) in browser i got this:


Notice: Undefined index: startpoint in C:\xampp2\htdocs\pgrout\php\pgrouting.php on line 12

Notice: Undefined offset: 1 in C:\xampp2\htdocs\pgrout\php\pgrouting.php on line 13

Notice: Undefined index: finalpoint in C:\xampp2\htdocs\pgrout\php\pgrouting.php on line 16

Notice: Undefined offset: 1 in C:\xampp2\htdocs\pgrout\php\pgrouting.php on line 17

Warning: pg_query(): Query failed: ERROR: function geom_way(unknown) doesn't exist LINE 5: WHERE geom_way( ^ HINT: No function more matching to the given name and types of arguments. Perhaps you should add explicit projection types. in C:\xampp2\htdocs\pgrout\php\pgrouting.php on line 45

Warning: pg_fetch_result() expects parameter 1 to be resource, boolean given in C:\xampp2\htdocs\pgrout\php\pgrouting.php on line 47

Warning: pg_fetch_result() expects parameter 1 to be resource, boolean given in C:\xampp2\htdocs\pgrout\php\pgrouting.php on line 48

Warning: pg_fetch_result() expects parameter 1 to be resource, boolean given in C:\xampp2\htdocs\pgrout\php\pgrouting.php on line 49

Warning: pg_fetch_result() expects parameter 1 to be resource, boolean given in C:\xampp2\htdocs\pgrout\php\pgrouting.php on line 50

Warning: pg_query(): Query failed: ERROR: function geom_way(unknown) doesn't exist LINE 5: WHERE geom_way( ^ HINT: No function more matching to the given name and types of arguments. Perhaps you should add explicit projection types. in C:\xampp2\htdocs\pgrout\php\pgrouting.php on line 45

Warning: pg_fetch_result() expects parameter 1 to be resource, boolean given in C:\xampp2\htdocs\pgrout\php\pgrouting.php on line 47

Warning: pg_fetch_result() expects parameter 1 to be resource, boolean given in C:\xampp2\htdocs\pgrout\php\pgrouting.php on line 48

Warning: pg_fetch_result() expects parameter 1 to be resource, boolean given in C:\xampp2\htdocs\pgrout\php\pgrouting.php on line 49

Warning: pg_fetch_result() expects parameter 1 to be resource, boolean given in C:\xampp2\htdocs\pgrout\php\pgrouting.php on line 50

Notice: Undefined index: method in C:\xampp2\htdocs\pgrout\php\pgrouting.php on line 63

Notice: Undefined variable: sql in C:\xampp2\htdocs\pgrout\php\pgrouting.php on line 86

Warning: pg_query(): Query failed: in C:\xampp2\htdocs\pgrout\php\pgrouting.php on line 86

Warning: pg_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp2\htdocs\pgrout\php\pgrouting.php on line 99
{"type":"FeatureCollection","features":[]}

  • You have looked at the publishing date of release, don't you? The current pgRouting release will not work with the old workshop anymore, and there will be many changes necessary to make it work. You had to use a pgRouting version of 2011. – dkastl Mar 6 '17 at 23:15
  • Yes, You are right. Just like I thought - one thing is the correct PHP queries, other thing is the pgRouting version. But do you know which version of pgRouting will work with this workshop? And is it still able to download it? If yes, do I have to change the Postgresql version to older one too? – bass Mar 7 '17 at 19:06
  • I think this workshop was using pgRouting 1.x and also a very early version of OpenLayers. It will be a lot of effort to make it work. I do not recommend you this. – dkastl Mar 8 '17 at 14:51
  • Sad to hear but it's true. I know that the latest workshop shows how to implement pgRouting on Geoserver and then to the Openlayers by WMS. But to show it online I need to buy special hosting that works with Geoserver, for example AcuGIS. But it's not the best resolution for me. I hope to doing that by PHP queries. The problem is I can't find good tutorial with 2.x pgrouting version and PHP script. Any ideas where to find good tutorial? – bass Mar 8 '17 at 19:50
  • You don't have to have a different hosting plan. But you have to learn how to make a PostgreSQL query through your programming language of choice. You won't get very far otherwise. – dkastl Mar 9 '17 at 23:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.