]> granicus.if.org Git - postgis/commitdiff
Add php example using postgis raster
authorRegina Obe <lr@pcorp.us>
Mon, 26 Dec 2011 20:10:35 +0000 (20:10 +0000)
committerRegina Obe <lr@pcorp.us>
Mon, 26 Dec 2011 20:10:35 +0000 (20:10 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@8583 b70326c6-7e19-0410-871a-916f4a2858ee

doc/using_raster_dataman.xml

index e68cc09338ec110b4c4ef99bd18888eae24fcb28..ead4d554d9841acf5cf54ba1312365260b27ce57 100644 (file)
@@ -384,7 +384,7 @@ Available GDAL raster formats:
        </orderedlist>
     </sect2>
   </sect1>
-   <sect1 id="RT_Raster_Catalog"> 
+  <sect1 id="RT_Raster_Catalog"> 
                <title>Raster Catalogs</title>
                <para>There are two raster catalog views that come packaged with PostGIS.  Both views utilize information embedded in the constraints of the raster tables.  As a result
                the catalog views are always consistent with the raster data in the tables since the constraints are enforced. </para>
@@ -496,4 +496,40 @@ Available GDAL raster formats:
                        
         </sect2>
    </sect1>
+   <sect1 id="RT_Raster_Applications"> 
+               <title>Building Custom Applications with PostGIS Raster</title>
+               <sect2 id="RT_PHP_Output">
+                       <title>PHP Example Outputting using ST_AsPNG in concert with other raster functions</title>
+                       <p>In this section, we'll demonstrate how to use the PHP PostgreSQL driver and the <xref linkend="RT_ST_AsGDALRaster" /> family of functions to
+                               output band 1 of a raster to a PHP request stream that can then be embedded in an img src html tag.</p>
+                               
+                       <p>The sample query demonstrates how to combine a whole bunch of raster functions together to grab all tiles that intersect
+                               a particular wgs 84 bounding box and then unions with <xref linkend="RT_ST_Union" /> the intersecting tiles together returning all bands, transforms to user specified projection using <xref linkend="RT_ST_Transform" />,
+                               and then outputs the results as a png using <xref linkend="RT_ST_AsPNG" />.</p>
+                       <programlisting>
+<?php
+$conn_str ='dbname=mydb host=localhost port=5432 user=myuser password=mypwd';
+$dbconn = pg_connect($conn_str);
+header('Content-Type: image/png');  
+/**If a particular projection was requested use it otherwise use mass state plane feet **/
+if (!empty( $_REQUEST['srid'] ) && is_numeric( $_REQUEST['srid']) ){
+               $input_srid = intval($_REQUEST['srid']);
+}
+else { $input_srid = 26986; }
+
+$sql = "set bytea_output='escape';
+SELECT ST_AsPNG(ST_Transform(
+                       ST_AddBand(ST_Union(rast,1), ARRAY[ST_Union(rast,2),ST_Union(rast,3)])
+                               ,$input_srid) ) As web_merc 
+ FROM aerials.boston 
+       WHERE 
+        ST_Intersects(rast, ST_Transform(ST_MakeEnvelope(-71.1217, 42.227, -71.1210, 42.218,4326),26986) )"; 
+$result = pg_query($sql);
+$row = pg_fetch_row($result);
+pg_free_result($result);
+if ($row === false) return;
+echo pg_unescape_bytea($row[0]);
+?></programlisting>
+               </sect2>
+   </sect1>
 </chapter>