From: Regina Obe Date: Tue, 27 Dec 2011 06:01:58 +0000 (+0000) Subject: replace java example with a simpler more useful one X-Git-Tag: 2.0.0alpha1~284 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d3706ece9c84799314ac1a2e5c0607dec68416e7;p=postgis replace java example with a simpler more useful one git-svn-id: http://svn.osgeo.org/postgis/trunk@8591 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/doc/using_raster_dataman.xml b/doc/using_raster_dataman.xml index d02e17909..3e9077387 100644 --- a/doc/using_raster_dataman.xml +++ b/doc/using_raster_dataman.xml @@ -612,19 +612,14 @@ public class TestRaster : IHttpHandler Java console app that outputs raster query as PNG file - In this section, we'll demonstrate how to use PostgreSQL JDBC driver and the family of functions to - output band 1,2,3 of a raster to a file. - - 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 the intersecting tiles together returning all bands, transforms to user specified projection using , - and then outputs the results as a png using . - This is same example as except implemented in C#. - You would call the below using java -jar SaveQueryImage.jar "2249" to get the raster image in Massachusetts state plane feet in a file in the same folder. The file will be called test.png - You can compile the following code using a command something like: + This is a simple java console app that takes a query that returns one image and outputs to specified file. + You can compile the following code using a command something like: set env CLASSPATH .:..\postgresql-9.0-801.jdbc4.jar javac SaveQueryImage.java jar cfm SaveQueryImage.jar Manifest.txt *.class - -- Manifest.txt -- +And call it from the command-line with something like +java.exe -jar SaveQueryImage.jar -jar SaveQueryImage.jar "SELECT ST_AsPNG(ST_AsRaster(ST_Buffer(ST_Point(1,5),10, 'quad_segs=2'),150, 150, '8BUI',100));" "test.png" + -- Manifest.txt -- // Code for SaveQueryImage.java @@ -649,31 +644,21 @@ public class SaveQueryImage { } Connection conn = null; - int srid = 26986; try { conn = DriverManager.getConnection("jdbc:postgresql://localhost:5432/mydb","myuser", "mypwd"); conn.setAutoCommit(false); - PreparedStatement sGetImg = conn.prepareStatement("SELECT ST_AsPNG( " + - " ST_Transform( " + - " ST_AddBand(ST_Union(rast,1), ARRAY[ST_Union(rast,2),ST_Union(rast,3)]) " + - " ,?) ) As new_rast " + - " FROM aerials.boston " + - " WHERE " + - " ST_Intersects(rast, ST_Transform(ST_MakeEnvelope(-71.1217, 42.227, -71.1210, 42.218,4326),26986) );"); - if (argv.length > 0) { - srid = Integer.parseInt(argv[0]); - } - sGetImg.setInt(1, srid); - + PreparedStatement sGetImg = conn.prepareStatement(argv[0]); + ResultSet rs = sGetImg.executeQuery(); FileOutputStream fout; try { rs.next(); - fout = new FileOutputStream(new File("test.png") ); + /** Output to file name requested by user **/ + fout = new FileOutputStream(new File(argv[1]) ); fout.write(rs.getBytes(1)); fout.close(); }