From: Ian T. <ijt...@gm...> - 2010-12-22 15:27:07
|
On Tue, Dec 21, 2010 at 8:49 PM, Michael Bedward <mic...@gm...> wrote: > There was some discussion of a WritableGridCoverage2D class a while > ago between Simone, myself and other list members. It got as far as a > (very) basic example in the demo module > (org.geotools.demo.coverage.WritableGridDemo). That would be the place > for setxXXX( world-coords ) methods with interpolation options. > > Since your source data are already on a regular grid perhaps > interpolation isn't required (?). If that's the case, you can simplify > the world to grid (image) coords calculations somewhat... > > GridEnvelope2D gridEnv = new GridEnvelope2D(0, 0, gridWidth, gridHeight); > ReferencedEnvelope worldEnv = new ReferencedEnvelope(minWorldX, > maxWorldX, minWorldY, maxWorldY, crs); > GridGeometry2D gg = new GridGeometry2D(gridEnv, worldEnv); > > Now you can convert from world coordinates to grid coordinates: > > DirectPosition2D pos = new DirectPosition2D(x, y); > GridCoordinates2D gridCoords = gg.worldToGrid(pos); > > Or if your source coords are in a different projection... > > pos = new DirectPosition2D(srcCRS, x, y); > GridCoordinates2D gridCoords = gg.worldToGrid(pos); > That is cool - I'll experiment today. I had been wondering if GridCoordinates did anything useful for me but I couldn't work it out. Thanks Ian |