<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
  <META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
  <META NAME="GENERATOR" CONTENT="GtkHTML/3.30.3">
</HEAD>
<BODY>
Hi Javad<BR>
<BR>
&gt;&gt;&gt;if you have clear example in details to display lines please introduce me<BR>
<BR>
That is *exactly* what I have outlined below...this *is* how you display a geojson feature in OL that comes from postgis - but first you need the geojson - that is where your php comes in - it is grabbing the response from postgis and returning it to the browser.<BR>
<BR>
&gt;&gt;&gt;I am new and my knowledge is not so much<BR>
<BR>
...time to start experimenting with examples and reading api documentation (all available online @ openlayers.org)<BR>
there are examples of how to display pretty much anything (kml, gml, geojson, ArcGIS server, WMS, WFS etc etc)<BR>
<BR>
&gt;&gt;&gt; I dont know what you mean about the resulted geojsonstring by php<BR>
<BR>
What does your php script return ? (point your browser to <A HREF="http://localhost/wherever/yourscript.php">http://localhost/wherever/yourscript.php</A> ) (remember to echo the returned rst result at the end of your php script)<BR>
It *must* return a text string that is formatted as geojson ...<BR>
i.e. <BR>
<BR>
{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;type&quot;: &quot;FeatureCollection&quot;,<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;features&quot;: [<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { &quot;type&quot;: &quot;Feature&quot;, &quot;id&quot;: 0, &quot;geometry&quot;: {&nbsp; .... }, &quot;properties&quot;: { .....}&nbsp; } , <BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { ...etc...} <BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ]<BR>
}<BR>
<BR>
(use qgis and save a shp file as geojson to see what I mean)<BR>
<BR>
You need to understand what your scripts etc are doing (what php does, how to use with postgres, how OL works etc) as well as the architecture of the app you are trying to develop.&nbsp; The forum can just point you in the right direction - not develop the app for you.&nbsp; <BR>
<BR>
Regards<BR>
<BR>
<TABLE CELLSPACING="0" CELLPADDING="0" WIDTH="100%">
<TR>
<TD>
-- <BR>
<B>Glenn Mullett</B><BR>
<I><FONT SIZE="1"><FONT COLOR="#333333">BTech(Nature Cons) PGDip(UNIGIS)</FONT></FONT></I><BR>
<FONT SIZE="2"><FONT COLOR="#333333">H.O.D. GIS</FONT></FONT><BR>
<FONT SIZE="2"><FONT COLOR="#333333">Lidwala Consulting Engineers</FONT></FONT><BR>
<FONT SIZE="2">email:<A HREF="mailto:gmullett@lidwala.com">gmullett@lidwala.com</A></FONT><BR>
<BR>
<FONT COLOR="#808080">____________________________________________________________________________________________________________________________________________________</FONT><BR>
<B><I><FONT SIZE="1"><FONT COLOR="#808080">Lidwala Consulting Engineers (SA) (Pty) Ltd email Disclaimer and confidentiality note:</FONT></FONT></I></B><BR>
<I><FONT SIZE="1"><FONT COLOR="#808080">This e-mail, its attachments and any rights attaching hereto are, unless the content clearly indicates otherwise, the property of Lidwala Consulting Engineers (SA) (Pty) Ltd and its subsidiaries. It is confidential, private and intended for only the addressee.&nbsp; Should you not be the addressee and receive this e-mail by mistake, kindly notify the sender, and delete this e-mail immediately.&nbsp; Do not disclose or use it in any way. Views and opinions expressed in this e-mail are those of the sender unless clearly stated as those of Lidwala Consulting Engineers (SA) (Pty) Ltd.&nbsp; Lidwala Consulting Engineers (SA) (Pty) Ltd accepts no liability for any loss or damages howsoever incurred, or suffered, resulting or arising, from the use of this email or its attachments.&nbsp; Lidwala Consulting Engineers (SA) (Pty) Ltd does not warrant the integrity of this e-mail nor that it is free of errors, viruses, interception or interference.</FONT></FONT></I><BR>
<FONT COLOR="#808080">____________________________________________________________________________________________________________________________________________________</FONT> <BR>
<BR>
</TD>
</TR>
</TABLE>
On Wed, 2011-08-24 at 21:59 +0200, javad sadidi wrote:<BR>
<BLOCKQUOTE TYPE=CITE>
    hi<BR>
    <I>&nbsp;</I>I have the table and want to display it as lines in openlayer. <BR>
    I am new and my knowledge is not so much.<BR>
    I send you the&nbsp; php code, please examine it and say to me how can I diplay it as Geojson or maybe kml in openlayers.if you have clear example in details to display lines please introduce me.<BR>
    I dont know what you mean about the resulted geojsonstring by php .<BR>
    <BR>
    <BR>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
    On Wed, Aug 24, 2011 at 8:00 PM, Glenn Mullett &lt;<A HREF="mailto:gmullett@lidwala.com">gmullett@lidwala.com</A>&gt; wrote:
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
    <BLOCKQUOTE>
        Hi Javad<BR>
        <BR>
        What geojson string is returned by the php? - is it correctly formatted?
    </BLOCKQUOTE>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
    <BLOCKQUOTE>
        <BR>
        <BR>
        &gt;&gt;&nbsp;&nbsp; $sql = &quot;SELECT gid, ST_AsGeoJSON(the_geom) AS geojson, length(the_geom) AS length FROM &quot;.TABLE.&quot;&quot;<BR>
        <BR>
        <BR>
    </BLOCKQUOTE>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
    <BLOCKQUOTE>
        I usually format my geojson with properties at this point already (in a plpgsql function)...<BR>
        <BR>
        the wrapper function I wrote for this:<BR>
        <BR>
        CREATE OR REPLACE FUNCTION geojson_attrib(table_name character varying, gid character varying, cs character varying, ce character varying, schema_name character varying)<BR>
        &nbsp; RETURNS SETOF character varying AS<BR>
        $BODY$<BR>
        select 'SELECT ''{' || $3 || '&quot;geometry&quot;:'' || st_asgeojson(transform(the_geom, 900913),6) || <BR>
        '',&quot;type&quot;:&quot;Feature&quot;,' || $4 || '&quot;properties&quot;:{' <BR>
        || array_to_string(ARRAY(<BR>
        SELECT '&quot;' || c.column_name || '&quot;:&quot;''||coalesce(&quot;'|| c.column_name || '&quot;::varchar,''null'')||''&quot;'<BR>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FROM information_schema.columns As c<BR>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WHERE table_schema= $5 and table_name = $1 <BR>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AND&nbsp; c.column_name NOT IN('gid', 'the_geom')<BR>
        &nbsp;&nbsp;&nbsp; ), ',') || '},&quot;gid&quot;:&quot;'' || gid || ''&quot;}'' as v FROM ' || $5 || '.' || $1 || ' where gid in(' || $2 || ')' as v;<BR>
        $BODY$<BR>
        &nbsp; LANGUAGE sql VOLATILE<BR>
        <BR>
        I use cs and ce to (comment start, comment end) remove geometries if I only want json, so you can set them to: ''<BR>
        <BR>
        <BR>
        To display in Openlayers you need to add a geojson reader:<BR>
        <BR>
        //load the php result&nbsp; into variable str using an xmlhttprequest ( I use Ext to do this)<BR>
        <BR>
        //geojson reader<BR>
        var geojson_format = new OpenLayers.Format.GeoJSON();<BR>
        <BR>
        //create&nbsp; a vector layer<BR>
        var vector_sites = new OpenLayers.Layer.Vector(); <BR>
        <BR>
        //add the vector to the ol map<BR>
        map.addLayer(vector_sites);<BR>
        <BR>
        // read the geojson string into the layer<BR>
        vector_sites.addFeatures(geojson_format.read(str)); <BR>
        <BR>
        Alternatively you can use GeoExt and just load the php result into a FeatureStore that you point to a vector layer<BR>
        <BR>
        &nbsp;&nbsp;&nbsp; var&nbsp; store = new GeoExt.data.FeatureStore({<BR>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; layer: vector_layer,<BR>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fields:fields,<BR>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; proxy: new GeoExt.data.ProtocolProxy({<BR>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; protocol: new OpenLayers.Protocol.HTTP({<BR>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; url: store_url,<BR>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; format: new OpenLayers.Format.GeoJSON()<BR>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; })<BR>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }),<BR>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; autoLoad: true<BR>
        &nbsp;&nbsp;&nbsp; });<BR>
        <BR>
        Regards<BR>
        <BR>
        <TABLE CELLSPACING="0" CELLPADDING="0" WIDTH="100%">
<TR>
<TD>
<BR>
<B>Glenn Mullett</B><BR>
<I><FONT SIZE="1"><FONT COLOR="#333333">BTech(Nature Cons) PGDip(UNIGIS)</FONT></FONT></I><BR>
<FONT SIZE="2"><FONT COLOR="#333333">H.O.D. GIS</FONT></FONT><BR>
<FONT SIZE="2"><FONT COLOR="#333333">Lidwala Consulting Engineers</FONT></FONT><BR>
<FONT SIZE="2">email:<A HREF="mailto:gmullett@lidwala.com">gmullett@lidwala.com</A></FONT><BR>
<BR>
<FONT COLOR="#808080">___________________________________________________________________________________________________________________________________________________</FONT>
</TD>
</TR>
</TABLE>
    </BLOCKQUOTE>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
    <BLOCKQUOTE>
        <BR>
    </BLOCKQUOTE>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
    <BLOCKQUOTE>
        On Wed, <A HREF="tel:2011-08-24">2011-08-24</A> at 19:32 +0200, javad sadidi wrote:<BR>
        <BR>
    </BLOCKQUOTE>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
    <BLOCKQUOTE>
        <BLOCKQUOTE TYPE=CITE>
            <BR>
        </BLOCKQUOTE>
    </BLOCKQUOTE>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
    <BLOCKQUOTE>
        <BLOCKQUOTE TYPE=CITE>
            hi <BR>
            I have a table in postgresql that it has topology and I want to display it as line in openlayers.<BR>
            I use php to connect and convert my data to Geojson. this the codes.but I can not&nbsp; get the result.who can help me.where is wrong in my codes,this is the code.<BR>
            <BR>
            <BR>
            &lt;?php<BR>
            <BR>
            &nbsp;&nbsp; // Database connection settings<BR>
            &nbsp;&nbsp; define(&quot;PG_DB&quot;&nbsp; , &quot;tehran&quot;);<BR>
            &nbsp;&nbsp; define(&quot;PG_HOST&quot;, &quot;localhost&quot;); <BR>
            &nbsp;&nbsp; define(&quot;PG_USER&quot;, &quot;postgres&quot;);<BR>
            &nbsp;&nbsp; define(&quot;PG_PORT&quot;, &quot;5432&quot;); <BR>
            &nbsp;&nbsp; define(&quot;TABLE&quot;, &quot;close&quot;);<BR>
            <BR>
            &nbsp; <BR>
            ?&gt;<BR>
            <BR>
            &lt;?php<BR>
            // Connect to database<BR>
            &nbsp;&nbsp; $dbcon = pg_connect(&quot;dbname=&quot;.PG_DB.&quot; host=&quot;.PG_HOST.&quot; user=&quot;.PG_USER);<BR>
            &nbsp;&nbsp; $sql = &quot;SELECT gid, ST_AsGeoJSON(the_geom) AS geojson, length(the_geom) AS length FROM &quot;.TABLE.&quot;&quot;<BR>
            <BR>
            &nbsp;&nbsp; // Perform database query<BR>
            &nbsp;&nbsp; $query = pg_query($dbcon,$sql); <BR>
            &nbsp;&nbsp; <BR>
            ?&gt;<BR>
            <BR>
            &lt;?php<BR>
            <BR>
            &nbsp;&nbsp; // Return route as GeoJSON<BR>
            &nbsp;&nbsp; $geojson = array(<BR>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'type'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =&gt; 'FeatureCollection',<BR>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'features'&nbsp; =&gt; array()<BR>
            &nbsp;&nbsp; ); <BR>
            &nbsp; <BR>
            &nbsp;&nbsp; // Add edges to GeoJSON array<BR>
            &nbsp;&nbsp; while($edge=pg_fetch_assoc($query)) {&nbsp; <BR>
            <BR>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $feature = array(<BR>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'type' =&gt; 'Feature',<BR>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'geometry' =&gt; json_decode($edge['geojson'], true),<BR>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'crs' =&gt; array(<BR>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'type' =&gt; 'EPSG',<BR>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'properties' =&gt; array('code' =&gt; '4326')<BR>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ),<BR>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'properties' =&gt; array(<BR>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'id' =&gt; $edge['id'],<BR>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'length' =&gt; $edge['length']<BR>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<BR>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; );<BR>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Add feature array to feature collection array<BR>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; array_push($geojson['features'], $feature);<BR>
            &nbsp;&nbsp; }<BR>
            <BR>
            &nbsp;&nbsp; // Close database connection<BR>
            &nbsp;&nbsp; pg_close($dbcon);<BR>
            <BR>
            &nbsp;&nbsp; // Return routing result<BR>
            &nbsp;&nbsp; header('Content-type: application/json',true);<BR>
            &nbsp;&nbsp; echo json_encode($geojson);<BR>
            &nbsp;&nbsp; <BR>
            ?&gt;<BR>
            <BR>
            <BR>
        </BLOCKQUOTE>
    </BLOCKQUOTE>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
    <BLOCKQUOTE>
        <BLOCKQUOTE TYPE=CITE>
<PRE>
_______________________________________________
Users mailing list
<A HREF="mailto:Users@lists.osgeo.org">Users@lists.osgeo.org</A>
<A HREF="http://lists.osgeo.org/mailman/listinfo/openlayers-users">http://lists.osgeo.org/mailman/listinfo/openlayers-users</A>
</PRE>
        </BLOCKQUOTE>
    </BLOCKQUOTE>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
    <BR>
</BLOCKQUOTE>
</BODY>
</HTML>