Thanks Ian, yeah i removed the print on the awt rectangles that i get
from ( getGridGeometry().getGridRange2D().getBounds() ).
Also, that difference is visible in plannarImage.
I was wondering if that difference in data after serialization /
deserialization is "normal" and could affect the writing operation.
Because basically what happens is:
1) Read an image in GridCoverage2D
2) Cut in N parts using Crop operation ( getting N GridCoverage2D )
3) Serialize each part and send it
4) Deserialize each part
5) Merge them back (with the result of 1 GridCoverage2D)
6) Write the GridCoverage2D in file.tiff

Now all this works just fine and is also really fast even with a lot
of cuts, since i merge them back in multithreading using the MapReduce
paradigm with ForkJoin.
But ... When there are few cuts (< 200/300) it's fine, but with 2000
cuts, for examples, it's stuck on writing.
Doing the steps above (without points 3,4) write the file well. So i
was wondering if it could be that difference on X and Y, if it could
affect the write operation.
I also tried on a powerful server ( octa-core and 24gb RAM ), thinking
could be of a memory issue, but i get the same result.
Thanks for your suggestions!

Il giorno gio 7 gen 2021 alle ore 18:09 Ian Turton
<ijtur...@gmail.com> ha scritto:
>
> and now without a zip file!
>
> Ian
>
> On Thu, 7 Jan 2021 at 17:05, Ian Turton <ijtur...@gmail.com> wrote:
>>
>> and here are my input png files (you'll need to add gt-image to read them)
>>
>> Ian
>>
>> On Thu, 7 Jan 2021 at 17:02, Ian Turton <ijtur...@gmail.com> wrote:
>>>
>>> It seems odd that you are dealing with java.awt.Rectangles - I'm not sure 
>>> where you are getting them from as there is no mention in the code. I 
>>> modified your code to this:
>>>
>>> public static void main(String[] args) throws IOException {
>>>     File input = new 
>>> File("/home/ian/code/geotools-cookbook/code/modules/spike/test.png");
>>>     AbstractGridFormat format = GridFormatFinder.findFormat(input);
>>>     Hints hints = null;
>>>     if (format instanceof GeoTiffFormat) {
>>>         hints = new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, 
>>> Boolean.TRUE);
>>>     }
>>>     AbstractGridCoverage2DReader reader = format.getReader(input, hints);
>>>     GridCoverage2D grid = reader.read(null);
>>>     System.out.println( grid.getEnvelope2D());
>>>     System.out.println( grid.getEnvelope());
>>>     reader.dispose();
>>>     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, null/*params.values().toArray(new 
>>> GeneralParameterValue[1])*/);
>>>     writer.dispose();
>>>     byte[] bytes = baos.toByteArray();
>>>
>>>     //Deserialization:
>>>
>>>     ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
>>>     GeoTiffReader reader2 = null;
>>>     hints = new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE);
>>>     reader2 = new GeoTiffReader(bais, hints);
>>>     GridCoverage2D coverage = reader2.read(null);
>>>     bais.close();
>>>     System.out.println( coverage.getEnvelope2D());
>>>     System.out.println( coverage.getEnvelope());
>>> }
>>>
>>>
>>> which gives me
>>>
>>> Envelope2D[(833207.8127810268, 9785025.96070077), (833286.9776217749, 
>>> 9785090.075567605)]
>>> GeneralEnvelope[(833207.8127810268, 9785025.96070077), (833286.9776217749, 
>>> 9785090.075567605)]
>>>
>>> Envelope2D[(833207.8127810268, 9785025.96070077), (833286.9776217749, 
>>> 9785090.075567605)]
>>> GeneralEnvelope[(833207.8127810268, 9785025.96070077), (833286.9776217749, 
>>> 9785090.075567605)]
>>>
>>> Where the bounds of the output and input grid match exactly.
>>>
>>> Ian
>>>
>>> On Thu, 7 Jan 2021 at 16:28, Lorenzo Di Giacomo <loridi...@gmail.com> wrote:
>>>>
>>>> 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
>>>
>>>
>>>
>>> --
>>> Ian Turton
>>
>>
>>
>> --
>> Ian Turton
>
>
>
> --
> Ian Turton


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

Reply via email to