From: Oleg72 <ev...@iw...> - 2008-09-26 15:39:59
|
Dear All, I am trying to read and edit large ESRI Ascii Grid. To edit small grids the following works fine: (WritableRaster)RenderedImage().getData(); Unfortunately this approach does not work with large Grids. * Is there a way to make GridCoverage2D created from large ascii Grid editable? At the moment the only way to solve this problem is to create new GridCoverage2D using GridCoverageBuilder and copy data (floating) into it. The only problem at the moment is to define number of digits after decimal point. If I am writing value 0.001 and reading it back I am getting 0.0 same problem with saving grid to file. * How do I define the number of decimal places for values stored in GridCoverage2D? Any help would be highly appreciated. Oleg -- View this message in context: http://www.nabble.com/WritableRaster-and-GridCoverageBuilder-tp19690976p19690976.html Sent from the geotools-gt2-users mailing list archive at Nabble.com. |
From: Michael B. <mic...@gm...> - 2008-09-27 00:48:48
|
try this... RenderedImage rImg = cov.getRenderedImage(); TiledImage tImg = new TiledImage(rImg, true); then work with the TiledImage which, in effect, is a writable view of your coverage's raster Caveat: I haven't done this with really large coverages. Let us know how you go. Michael 2008/9/27 Oleg72 <ev...@iw...>: > > Dear All, > I am trying to read and edit large ESRI Ascii Grid. > To edit small grids the following works fine: > (WritableRaster)RenderedImage().getData(); > > Unfortunately this approach does not work with large Grids. > * Is there a way to make GridCoverage2D created from large ascii Grid > editable? > > At the moment the only way to solve this problem is to create new > GridCoverage2D using GridCoverageBuilder and copy data (floating) into it. > The only problem at the moment is to define number of digits after decimal > point. > If I am writing value 0.001 and reading it back I am getting 0.0 same > problem with saving grid to file. > * How do I define the number of decimal places for values stored in > GridCoverage2D? > Any help would be highly appreciated. > Oleg > -- > View this message in context: http://www.nabble.com/WritableRaster-and-GridCoverageBuilder-tp19690976p19690976.html > Sent from the geotools-gt2-users mailing list archive at Nabble.com. > > > ------------------------------------------------------------------------- > This SF.Net email is sponsored by the Moblin Your Move Developer's challenge > Build the coolest Linux based applications with Moblin SDK & win great prizes > Grand prize is a trip for two to an Open Source event anywhere in the world > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > _______________________________________________ > Geotools-gt2-users mailing list > Geo...@li... > https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users > |
From: Oleg72 <ev...@iw...> - 2008-09-27 17:13:18
|
Unfortunately it does not work I tried: RenderedImage rImg = cov.getRenderedImage(); TiledImage tImg = new TiledImage(rImg, true); float c = (float)100; for (int numXtiles=0; numXtiles<tImg .getNumXTiles(); numXtiles++){ for (int numYtiles=0; numYtiles<tImg .getNumYTiles(); numYtiles++){ WritableRaster wr = tImg.getWritableTile(numXtiles, numYtiles); for (int yy=0; yy<wr.getHeight(); yy++){ for (int xx=0; xx<wr.getWidth(); xx++){ wr.setSample(wr.getMinX()+xx, wr.getMinY()+yy, 0, c); } } tImg.releaseWritableTile(numXtiles, numYtiles); } } On the loop 1880 program is terminated with the following error: "Exception in thread "main" java.lang.RuntimeException: Cannot construct DataBuffer." Michael Bedward wrote: > > try this... > > RenderedImage rImg = cov.getRenderedImage(); > TiledImage tImg = new TiledImage(rImg, true); > > then work with the TiledImage which, in effect, is a writable view of > your coverage's raster > > Caveat: I haven't done this with really large coverages. > > Let us know how you go. > > Michael > > 2008/9/27 Oleg72 <ev...@iw...>: >> >> Dear All, >> I am trying to read and edit large ESRI Ascii Grid. >> To edit small grids the following works fine: >> (WritableRaster)RenderedImage().getData(); >> >> Unfortunately this approach does not work with large Grids. >> * Is there a way to make GridCoverage2D created from large ascii Grid >> editable? >> >> At the moment the only way to solve this problem is to create new >> GridCoverage2D using GridCoverageBuilder and copy data (floating) into >> it. >> The only problem at the moment is to define number of digits after >> decimal >> point. >> If I am writing value 0.001 and reading it back I am getting 0.0 same >> problem with saving grid to file. >> * How do I define the number of decimal places for values stored in >> GridCoverage2D? >> Any help would be highly appreciated. >> Oleg >> -- >> View this message in context: >> http://www.nabble.com/WritableRaster-and-GridCoverageBuilder-tp19690976p19690976.html >> Sent from the geotools-gt2-users mailing list archive at Nabble.com. >> >> >> ------------------------------------------------------------------------- >> This SF.Net email is sponsored by the Moblin Your Move Developer's >> challenge >> Build the coolest Linux based applications with Moblin SDK & win great >> prizes >> Grand prize is a trip for two to an Open Source event anywhere in the >> world >> http://moblin-contest.org/redirect.php?banner_id=100&url=/ >> _______________________________________________ >> Geotools-gt2-users mailing list >> Geo...@li... >> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users >> > > ------------------------------------------------------------------------- > This SF.Net email is sponsored by the Moblin Your Move Developer's > challenge > Build the coolest Linux based applications with Moblin SDK & win great > prizes > Grand prize is a trip for two to an Open Source event anywhere in the > world > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > _______________________________________________ > Geotools-gt2-users mailing list > Geo...@li... > https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users > > -- View this message in context: http://www.nabble.com/WritableRaster-and-GridCoverageBuilder-tp19690976p19704613.html Sent from the geotools-gt2-users mailing list archive at Nabble.com. |
From: Michael B. <mic...@gm...> - 2008-09-28 05:56:30
|
Bummer. This might be grasping at straws, but does it make any difference if you use an iterator ? For example... RenderedImage rImg = cov.getRenderedImage(); TiledImage tImg = new TiledImage(rImg, true); WritableRectIter iter = RectIterFactory.createWritable(tImg, null); float c = (float)100; for (int y = tImg.getMinY(); y <= tImg.getMaxY(); y++) { for (int x = tImg.getMinX(); x <= tImg.getMaxX(); x++) { iter.setSample(c); } iter.nextLine(); iter.startPixels(); } Michael > for (int numXtiles=0; numXtiles<tImg .getNumXTiles(); numXtiles++){ > for (int numYtiles=0; numYtiles<tImg .getNumYTiles(); numYtiles++){ > WritableRaster wr = tImg.getWritableTile(numXtiles, numYtiles); > for (int yy=0; yy<wr.getHeight(); yy++){ > for (int xx=0; xx<wr.getWidth(); xx++){ > wr.setSample(wr.getMinX()+xx, wr.getMinY()+yy, 0, c); > } > } > tImg.releaseWritableTile(numXtiles, numYtiles); > } > } 2008/9/28 Oleg72 <ev...@iw...>: > > Unfortunately it does not work > I tried: > RenderedImage rImg = cov.getRenderedImage(); > TiledImage tImg = new TiledImage(rImg, true); > float c = (float)100; > for (int numXtiles=0; numXtiles<tImg .getNumXTiles(); numXtiles++){ > for (int numYtiles=0; numYtiles<tImg .getNumYTiles(); numYtiles++){ > WritableRaster wr = tImg.getWritableTile(numXtiles, numYtiles); > for (int yy=0; yy<wr.getHeight(); yy++){ > for (int xx=0; xx<wr.getWidth(); xx++){ > wr.setSample(wr.getMinX()+xx, wr.getMinY()+yy, 0, c); > } > } > tImg.releaseWritableTile(numXtiles, numYtiles); > } > } > > On the loop 1880 program is terminated with the following error: > "Exception in thread "main" java.lang.RuntimeException: Cannot construct > DataBuffer." > > > > Michael Bedward wrote: >> >> try this... >> >> RenderedImage rImg = cov.getRenderedImage(); >> TiledImage tImg = new TiledImage(rImg, true); >> >> then work with the TiledImage which, in effect, is a writable view of >> your coverage's raster >> >> Caveat: I haven't done this with really large coverages. >> >> Let us know how you go. >> >> Michael >> >> 2008/9/27 Oleg72 <ev...@iw...>: >>> >>> Dear All, >>> I am trying to read and edit large ESRI Ascii Grid. >>> To edit small grids the following works fine: >>> (WritableRaster)RenderedImage().getData(); >>> >>> Unfortunately this approach does not work with large Grids. >>> * Is there a way to make GridCoverage2D created from large ascii Grid >>> editable? >>> >>> At the moment the only way to solve this problem is to create new >>> GridCoverage2D using GridCoverageBuilder and copy data (floating) into >>> it. >>> The only problem at the moment is to define number of digits after >>> decimal >>> point. >>> If I am writing value 0.001 and reading it back I am getting 0.0 same >>> problem with saving grid to file. >>> * How do I define the number of decimal places for values stored in >>> GridCoverage2D? >>> Any help would be highly appreciated. >>> Oleg >>> -- >>> View this message in context: >>> http://www.nabble.com/WritableRaster-and-GridCoverageBuilder-tp19690976p19690976.html >>> Sent from the geotools-gt2-users mailing list archive at Nabble.com. >>> >>> >>> ------------------------------------------------------------------------- >>> This SF.Net email is sponsored by the Moblin Your Move Developer's >>> challenge >>> Build the coolest Linux based applications with Moblin SDK & win great >>> prizes >>> Grand prize is a trip for two to an Open Source event anywhere in the >>> world >>> http://moblin-contest.org/redirect.php?banner_id=100&url=/ >>> _______________________________________________ >>> Geotools-gt2-users mailing list >>> Geo...@li... >>> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users >>> >> >> ------------------------------------------------------------------------- >> This SF.Net email is sponsored by the Moblin Your Move Developer's >> challenge >> Build the coolest Linux based applications with Moblin SDK & win great >> prizes >> Grand prize is a trip for two to an Open Source event anywhere in the >> world >> http://moblin-contest.org/redirect.php?banner_id=100&url=/ >> _______________________________________________ >> Geotools-gt2-users mailing list >> Geo...@li... >> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users >> >> > > -- > View this message in context: http://www.nabble.com/WritableRaster-and-GridCoverageBuilder-tp19690976p19704613.html > Sent from the geotools-gt2-users mailing list archive at Nabble.com. > > > ------------------------------------------------------------------------- > This SF.Net email is sponsored by the Moblin Your Move Developer's challenge > Build the coolest Linux based applications with Moblin SDK & win great prizes > Grand prize is a trip for two to an Open Source event anywhere in the world > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > _______________________________________________ > Geotools-gt2-users mailing list > Geo...@li... > https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users > |
From: Oleg72 <ev...@iw...> - 2008-09-30 15:25:03
|
It still does not work properly for big grids. For 2 MB Grid it works fine. But for 40 MB only part of the Grid is changed. I used following: RenderedImage ri = gridCoverage2D.getRenderedImage(); tImg = new TiledImage(ri, true); for (int numXtiles=0; numXtiles<tImg.getNumXTiles(); numXtiles++){ for (int numYtiles=0; numYtiles<tImg.getNumYTiles(); numYtiles++){ WritableRaster wr = tImg.getWritableTile(numXtiles, numYtiles); WritableRectIter iter = RectIterFactory.createWritable(wr, null); for (int y=0; y<wr.getHeight(); y++){ for (int x=0; x<wr.getWidth(); x++){ iter.setSample(123.45); iter.nextPixel(); } iter.nextLine(); iter.startPixels(); } tImg.releaseWritableTile(numXtiles, numYtiles); } } To save Grid I used: ArcGridWriter writer = new ArcGridWriter(new File("output.asc")); writer.write(gridCoverage2D, null); If I create a new GridCoverage2D everything works with large grids as well. But I did not managed to prperly format new grid coverage. if I write sample 123.45 only 123.0 is written. If I used following: GridCoverageBuilder builder = new GridCoverageBuilder(); builder.setEnvelope(env); Variable elevation = builder.newVariable("Elevation", SI.METRE); elevation.setLinearTransform(0.01, 0); elevation.addNodataValue("No data", -9999); builder.setImageSize(sizeX, sizeY); builder.setSampleRange(-1000, 20000); GridCoverage2D newgc = builder.getGridCoverage2D(); I tried to set 12345 instead of 123.45 and then transform it: elevation.setLinearTransform(0.01, 0); But there are 2 problems: 1. it writes to file 123.44999996543 instead of 123.45 2. I have to set large sample range and this leads to out of memory error. Bummer. This might be grasping at straws, but does it make any difference if you use an iterator ? For example... RenderedImage rImg = cov.getRenderedImage(); TiledImage tImg = new TiledImage(rImg, true); WritableRectIter iter = RectIterFactory.createWritable(tImg, null); float c = (float)100; for (int y = tImg.getMinY(); y <= tImg.getMaxY(); y++) { for (int x = tImg.getMinX(); x <= tImg.getMaxX(); x++) { iter.setSample(c); } iter.nextLine(); iter.startPixels(); } Michael -- View this message in context: http://www.nabble.com/WritableRaster-and-GridCoverageBuilder-tp19690976p19744344.html Sent from the geotools-gt2-users mailing list archive at Nabble.com. |
From: Michael B. <mic...@gm...> - 2008-09-30 22:32:00
|
Hi again > It still does not work properly for big grids. For 2 MB Grid it works fine. > But for 40 MB only part of the Grid is changed. > I used following: > No - try the code I suggested with the iterator rather than working with rasters and tiles directly. The iterator should handle all those things for you. Michael |
From: Oleg72 <ev...@iw...> - 2008-10-01 12:09:34
|
Hi Michael, I tried your code at first. But it did't work as well. Although MinX = 0, MinY = 0, MaxX = 13184, MaxY = 9933. Iterator is stoped at x = 13184, y = 3 while trying to perform iter.setSample(c); with following error: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 52736 at java.awt.image.DataBufferDouble.setElemFloat(Unknown Source) at javax.media.jai.ComponentSampleModelJAI.setSample(ComponentSampleModelJAI.java:926) at com.sun.media.jai.iterator.WritableRectIterFallback.setSample(WritableRectIterFallback.java:42) at volumecalculator.spatial.impl.geotools.GridGt2.<init>(GridGt2.java:363) at volumecalculator.spatial.impl.geotools.GridFactoryGt2.createGrid(GridFactoryGt2.java:27) at volumecalculator.VolumeCalculatorAppContext.appInit(VolumeCalculatorAppContext.java:26) The Tile is 4 pixels high. That is why I thought using tiles will help. Michael Bedward wrote: > > For example... > > RenderedImage rImg = cov.getRenderedImage(); > TiledImage tImg = new TiledImage(rImg, true); > WritableRectIter iter = RectIterFactory.createWritable(tImg, null); > float c = (float)100; > for (int y = tImg.getMinY(); y <= tImg.getMaxY(); y++) { > for (int x = tImg.getMinX(); x <= tImg.getMaxX(); x++) { > iter.setSample(c); > } > iter.nextLine(); > iter.startPixels(); > } > > > -- View this message in context: http://www.nabble.com/WritableRaster-and-GridCoverageBuilder-tp19690976p19758711.html Sent from the geotools-gt2-users mailing list archive at Nabble.com. |
From: Martin D. <mar...@ge...> - 2008-10-03 17:00:00
|
Hello all As stated in Sun's javadoc, java.awt.image.RenderedImage.getData() performs a *copy* of the data. So it is not surprising if OutOfMemoryError occur for big images. Use iterators as suggested by Mickael. But you need to do it that way: RectIter iter = .... if (!iter.finishedBands()) do { iter.startLines(); if (!iter.finishedLines()) do { iter.startPixels(); if (!iter.finishedPixel()) do { // Do your process here. } while (!iter.nextPixelDone()); } while (!iter.nextLineDone()); } while (!iter.nextBandDone()); Martin |
From: Michael B. <mic...@gm...> - 2008-10-02 02:06:07
|
2008/10/1 Oleg72 <ev...@iw...>: > > Hi Michael, > I tried your code at first. But it did't work as well. > At least you didn't get an out of memory error :-) Here's one last suggestion, after which I'm afraid that my feeble knowledge of JAI is used up... RenderedImage rImg = cov.getRenderedImage(); TiledImage tImg = new TiledImage(rImg, true); WritableRectIter iter = RectIterFactory.createWritable(tImg, null); float c = (float)100; do { do { iter.setSample(c); } while (!iter.nextPixelDone()); iter.startPixels(); } while (!iter.nextLineDone()); Hope this helps, Michael |
From: Oleg72 <ev...@iw...> - 2008-10-02 09:10:52
|
Michael Bedward wrote: > > > Here's one last suggestion, after which I'm afraid that my feeble > knowledge of JAI is used up... > > RenderedImage rImg = cov.getRenderedImage(); > TiledImage tImg = new TiledImage(rImg, true); > WritableRectIter iter = RectIterFactory.createWritable(tImg, null); > float c = (float)100; > do { > do { > iter.setSample(c); > } while (!iter.nextPixelDone()); > iter.startPixels(); > } while (!iter.nextLineDone()); > > > In this way it is possible to write data into GridCiverage and read it, but it is not possible to write changes to file. It works only with -Xmx1024m otherwise it can not create DataBuffer while trying to execute iter.nextLineDone(). However I can live with that. By the way this solution: Michael Bedward wrote: > > RenderedImage rImg = cov.getRenderedImage(); > TiledImage tImg = new TiledImage(rImg, true); > WritableRectIter iter = RectIterFactory.createWritable(tImg, null); > float c = (float)100; > for (int y = tImg.getMinY(); y <= tImg.getMaxY(); y++) { > for (int x = tImg.getMinX(); x <= tImg.getMaxX(); x++) { > iter.setSample(c); > } > iter.nextLine(); > iter.startPixels(); > } > works with WritableRandomIter. Thanks a lot for your help Oleg -- View this message in context: http://www.nabble.com/WritableRaster-and-GridCoverageBuilder-tp19690976p19775851.html Sent from the geotools-gt2-users mailing list archive at Nabble.com. |
From: Michael B. <mic...@gm...> - 2008-10-02 09:17:40
|
No worries - glad to hear you've got something that's workable for you now Michael 2008/10/2 Oleg72 wrote: > > In this way it is possible to write data into GridCiverage and read it, but > it is not possible to write changes to file. It works only with -Xmx1024m > otherwise it can not create DataBuffer while trying to execute > iter.nextLineDone(). > However I can live with that. > > By the way this solution: > > Michael Bedward wrote: >> >> RenderedImage rImg = cov.getRenderedImage(); >> TiledImage tImg = new TiledImage(rImg, true); >> WritableRectIter iter = RectIterFactory.createWritable(tImg, null); >> float c = (float)100; >> for (int y = tImg.getMinY(); y <= tImg.getMaxY(); y++) { >> for (int x = tImg.getMinX(); x <= tImg.getMaxX(); x++) { >> iter.setSample(c); >> } >> iter.nextLine(); >> iter.startPixels(); >> } >> > > works with WritableRandomIter. > > Thanks a lot for your help > Oleg > > > > -- > View this message in context: http://www.nabble.com/WritableRaster-and-GridCoverageBuilder-tp19690976p19775851.html > Sent from the geotools-gt2-users mailing list archive at Nabble.com. > > > ------------------------------------------------------------------------- > This SF.Net email is sponsored by the Moblin Your Move Developer's challenge > Build the coolest Linux based applications with Moblin SDK & win great prizes > Grand prize is a trip for two to an Open Source event anywhere in the world > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > _______________________________________________ > Geotools-gt2-users mailing list > Geo...@li... > https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users > |