From e200e50d5182d7255daff176aa931238ee8016eb Mon Sep 17 00:00:00 2001 From: Regina Obe Date: Tue, 27 Dec 2011 05:29:10 +0000 Subject: [PATCH] provide a java console app example git-svn-id: http://svn.osgeo.org/postgis/trunk@8590 b70326c6-7e19-0410-871a-916f4a2858ee --- doc/using_raster_dataman.xml | 85 ++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/doc/using_raster_dataman.xml b/doc/using_raster_dataman.xml index 6c65f3bc1..d02e17909 100644 --- a/doc/using_raster_dataman.xml +++ b/doc/using_raster_dataman.xml @@ -608,6 +608,91 @@ public class TestRaster : IHttpHandler } return result; } +}]]> + + + 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: +set env CLASSPATH .:..\postgresql-9.0-801.jdbc4.jar +javac SaveQueryImage.java +jar cfm SaveQueryImage.jar Manifest.txt *.class + -- Manifest.txt -- + + // Code for SaveQueryImage.java + 0) { + srid = Integer.parseInt(argv[0]); + } + sGetImg.setInt(1, srid); + + ResultSet rs = sGetImg.executeQuery(); + + FileOutputStream fout; + try + { + rs.next(); + fout = new FileOutputStream(new File("test.png") ); + fout.write(rs.getBytes(1)); + fout.close(); + } + catch(Exception e) + { + System.out.println("Can't create file"); + e.printStackTrace(); + } + + rs.close(); + sGetImg.close(); + conn.close(); + } + catch (SQLException se) { + System.out.println("Couldn't connect: print out a stack trace and exit."); + se.printStackTrace(); + System.exit(1); + } + } }]]> -- 2.40.0