hi<br>I have a databse in postgresql and want to add it to open layer as lines in Geojson format.for this I write php codes . my file is close.php this is the code:<br><br><font style="color: rgb(153, 0, 0);" size="1"><?php<br>
<br> // Database connection settings<br> define("PG_DB" , "tehran");<br> define("PG_HOST", "localhost"); <br> define("PG_USER", "postgres");<br> define("PG_PORT", "5432"); <br>
define("TABLE", "close");<br><br> ?><br><br><?php<br><br> $sql = "SELECT gid, ST_AsGeoJSON(the_geom) AS geojson, length(the_geom) AS length FROM .TABLE " ; <br> <br>
<br> // Connect to database<br> $dbcon = pg_connect("dbname=".PG_DB." host=".PG_HOST." user=".PG_USER);<br><br> // Perform database query<br> $query = pg_query($dbcon,$sql); <br> <br>
?><br><br><?php<br><br> // Return streets as GeoJSON<br> $geojson = array(<br> 'type' => 'FeatureCollection',<br> 'features' => array()<br> ); <br> <br> // Add edges to GeoJSON array<br>
while($edge=pg_fetch_assoc($query)) { <br><br> $feature = array(<br> 'type' => 'Feature',<br> 'geometry' => json_decode($edge['geojson'], true),<br> 'crs' => array(<br>
'type' => 'EPSG',<br> 'properties' => array('code' => '4326')<br> ),<br> 'properties' => array(<br> 'id' => $edge['id'],<br>
'length' => $edge['length']<br> )<br> );<br> <br> // Add feature array to feature collection array<br> array_push($geojson['features'], $feature);<br> }<br>
<br> // Close database connection<br> pg_close($dbcon);<br><br> // Return result<br> header('Content-type: application/json',true);<br> echo json_encode($geojson);<br> <br>?><br></font><br><br>
then I add a layers to openlayers:this is the code:<br><pre> <span class="nx">json_layer</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">OpenLayers</span><span class="p">.</span><span class="nx">Layer</span><span class="p">.</span><span class="nx">Vector</span><span class="p">(</span><span class="s2">"GeoJSON"</span><span class="p">,</span> <span class="p">{</span>
<span class="nx">strategies</span><span class="o">:</span> <span class="p">[</span><span class="k">new</span> <span class="nx">OpenLayers</span><span class="p">.</span><span class="nx">Strategy</span><span class="p">.</span><span class="nx">Fixed</span><span class="p">()],</span>
<span class="nx">protocol</span><span class="o">:</span> <span class="k">new</span> <span class="nx">OpenLayers</span><span class="p">.</span><span class="nx">Protocol</span><span class="p">.</span><span class="nx">HTTP</span><span class="p">({</span>
url: "./php/test.php",<span class="nx"></span><span class="p"></span>
<span class="nx">format</span><span class="o">:</span> <span class="k">new</span> <span class="nx">OpenLayers</span><span class="p">.</span><span class="nx">Format</span><span class="p">.</span><span class="nx">GeoJSON</span><span class="p">()</span><br>
<br> <span class="p">})</span>
<span class="p">});</span>
<span class="c1">// Add our vector layer to the map</span>
<span class="nx">map</span><span class="p">.</span><span class="nx">addLayer</span><span class="p">(</span><span class="nx">json_layer</span><span class="p">);</span>
</pre>but I dont see any line in the result of openlayers in the browser.projection of my database is4326 and for openlayers is 900913.<br><br>I have added the following lines to the openlayers codes but it doesnt works yet:<br>
<br><pre>internalProjection: epsg_900913,<br> externalProjection: epsg_4326</pre>
<br>what is wrong in the php or openlayers code?<br>who can help me?<br>I have confused with this problem for some weeks.<br>thanks<br><div style="visibility: hidden; left: -5000px; position: absolute; z-index: 9999; padding: 0px; margin-left: 0px; margin-top: 0px; overflow: hidden; word-wrap: break-word; color: black; font-size: 10px; text-align: left; line-height: 130%;" id="avg_ls_inline_popup">
</div>