Hi Marcos,

I've got some ideas. If possible, please send me a sample ASC file off
list (up to a few Mb is ok) which has the characteristics of your full
data set so that I can run some tests at this end.

cheers
Michael

On 30 July 2011 11:41, Marcos Nino-Ruiz <[email protected]> wrote:
> Thanks for your prompt response Michael,
>
> The original coverage is the one I want to modify, the code is:
>
>        File inasc = new File("/gsdata/data/lsa/sci/shore.asc");
>        ArcGridReader agr = new ArcGridReader(inasc);
>        GridCoverage2D aCoverage = (GridCoverage2D)agr.read(null);
>        GridCoverageFactory gcf =
> CoverageFactoryFinder.getGridCoverageFactory(null);
>        CoordinateReferenceSystem crs =
> aCoverage.getCoordinateReferenceSystem();
>        log.debug("using following CRS: "+crs.toWKT());
>        Envelope2D envelope2d = aCoverage.getEnvelope2D();
>        float[][] data = new
> float[Double.valueOf(xSizeOut).intValue()][Double.valueOf(ySizeOut).intValue()];
>        GridCoverage2D cov = gcf.create("cov", data, envelope2d);
>
>        WritableGridCoverage2D writableCov = new WritableGridCoverage2D(cov);
>
>
> I´ve also seen that you can use hints with the GridCoverageFactory
> create method, but I can´t find a .create() signature that receives
> the matrix of floats (data) that I want to modify in the simple way
> you do:
>  for (int x = 0; x < xSizeOut; x++) {
>                for (int y = 0; y < ySizeOut; y++) {
>                GridCoordinates2D aCoord = new GridCoordinates2D(x, y);
>                value = aCoverage.evaluate(aCoord, dest);
>                writableCov.setValue(aCoord, lsaWeigth(value[0]));//my
> special analysis function that arcGIS doesn't have!
>            }
>
> If I "clip" the map puting xSizeOut=ySizeOut, everything goes well
> (map now being a square), but the cell size changes so my map doesn't
> align anymore (because the xllcorner, yllcorner and CRS of the
> envelope2D remain the same!)
>
> Thanks for your help, greatly appreciated!!
>
> Marcos Nino-Ruiz
> Computer and Systems engineer
> CRC for Spatial Information
> The University of Melbourne
> Victoria 3010
> Australia
>
>
>
> On Fri, Jul 29, 2011 at 7:25 PM, Michael Bedward
> <[email protected]> wrote:
>> On 29 July 2011 10:33, Marcos Nino-Ruiz <[email protected]> 
>> wrote:
>>> Hi dear everyone, especially Michael Bedward,
>>
>> Oh-oh... I always fear bad news when my name is mentioned up front.
>>
>>> I´m trying to build upon your
>>> org.geotools.demo.coverage.WritableGridDemo.java example, because I
>>> need to create my own  Arc Grid Coverage.
>>
>> Don't expect production quality code with that one. If I remember
>> rightly, it was a quick hack in response to a question on the list a
>> couple of years ago.
>>
>>> I want to modify the values
>>> of the raster and then save them in an ArcGrid coverage. The problem
>>> is, if I want to have a more realistic coverage, with X and Y
>>> dimensions different (not a square) when I go to save that coverage,
>>> using :
>>> //        writableCov.show();
>>>        String coveragePath= "covargeResult.asc";
>>>        File outasc = new File(lsaResult);
>>>        if (outasc.exists())
>>>            outasc.delete();
>>>        ArcGridWriter agw;
>>>        agw = new ArcGridWriter(outasc);
>>>        agw.write(writableCov, null);
>>>
>>> It will show the following exception:
>>> Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5
>>>        at 
>>> com.sun.media.jai.iterator.WritableRandomIterFallback.makeCurrentWritable(WritableRandomIterFallback.java:33)
>>>        at 
>>> com.sun.media.jai.iterator.WritableRandomIterFallback.setSample(WritableRandomIterFallback.java:59)
>>>        at 
>>> edu.unimelb.climatechange.lsa.WritableGridCoverage2D.flushCache(WritableGridCoverage2D.java:240)
>>>        at 
>>> edu.unimelb.climatechange.lsa.WritableGridCoverage2D.getRenderedImage(WritableGridCoverage2D.java:135)
>>>        at 
>>> org.geotools.gce.arcgrid.ArcGridWriter.writeGridCoverage(ArcGridWriter.java:250)
>>>        at 
>>> org.geotools.gce.arcgrid.ArcGridWriter.write(ArcGridWriter.java:506)
>>
>> Right - so the problem seems to be that the JAI iterator used to write
>> the value to the image has been pointed to an invalid image location.
>> But the flushCache method is deferring to the super class to convert
>> world to grid (image) coordinates. So perhaps the problem goes back to
>> when you are setting up the GridCoverage2D object that you
>> subsequently pass to the WritableGridCoverage constructor.  Could you
>> post a snippet for how you are doing that please ?
>>
>> Michael
>>
>

------------------------------------------------------------------------------
Got Input?   Slashdot Needs You.
Take our quick survey online.  Come on, we don't ask for help often.
Plus, you'll get a chance to win $100 to spend on ThinkGeek.
http://p.sf.net/sfu/slashdot-survey
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to