From: Michael B. <mic...@gm...> - 2009-01-17 07:46:41
|
Hi Greg, Do you want to access the data by grid cell (pixel) coordinates or geographic (= map = world) coordinates ? Either way there are some useful bits and bobs that save you having to do so much calculating in your own code. For the cell coords it's easiest to work with the image data behind the grid coverage directly... RenderedImage img = myGrid.getRenderedImage(); RandomIter iter = RandomIterFactory.create(img, null); // second arg for create method is bounds; null means access whole image // get data for pixel in col x, row y, band b of the image... int intDatum = iter.getSample(x, y, b); There are also getSampleFloat and getSampleDouble methods. See: // see http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/javax/media/jai/iterator/RandomIter.html You might find it useful to work with the transform function that converts from your CRS to grid (pixel) coords... try { // get a transform to convert from pixel coords to maps coords of pixel centre... MathTransform2D gridToWorld = myGrid.getGridGeometry().getGridToCRS2D(PixelOrientation.CENTER); // get transform to convert map coords to pixel coords MathTransform2D worldToGrid = gridToWorld.inverse(); // convert a pixel col c, row r to map coords Point2D imgPos = new Point2D.Double(c, r); Point2D mapPos = new Point2D.Double(); gridToWorld.transform(imgPos, mapPos); } catch ( Exception ex ) { // bummer.... } you can also use PixelOrientation LOWER_LEFT, LOWER_RIGHT, UPPER_LEFT, UPPER_RIGHT. Have a look at the javadocs for more info. Michael 2009/1/17 Greg Ederer <gr...@er...>: > Hi, > > I've made some progress. I now have: > > System.setProperty("org.geotools.referencing.forceXY", "true"); > DirectPosition dp = new DirectPositionImpl(crs, 0.05d, 0.05d, > Double.NaN); > float[] result = coverage.evaluate(dp, new float[1]); > > System.out.println("result: " + result[0]); > > The source data are Float32 in a 0.1 degree x 0.1 degree grid. Am I > correct in thinking that result[0] contains the Float32 value of the > pixel whose center is at (0.05, 0.05) degrees (in other words, the > first pixel in the upper left? Am I correct in thinking that (0.15, > 0.05) would give me the next pixel to the right, and so on? > > Thanks! > > Greg > > On Jan 16, 2009, at 10:07 AM, Greg Ederer wrote: > >> Hi, >> >> I have a GridCoverage2D that I create like so: >> >> GeoTiffReader reader = new GeoTiffReader(coverageFile); >> GridCoverage2D coverage = (GridCoverage2D) reader.read(null); >> >> I would now like retrieve individual pixel values. The docs refer to >> a DirectPosition class. But, I'm unclear on how to create a >> DirectPosition instance. >> >> What is the best way to do this? >> >> Thanks! >> >> Greg >> >> ------------------------------------------------------------------------------ >> This SF.net email is sponsored by: >> SourcForge Community >> SourceForge wants to tell your story. >> http://p.sf.net/sfu/sf-spreadtheword >> _______________________________________________ >> Geotools-gt2-users mailing list >> Geo...@li... >> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users > > > ------------------------------------------------------------------------------ > This SF.net email is sponsored by: > SourcForge Community > SourceForge wants to tell your story. > http://p.sf.net/sfu/sf-spreadtheword > _______________________________________________ > Geotools-gt2-users mailing list > Geo...@li... > https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users > |