Both X and Y are set to 0, in every GridCoverage2D deserialized.
I think that maybe some READ_GRIDCOVERAGE2D parameters are needed (?)
Original: java.awt.Rectangle[x=209,y=333,width=334,height=148]
After serialization / deserialization:
java.awt.Rectangle[x=0,y=0,width=334,height=148]

Serialization:

ByteArrayOutputStream baos = new ByteArrayOutputStream();
GeoTiffWriter writer = new GeoTiffWriter(baos, null);
GeoTiffWriteParams wp = new GeoTiffWriteParams();
wp.setSourceRegion(grid.getGridGeometry().getGridRange2D().getBounds());
final ParameterValueGroup params = new GeoTiffFormat().getWriteParameters();
params.parameter(AbstractGridFormat.GEOTOOLS_WRITE_PARAMS.getName().toString()).setValue(wp);
writer.write(grid, params.values().toArray(new GeneralParameterValue[1]));
writer.dispose();
byte[] bytes = baos.toByteArray();

Deserialization:

ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
GeoTiffReader reader = null;
Hints hints = new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE);
reader = new GeoTiffReader(bais, hints);
GridCoverage2D grid = reader.read(null);
bais.close();
return grid;

Il giorno gio 7 gen 2021 alle ore 15:06 Ian Turton
<ijtur...@gmail.com> ha scritto:
>
> How different are we talking about here? You'll probably need to share some 
> code and example data to allow anyone to look into this.
>
>
> Ian
>
> On Thu, 7 Jan 2021 at 11:58, Lorenzo Di Giacomo <loridi...@gmail.com> wrote:
>>
>> Hello, i'm try to serialize a GridCoverage2D using GeoTiffWriter
>> writing in a ByteArrayOutputStream and deserializing using
>> GeoTiffReader from the ByteArrayInputStream... The problem is that the
>> Bounds (Rectangle object) of the deserialized GridCoverage2D has
>> different X,Y then the original (the width and height are the same)
>> ... I also tried to use GeoTiffWriteParams setSourceRegion method but
>> nothing. Do you know if that's a problem or some other params must be
>> set in order to have the same bounds from the 2 grid? Thanks again!!
>>
>>
>> _______________________________________________
>> GeoTools-Devel mailing list
>> GeoTools-Devel@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/geotools-devel
>
>
>
> --
> Ian Turton


_______________________________________________
GeoTools-Devel mailing list
GeoTools-Devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-devel

Reply via email to