From: Michael B. <mic...@gm...> - 2010-12-21 04:49:02
|
Hi Ian, I do this... public GridCoverage2D createCoverage(double[][] data, String name, Envelope env) { int width = data[0].length; int height = data.length; WritableRaster raster = RasterFactory.createBandedRaster(DataBuffer.TYPE_DOUBLE, width, height, 1, null); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { raster.setSample(x, y, 0, data[y][x]); } } GridCoverageFactory gcf = CoverageFactoryFinder.getGridCoverageFactory(null); return gcf.create(name, raster, env); } It is just a simplified version of the GridCoverageFactory.create method that takes float arrays. The imports are... import java.awt.image.DataBuffer; import java.awt.image.WritableRaster; import javax.media.jai.RasterFactory; import org.geotools.coverage.CoverageFactoryFinder; import org.geotools.coverage.grid.GridCoverage2D; import org.geotools.coverage.grid.GridCoverageFactory; import org.opengis.geometry.Envelope; Michael On 21 December 2010 15:07, Ian Turton <ijt...@gm...> wrote: > Does any one have example code of how I could go about building a > GridCoverage2D from an array of doubles? > Currently I have: > > private GridCoverage2D convert(ArrayList<Circle> results) { > ReferencedEnvelope resBounds = new > ReferencedEnvelope(bounds.getCoordinateReferenceSystem()); > for(Circle c:results) { > resBounds.expandToInclude(c.getBounds()); > } > System.out.println(resBounds); > GridCoverageBuilder builder = new GridCoverageBuilder(); > builder.setEnvelope(bounds); > builder.setCoordinateReferenceSystem(bounds.getCoordinateReferenceSystem()); > final double scale = 1000.0; > final int width = (int)(resBounds.getWidth()/scale); > final int height = (int)(resBounds.getHeight()/scale); > builder.setImageSize(width, height); > BufferedImage img = builder.getBufferedImage(); > QuantizeCircle qc = new QuantizeCircle(img); > qc.setCellsize(scale); > for(Circle c:results) { > qc.quantize(c); > } > return builder.getGridCoverage2D(); > } > > But I'm struggling with the quantize function as the image doesn't > seem to be the size I was expecting, so I thought I'd ask here to see > if there is an easier way to do this? > > Thanks > > Ian > > PS If you want to see all the code look at > http://code.google.com/p/spatial-cluster-detection/source/browse/trunk/cluster/?r=10 > -- > Ian Turton > > ------------------------------------------------------------------------------ > Lotusphere 2011 > Register now for Lotusphere 2011 and learn how > to connect the dots, take your collaborative environment > to the next level, and enter the era of Social Business. > http://p.sf.net/sfu/lotusphere-d2d > _______________________________________________ > Geotools-gt2-users mailing list > Geo...@li... > https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users > |