Thank you all for the suggestions.
In the meantime I made a littlebit of progress.

I added an SLD to style my GridCoverage (not sure this was needed, but 
ok). It at least provides some color model.
Now, what I am doing is that I tried to use the approach suggested by 
Christian, and do:
ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
OutputStream oos = new java.io.ObjectOutputStream(baos);
oos.writeObject (new SerializableRenderedImage(outcov.getRenderedImage())

Now, I noticed that this approach is *similar*to some test cases in 
http://svn.geotools.org/trunk/modules/library/coverage/src/test/java/org/geotools/coverage/grid/GridCoverageTestBase.java
but in these test cases it does not seem to be necessary to create the 
new SerializableRenderedImage. Can anyone please comment on this?

What I need is the output of a Coverage (or Geotiff, anything that will 
be contained aas one object and will contain georeferencing information 
- at least the ReferencedEnvelope).
I need to pass the coverage to a remote service that will decode it. The 
coverage has a ReferencedEnvelope, and that is what I need to be passed 
with the raw data.
I have control over the decoding of the byte[] to an extent, so I can 
have  a less standard way of decoding it.

I don't think that a jpeg or png will satisfy my needs, as they will 
lack the georeferenceing, plsu I need to access the raw cell values. 
Passing a geotiff in a byte array would be ultimately best, but I do not 
know how to encode that.

Storing temp files is not feasible for all kinds of reasons - for 
instance, not much control over the deployment machine.

Cheers for all hints!
Martin



Simone Giannecchini wrote:
> Ciao Christian,
> as I mentioned once reading/writing to stream is not really support in
> coverage io for geotools.
> Quick solution is to write to a temp file then read as a pure byte
> stream and send over the cable. Do the opposite on the other side.
>
> It might be possible to quickly add support for  reading/writing using
> streams but I am not sure I we will have time to do that anytime soon.
> Anyway I would suggest you open up a Jira for this.
> Notice that this would allow you to write/read a geotiff, as an
> instace, from a byte array.
>
>
> Simone.
> -------------------------------------------------------
> Ing. Simone Giannecchini
> GeoSolutions S.A.S.
> Owner - Software Engineer
> Via Carignoni 51
> 55041  Camaiore (LU)
> Italy
>
> phone: +39 0584983027
> fax:      +39 0584983027
> mob:    +39 333 8128928
>
>
> http://www.geo-solutions.it
> http://simboss.blogspot.com/
> http://www.linkedin.com/in/simonegiannecchini
>
> -------------------------------------------------------
>
>
>
> On Thu, Apr 23, 2009 at 3:39 PM, Martin Tomko <[email protected]> wrote:
>   
>> Dear all,
>> I need to pass around the results of my coverage processing (a
>> Coverage2D, or a geotiff, both are acceptable)  through an XML (as a
>> xsd:base64Binary). The coverages will be VERY small.
>>
>> In order to do that, I need to serialize the object (the coverage). I
>> have found some code doing something like that:
>>    public static byte[] toBytes(Object object){
>>        java.io.ByteArrayOutputStream baos = new
>> java.io.ByteArrayOutputStream();
>>        try{
>>            java.io.ObjectOutputStream oos = new
>> java.io.ObjectOutputStream(baos);
>>            oos.writeObject(object);
>>        }catch(java.io.IOException ioe){
>>        }
>>        return baos.toByteArray();
>>    }
>>
>> But it does not seem to work with coverages:
>> Exception in thread "main" java.lang.IllegalArgumentException: No
>> Serializers available for the ColorModel.
>>    at
>> javax.media.jai.remote.SerializableRenderedImage.<init>(SerializableRenderedImage.java:507)
>>    at
>> javax.media.jai.remote.SerializableRenderedImage.<init>(SerializableRenderedImage.java:390)
>>    at
>> org.geotools.coverage.grid.GridCoverage2D.writeObject(GridCoverage2D.java:1034)
>>    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>    at
>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>>    at
>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>>    at java.lang.reflect.Method.invoke(Method.java:597)
>>    at
>> java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:945)
>>    at
>> java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1461)
>>    at
>> java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1392)
>>    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1150)
>>    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:326)
>>    at ch.uzh.geo.tomko.service.VService.toBytes(VService.java:492)
>>
>> It seems that specific serializers are invoked for the rendered image.
>> Can anyone please point me to a solution? Note that my coverage
>> currently does not have a color model assigned (it has only 6 values -
>> In general I need it for DEMs etc...). I tried to set the coverage
>> ViewType to Geophysics or Rendered, but that did not help.
>> I need the actual values of the cells to be preserved in the output.
>>
>> Thank for any help,
>> Martin
>>
>>
>> ------------------------------------------------------------------------------
>> Stay on top of everything new and different, both inside and
>> around Java (TM) technology - register by April 22, and save
>> $200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
>> 300 plus technical and hands-on sessions. Register today.
>> Use priority code J9JMT32. http://p.sf.net/sfu/p
>> _______________________________________________
>> Geotools-gt2-users mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
>>
>>     
>
>
>   


-- 
Martin Tomko
Postdoctoral Research Assistant 
    
Geographic Information Systems Division
Department of Geography
University of Zurich - Irchel
Winterthurerstr. 190
CH-8057 Zurich, Switzerland

email:  [email protected]
site:   http://www.geo.uzh.ch/~mtomko
mob:    +41-788 629 558
tel:    +41-44-6355256
fax:    +41-44-6356848


------------------------------------------------------------------------------
Stay on top of everything new and different, both inside and 
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today. 
Use priority code J9JMT32. http://p.sf.net/sfu/p
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to