Re: [JPP-Devel] SVN: [6507] core/trunk/src/org/openjump/core/rasterimage

2020-09-22 Thread Rahkonen Jukka (MML)
Hi,

What is the question? TIFF files can have either internal or external overviews 
and if client supports them it is much faster to render the image at small 
scales. I have no idea about what readers can handle internal/external 
overviews but I can arrange test images easily.
External overviews are not very common but because they are external they are 
handy for testing what resampling method feels best. Also it is easier to 
delete the .ovr file than the internal overviews if user wants to archive the 
image and save the 30% of disk space that overviews take.

-Jukka Rahkonen-

Lähettäjä: Giuseppe Aruta 
Lähetetty: tiistai 22. syyskuuta 2020 17.19
Vastaanottaja: OpenJump develop and use 
Aihe: Re: [JPP-Devel] SVN: [6507] core/trunk/src/org/openjump/core/rasterimage

Let us wait  for Michael and Jukka's opinion about it.
I am not sure but possibly it was request by one of the member of the list 
years ago to Alberto De Luca who implemented this part of the code.
I prefer to  comment out and build a new clean method

Il giorno mar 22 set 2020 alle ore 15:29 
mailto:edgar.sol...@web.de>> ha scritto:


On 9/22/2020 13:49, Giuseppe Aruta wrote:
>> +   private static ImageAndMetadata readImage(File tiffFile, int 
>> overviewIndex, int indexStart, Point originalSize,
>> +   Resolution originalCellSize, Envelope wholeImageEnvelope, 
>> Envelope viewportEnvelope, double noDataValue,
>> +   Stats stats) throws IOException, NoninvertibleTransformException 
>> {
>> +
>> + ImageInputStream imageInputStream = 
>> ImageIO.createImageInputStream(tiffFile);
>> + Iterator iterator = 
>> ImageIO.getImageReaders(imageInputStream);
>
> this seems to be a leftover. we want to enforce a specific TIFF reader, which 
> seems not to be done here.
>
> why exactly are there two readImage() methods needed anyway? one should 
> suffice. can you remove it?
>
> Not sure. As it tries to read overviews of a file from an external .ovr file. 
> I have never used or found it in projects. Once I tried to save a tiff with 
> overviews using QGIS: I had back two files, a TIF and a OVR one. But when I 
> tried to load this  couple into OpenJUMP, it took so long that I gave up. 
> AFAIR this was a request of many years ago from someone of the list

why not remove it then, if it's not used or working anyway? if you want to keep 
it, to have a go at it in the future, i'd suggest to at least to deactivate it, 
just to make sure it is no code path used accidentially.

a hack i use sometimes is to add

// explain why!
if (true) throw new java.lang.UnsupportedOperationException();

before some code i want to deactivate. this way the code does not have to be 
commented out and stays readable but will not be used anyway.

..ede


___
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net<mailto:Jump-pilot-devel@lists.sourceforge.net>
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel
___
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel


Re: [JPP-Devel] SVN: [6507] core/trunk/src/org/openjump/core/rasterimage

2020-09-22 Thread edgar . soldin
On 22.09.2020 16:18, Giuseppe Aruta wrote:
> I prefer to  comment out and build a new clean method

up to you. as long as it is not active while we are trying to beat it into 
shape ;).. ede


___
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel


Re: [JPP-Devel] SVN: [6507] core/trunk/src/org/openjump/core/rasterimage

2020-09-22 Thread Giuseppe Aruta
Let us wait  for Michael and Jukka's opinion about it.
I am not sure but possibly it was request by one of the member of the list
years ago to Alberto De Luca who implemented this part of the code.
I prefer to  comment out and build a new clean method

Il giorno mar 22 set 2020 alle ore 15:29  ha scritto:

>
>
> On 9/22/2020 13:49, Giuseppe Aruta wrote:
> >> +   private static ImageAndMetadata readImage(File tiffFile, int
> overviewIndex, int indexStart, Point originalSize,
> >> +   Resolution originalCellSize, Envelope wholeImageEnvelope,
> Envelope viewportEnvelope, double noDataValue,
> >> +   Stats stats) throws IOException,
> NoninvertibleTransformException {
> >> +
> >> + ImageInputStream imageInputStream =
> ImageIO.createImageInputStream(tiffFile);
> >> + Iterator iterator =
> ImageIO.getImageReaders(imageInputStream);
> >
> > this seems to be a leftover. we want to enforce a specific TIFF reader,
> which seems not to be done here.
> >
> > why exactly are there two readImage() methods needed anyway? one should
> suffice. can you remove it?
> >
> > Not sure. As it tries to read overviews of a file from an external .ovr
> file. I have never used or found it in projects. Once I tried to save a
> tiff with overviews using QGIS: I had back two files, a TIF and a OVR one.
> But when I tried to load this  couple into OpenJUMP, it took so long that I
> gave up. AFAIR this was a request of many years ago from someone of the list
>
> why not remove it then, if it's not used or working anyway? if you want to
> keep it, to have a go at it in the future, i'd suggest to at least to
> deactivate it, just to make sure it is no code path used accidentially.
>
> a hack i use sometimes is to add
>
> // explain why!
> if (true) throw new java.lang.UnsupportedOperationException();
>
> before some code i want to deactivate. this way the code does not have to
> be commented out and stays readable but will not be used anyway.
>
> ..ede
>
>
> ___
> Jump-pilot-devel mailing list
> Jump-pilot-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel
>
___
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel


Re: [JPP-Devel] SVN: [6507] core/trunk/src/org/openjump/core/rasterimage

2020-09-22 Thread edgar . soldin



On 9/22/2020 13:49, Giuseppe Aruta wrote:

+       private static ImageAndMetadata readImage(File tiffFile, int 
overviewIndex, int indexStart, Point originalSize,
+           Resolution originalCellSize, Envelope wholeImageEnvelope, Envelope 
viewportEnvelope, double noDataValue,
+           Stats stats) throws IOException, NoninvertibleTransformException {
+
+         ImageInputStream imageInputStream = 
ImageIO.createImageInputStream(tiffFile);
+         Iterator iterator = 
ImageIO.getImageReaders(imageInputStream);


this seems to be a leftover. we want to enforce a specific TIFF reader, which 
seems not to be done here.

why exactly are there two readImage() methods needed anyway? one should 
suffice. can you remove it?

Not sure. As it tries to read overviews of a file from an external .ovr file. I 
have never used or found it in projects. Once I tried to save a tiff with 
overviews using QGIS: I had back two files, a TIF and a OVR one. But when I 
tried to load this  couple into OpenJUMP, it took so long that I gave up. AFAIR 
this was a request of many years ago from someone of the list


why not remove it then, if it's not used or working anyway? if you want to keep 
it, to have a go at it in the future, i'd suggest to at least to deactivate it, 
just to make sure it is no code path used accidentially.

a hack i use sometimes is to add

// explain why!
if (true) throw new java.lang.UnsupportedOperationException();

before some code i want to deactivate. this way the code does not have to be 
commented out and stays readable but will not be used anyway.

..ede


___
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel


Re: [JPP-Devel] SVN: [6507] core/trunk/src/org/openjump/core/rasterimage

2020-09-22 Thread Giuseppe Aruta
*we already have support for reading
GeoReferencedRaster.parseGDALM**etaData(URI
uri) (seems format agnostic too). but that is depending on GDAL installed,
while the implementaion in TiffUtils.calculateStats() seems be plain java
utilizing some apache commons imaging code but is limited to TIFF files*.

Note that, together with Statistics, also NoData value is read using apache
commons. Possibly it can be used JAI staff instead (as in
AddRasterImageLayerWizard class).


Il giorno mar 22 set 2020 alle ore 13:49 Giuseppe Aruta <
giuseppe.ar...@gmail.com> ha scritto:

> > +   private static ImageAndMetadata readImage(File tiffFile, int
> overviewIndex, int indexStart, Point originalSize,
> > +   Resolution originalCellSize, Envelope wholeImageEnvelope,
> Envelope viewportEnvelope, double noDataValue,
> > +   Stats stats) throws IOException,
> NoninvertibleTransformException {
> > +
> > + ImageInputStream imageInputStream =
> ImageIO.createImageInputStream(tiffFile);
> > + Iterator iterator =
> ImageIO.getImageReaders(imageInputStream);
>
> this seems to be a leftover. we want to enforce a specific TIFF reader,
> which seems not to be done here.
>
> why exactly are there two readImage() methods needed anyway? one should
> suffice. can you remove it?
>
> Not sure. As it tries to read overviews of a file from an external .ovr
> file. I have never used or found it in projects. Once I tried to save a
> tiff with overviews using QGIS: I had back two files, a TIF and a OVR one.
> But when I tried to load this  couple into OpenJUMP, it took so long that I
> gave up. AFAIR this was a request of many years ago from someone of the list
>
> Il giorno mar 22 set 2020 alle ore 13:07  ha scritto:
>
>> we already have support for reading
>> GeoReferencedRaster.parseGDALMetaData(URI uri) (seems format agnostic too).
>> but that is depending on GDAL installed, while the implementaion in
>> TiffUtils.calculateStats() seems be plain java utilizing some apache
>> commons imaging code but is limited to TIFF files.
>>
>> note the following comment in GeoRefRaster
>>/**
>> * initialize the img and try to parse geo infos via (in this order)
>> * worldfile, gdal or geotiff
>> */
>>protected void readRasterfile() throws ReferencedImageException {
>>
>> tl;dr i am good with keeping the addtional metadata reading within
>> TiffUtils generally. still you my want to consider a caching approach there
>> as well if the info is accessed more than once and expected not to change
>> over the course of the runtime.
>>
>> ..ede
>>
>> On 9/22/2020 12:32, Giuseppe Aruta wrote:
>> > I will make those changes. Statistics are calculated in order to reuse
>> on raster analysis (sextante). It is also saved into a special .aux.xml
>> sidecar file.
>> > At this moment there is no need to implement GeoReferencedRaster with
>> Statistic read as it is uìused only by Sextante.
>> >
>> > Il giorno mar 22 set 2020 alle ore 11:59 > edgar.sol...@web.de>> ha scritto:
>> >
>> > hey Peppe,
>> >
>> > nice try, but no dice. the reason i created an explicit TiffUtilsV2
>> was
>> > to make sure it contains no reference to RasterImageIO or TiffTags
>> > anymore. the idea is to wrap GeoReferencedRaster functionality to
>> reuse.
>> > GeoReferencedRaster includes all functionality for retrieving an
>> > Envelope or dimensions needed.
>> >
>> > If you are lacking functionality in GeoReferencedRaster we may add
>> it
>> > accordingly.
>> >
>> > i cut some code parts below and commented them which should be
>> replaced
>> > by using GeoReferencedRaster routines. ..ede
>> >
>> >
>> >
>> > On 9/22/2020 11:26, jump-pilot-svn--- via Jump-pilot-devel wrote:
>> >  > Revision: 6507
>> >  > http://sourceforge.net/p/jump-pilot/code/6507 <
>> http://sourceforge.net/p/jump-pilot/code/6507>
>> >  > Author:   ma15569
>> >  > Date: 2020-09-22 09:26:19 + (Tue, 22 Sep 2020)
>> >  > Log Message:
>> >  > ---
>> >  > Ported functionality from TiffUtils to TiffUtilsV2.
>> >  > Make TiffUtils deprecated
>> >  >
>> > SNIP
>>
>>
>>
>>
>> ___
>> Jump-pilot-devel mailing list
>> Jump-pilot-devel@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel
>>
>
___
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel


Re: [JPP-Devel] SVN: [6507] core/trunk/src/org/openjump/core/rasterimage

2020-09-22 Thread Giuseppe Aruta
> +   private static ImageAndMetadata readImage(File tiffFile, int
overviewIndex, int indexStart, Point originalSize,
> +   Resolution originalCellSize, Envelope wholeImageEnvelope,
Envelope viewportEnvelope, double noDataValue,
> +   Stats stats) throws IOException,
NoninvertibleTransformException {
> +
> + ImageInputStream imageInputStream =
ImageIO.createImageInputStream(tiffFile);
> + Iterator iterator =
ImageIO.getImageReaders(imageInputStream);

this seems to be a leftover. we want to enforce a specific TIFF reader,
which seems not to be done here.

why exactly are there two readImage() methods needed anyway? one should
suffice. can you remove it?

Not sure. As it tries to read overviews of a file from an external .ovr
file. I have never used or found it in projects. Once I tried to save a
tiff with overviews using QGIS: I had back two files, a TIF and a OVR one.
But when I tried to load this  couple into OpenJUMP, it took so long that I
gave up. AFAIR this was a request of many years ago from someone of the list

Il giorno mar 22 set 2020 alle ore 13:07  ha scritto:

> we already have support for reading
> GeoReferencedRaster.parseGDALMetaData(URI uri) (seems format agnostic too).
> but that is depending on GDAL installed, while the implementaion in
> TiffUtils.calculateStats() seems be plain java utilizing some apache
> commons imaging code but is limited to TIFF files.
>
> note the following comment in GeoRefRaster
>/**
> * initialize the img and try to parse geo infos via (in this order)
> * worldfile, gdal or geotiff
> */
>protected void readRasterfile() throws ReferencedImageException {
>
> tl;dr i am good with keeping the addtional metadata reading within
> TiffUtils generally. still you my want to consider a caching approach there
> as well if the info is accessed more than once and expected not to change
> over the course of the runtime.
>
> ..ede
>
> On 9/22/2020 12:32, Giuseppe Aruta wrote:
> > I will make those changes. Statistics are calculated in order to reuse
> on raster analysis (sextante). It is also saved into a special .aux.xml
> sidecar file.
> > At this moment there is no need to implement GeoReferencedRaster with
> Statistic read as it is uìused only by Sextante.
> >
> > Il giorno mar 22 set 2020 alle ore 11:59  edgar.sol...@web.de>> ha scritto:
> >
> > hey Peppe,
> >
> > nice try, but no dice. the reason i created an explicit TiffUtilsV2
> was
> > to make sure it contains no reference to RasterImageIO or TiffTags
> > anymore. the idea is to wrap GeoReferencedRaster functionality to
> reuse.
> > GeoReferencedRaster includes all functionality for retrieving an
> > Envelope or dimensions needed.
> >
> > If you are lacking functionality in GeoReferencedRaster we may add it
> > accordingly.
> >
> > i cut some code parts below and commented them which should be
> replaced
> > by using GeoReferencedRaster routines. ..ede
> >
> >
> >
> > On 9/22/2020 11:26, jump-pilot-svn--- via Jump-pilot-devel wrote:
> >  > Revision: 6507
> >  > http://sourceforge.net/p/jump-pilot/code/6507 <
> http://sourceforge.net/p/jump-pilot/code/6507>
> >  > Author:   ma15569
> >  > Date: 2020-09-22 09:26:19 + (Tue, 22 Sep 2020)
> >  > Log Message:
> >  > ---
> >  > Ported functionality from TiffUtils to TiffUtilsV2.
> >  > Make TiffUtils deprecated
> >  >
> > SNIP
>
>
>
>
> ___
> Jump-pilot-devel mailing list
> Jump-pilot-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel
>
___
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel


Re: [JPP-Devel] SVN: [6507] core/trunk/src/org/openjump/core/rasterimage

2020-09-22 Thread edgar . soldin

we already have support for reading GeoReferencedRaster.parseGDALMetaData(URI 
uri) (seems format agnostic too). but that is depending on GDAL installed, 
while the implementaion in TiffUtils.calculateStats() seems be plain java 
utilizing some apache commons imaging code but is limited to TIFF files.

note the following comment in GeoRefRaster
  /**
   * initialize the img and try to parse geo infos via (in this order)
   * worldfile, gdal or geotiff
   */
  protected void readRasterfile() throws ReferencedImageException {

tl;dr i am good with keeping the addtional metadata reading within TiffUtils 
generally. still you my want to consider a caching approach there as well if 
the info is accessed more than once and expected not to change over the course 
of the runtime.

..ede

On 9/22/2020 12:32, Giuseppe Aruta wrote:

I will make those changes. Statistics are calculated in order to reuse on 
raster analysis (sextante). It is also saved into a special .aux.xml sidecar 
file.
At this moment there is no need to implement GeoReferencedRaster with Statistic 
read as it is uìused only by Sextante.

Il giorno mar 22 set 2020 alle ore 11:59 mailto:edgar.sol...@web.de>> ha scritto:

hey Peppe,

nice try, but no dice. the reason i created an explicit TiffUtilsV2 was
to make sure it contains no reference to RasterImageIO or TiffTags
anymore. the idea is to wrap GeoReferencedRaster functionality to reuse.
GeoReferencedRaster includes all functionality for retrieving an
Envelope or dimensions needed.

If you are lacking functionality in GeoReferencedRaster we may add it
accordingly.

i cut some code parts below and commented them which should be replaced
by using GeoReferencedRaster routines. ..ede



On 9/22/2020 11:26, jump-pilot-svn--- via Jump-pilot-devel wrote:
 > Revision: 6507
 > http://sourceforge.net/p/jump-pilot/code/6507 

 > Author:   ma15569
 > Date:     2020-09-22 09:26:19 + (Tue, 22 Sep 2020)
 > Log Message:
 > ---
 > Ported functionality from TiffUtils to TiffUtilsV2.
 > Make TiffUtils deprecated
 >
SNIP





___
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel


Re: [JPP-Devel] SVN: [6507] core/trunk/src/org/openjump/core/rasterimage

2020-09-22 Thread Giuseppe Aruta
I will make those changes. Statistics are calculated in order to reuse on
raster analysis (sextante). It is also saved into a special .aux.xml
sidecar file.
At this moment there is no need to implement GeoReferencedRaster with
Statistic read as it is uìused only by Sextante.

Il giorno mar 22 set 2020 alle ore 11:59  ha scritto:

> hey Peppe,
>
> nice try, but no dice. the reason i created an explicit TiffUtilsV2 was
> to make sure it contains no reference to RasterImageIO or TiffTags
> anymore. the idea is to wrap GeoReferencedRaster functionality to reuse.
> GeoReferencedRaster includes all functionality for retrieving an
> Envelope or dimensions needed.
>
> If you are lacking functionality in GeoReferencedRaster we may add it
> accordingly.
>
> i cut some code parts below and commented them which should be replaced
> by using GeoReferencedRaster routines. ..ede
>
>
>
> On 9/22/2020 11:26, jump-pilot-svn--- via Jump-pilot-devel wrote:
> > Revision: 6507
> >http://sourceforge.net/p/jump-pilot/code/6507
> > Author:   ma15569
> > Date: 2020-09-22 09:26:19 + (Tue, 22 Sep 2020)
> > Log Message:
> > ---
> > Ported functionality from TiffUtils to TiffUtilsV2.
> > Make TiffUtils deprecated
> >
> SNIP
> >
> >
> > Modified: core/trunk/src/org/openjump/core/rasterimage/TiffUtils.java
> > ===
> > --- core/trunk/src/org/openjump/core/rasterimage/TiffUtils.java
>  2020-09-21 13:32:21 UTC (rev 6506)
> > +++ core/trunk/src/org/openjump/core/rasterimage/TiffUtils.java
>  2020-09-22 09:26:19 UTC (rev 6507)
> > @@ -5,7 +5,6 @@
> SNIP
> >
> > Modified: core/trunk/src/org/openjump/core/rasterimage/TiffUtilsV2.java
> > ===
> > --- core/trunk/src/org/openjump/core/rasterimage/TiffUtilsV2.java
>  2020-09-21 13:32:21 UTC (rev 6506)
> > +++ core/trunk/src/org/openjump/core/rasterimage/TiffUtilsV2.java
>  2020-09-22 09:26:19 UTC (rev 6507)
> > @@ -1,14 +1,37 @@
> >   package org.openjump.core.rasterimage;
> >
> SNIP
> >
> > @@ -66,4 +89,283 @@
> >   renderedOp = JAI.create("scale", parameterBlock);
> >   return JAI.create("scale", parameterBlock);
> > }
> > +  public static ImageAndMetadata readImage(File tiffFile, Envelope
> viewportEnvelope, Resolution requestedRes,
> > +   Overviews overviews, Stats stats) throws
> NoninvertibleTransformException, IOException, FileNotFoundException,
> > +   TiffTags.TiffReadingException, Exception {
> > +
> > + // Try to read geotiff tags
> > + TiffTags.TiffMetadata tiffMetadata =
> TiffTags.readMetadata(tiffFile);
> > + int originalImageWidth = tiffMetadata.getColsCount();
> > + int originalImageHeight = tiffMetadata.getRowsCount();
> > + Resolution cellSize = tiffMetadata.getResolution();
> > + Double noData = tiffMetadata.getNoData();
> > +
> > + // Now try with tfw
> > + if (cellSize == null) {
> > +   WorldFileHandler worldFileHandler = new
> WorldFileHandler(tiffFile.getAbsolutePath(), true);
> > +   Envelope envelope =
> worldFileHandler.readWorldFile(originalImageWidth, originalImageHeight);
> > +   cellSize = new Resolution(envelope.getWidth() /
> originalImageWidth, envelope.getHeight() / originalImageHeight);
> > + }
>
> not needed. should be retrievable from GeoReferencedRaster
>
> > + Envelope wholeImageEnvelope =
> RasterImageIO.getGeoReferencing(tiffFile.getAbsolutePath(), true,
> > + new Point(originalImageWidth, originalImageHeight));
>
> Envelope as well.
>
> > + if (requestedRes == null) {
> > +   requestedRes = cellSize;
> > + }
> > +
> > + int overviewLevel = overviews.pickOverviewLevel(requestedRes);
> > +
> > + if (stats == null) {
> > +   // Statistics on all pixels
> > +   stats = calculateStats(tiffFile, noData, tiffFile);
> > + }
> > +
> SNIP
> > +   return imageAndMetadata;
> > +
> > + }
> > +
> > +   }
> > +
> > +   private static ImageAndMetadata readImage(File tiffFile, int
> overviewIndex, int indexStart, Point originalSize,
> > +   Resolution originalCellSize, Envelope wholeImageEnvelope,
> Envelope viewportEnvelope, double noDataValue,
> > +   Stats stats) throws IOException,
> NoninvertibleTransformException {
> > +
> > + ImageInputStream imageInputStream =
> ImageIO.createImageInputStream(tiffFile);
> > + Iterator iterator =
> ImageIO.getImageReaders(imageInputStream);
>
> this seems to be a leftover. we want to enforce a specific TIFF reader,
> which seems not to be done here.
>
> why exactly are there two readImage() methods needed anyway? one should
> suffice. can you remove it?
>
> > + if (iterator != null && iterator.hasNext()) {
> > +
> > +   ImageReader imageReader = iterator.next();
> > +   

Re: [JPP-Devel] SVN: [6507] core/trunk/src/org/openjump/core/rasterimage

2020-09-22 Thread edgar . soldin

hey Peppe,

nice try, but no dice. the reason i created an explicit TiffUtilsV2 was
to make sure it contains no reference to RasterImageIO or TiffTags
anymore. the idea is to wrap GeoReferencedRaster functionality to reuse.
GeoReferencedRaster includes all functionality for retrieving an
Envelope or dimensions needed.

If you are lacking functionality in GeoReferencedRaster we may add it
accordingly.

i cut some code parts below and commented them which should be replaced
by using GeoReferencedRaster routines. ..ede



On 9/22/2020 11:26, jump-pilot-svn--- via Jump-pilot-devel wrote:

Revision: 6507
   http://sourceforge.net/p/jump-pilot/code/6507
Author:   ma15569
Date: 2020-09-22 09:26:19 + (Tue, 22 Sep 2020)
Log Message:
---
Ported functionality from TiffUtils to TiffUtilsV2.
Make TiffUtils deprecated


SNIP
  


Modified: core/trunk/src/org/openjump/core/rasterimage/TiffUtils.java
===
--- core/trunk/src/org/openjump/core/rasterimage/TiffUtils.java 2020-09-21 
13:32:21 UTC (rev 6506)
+++ core/trunk/src/org/openjump/core/rasterimage/TiffUtils.java 2020-09-22 
09:26:19 UTC (rev 6507)
@@ -5,7 +5,6 @@

SNIP


Modified: core/trunk/src/org/openjump/core/rasterimage/TiffUtilsV2.java
===
--- core/trunk/src/org/openjump/core/rasterimage/TiffUtilsV2.java   
2020-09-21 13:32:21 UTC (rev 6506)
+++ core/trunk/src/org/openjump/core/rasterimage/TiffUtilsV2.java   
2020-09-22 09:26:19 UTC (rev 6507)
@@ -1,14 +1,37 @@
  package org.openjump.core.rasterimage;
  

SNIP
  
@@ -66,4 +89,283 @@

  renderedOp = JAI.create("scale", parameterBlock);
  return JAI.create("scale", parameterBlock);
}
+  public static ImageAndMetadata readImage(File tiffFile, Envelope 
viewportEnvelope, Resolution requestedRes,
+ Overviews overviews, Stats stats) throws 
NoninvertibleTransformException, IOException, FileNotFoundException,
+ TiffTags.TiffReadingException, Exception {
+
+   // Try to read geotiff tags
+   TiffTags.TiffMetadata tiffMetadata = 
TiffTags.readMetadata(tiffFile);
+   int originalImageWidth = tiffMetadata.getColsCount();
+   int originalImageHeight = tiffMetadata.getRowsCount();
+   Resolution cellSize = tiffMetadata.getResolution();
+   Double noData = tiffMetadata.getNoData();
+
+   // Now try with tfw
+   if (cellSize == null) {
+ WorldFileHandler worldFileHandler = new 
WorldFileHandler(tiffFile.getAbsolutePath(), true);
+ Envelope envelope = 
worldFileHandler.readWorldFile(originalImageWidth, originalImageHeight);
+ cellSize = new Resolution(envelope.getWidth() / 
originalImageWidth, envelope.getHeight() / originalImageHeight);
+   }


not needed. should be retrievable from GeoReferencedRaster


+   Envelope wholeImageEnvelope = 
RasterImageIO.getGeoReferencing(tiffFile.getAbsolutePath(), true,
+   new Point(originalImageWidth, originalImageHeight));


Envelope as well.


+   if (requestedRes == null) {
+ requestedRes = cellSize;
+   }
+
+   int overviewLevel = overviews.pickOverviewLevel(requestedRes);
+
+   if (stats == null) {
+ // Statistics on all pixels
+ stats = calculateStats(tiffFile, noData, tiffFile);
+   }
+

SNIP

+ return imageAndMetadata;
+
+   }
+
+ }
+
+ private static ImageAndMetadata readImage(File tiffFile, int 
overviewIndex, int indexStart, Point originalSize,
+ Resolution originalCellSize, Envelope wholeImageEnvelope, 
Envelope viewportEnvelope, double noDataValue,
+ Stats stats) throws IOException, NoninvertibleTransformException {
+
+   ImageInputStream imageInputStream = 
ImageIO.createImageInputStream(tiffFile);
+   Iterator iterator = 
ImageIO.getImageReaders(imageInputStream);


this seems to be a leftover. we want to enforce a specific TIFF reader, which 
seems not to be done here.

why exactly are there two readImage() methods needed anyway? one should 
suffice. can you remove it?


+   if (iterator != null && iterator.hasNext()) {
+
+ ImageReader imageReader = iterator.next();
+ imageReader.setInput(imageInputStream);
+ for (int i = 0; i < imageReader.getNumImages(true); i++) {
+   if (i + indexStart == overviewIndex) {
+
+ Resolution subsetResolution = new 
Resolution(wholeImageEnvelope.getWidth() / imageReader.getWidth(i),
+ wholeImageEnvelope.getHeight() / 
imageReader.getHeight(i));
+
+ Rectangle imageSubset = 
RasterImageIO.getDrawingRectangle(imageReader.getWidth(i), 
imageReader.getHeight(i),
+ wholeImageEnvelope, viewportEnvelope, subsetResolution);
+
+ BufferedImage 

[JPP-Devel] SVN: [6507] core/trunk/src/org/openjump/core/rasterimage

2020-09-22 Thread jump-pilot-svn--- via Jump-pilot-devel
Revision: 6507
  http://sourceforge.net/p/jump-pilot/code/6507
Author:   ma15569
Date: 2020-09-22 09:26:19 + (Tue, 22 Sep 2020)
Log Message:
---
Ported functionality from TiffUtils to TiffUtilsV2.
Make TiffUtils deprecated

Modified Paths:
--
core/trunk/src/org/openjump/core/rasterimage/RasterImageIO.java
core/trunk/src/org/openjump/core/rasterimage/TiffUtils.java
core/trunk/src/org/openjump/core/rasterimage/TiffUtilsV2.java

Modified: core/trunk/src/org/openjump/core/rasterimage/RasterImageIO.java
===
--- core/trunk/src/org/openjump/core/rasterimage/RasterImageIO.java 
2020-09-21 13:32:21 UTC (rev 6506)
+++ core/trunk/src/org/openjump/core/rasterimage/RasterImageIO.java 
2020-09-22 09:26:19 UTC (rev 6507)
@@ -26,7 +26,6 @@
 import org.apache.commons.imaging.ImageReadException;
 import org.apache.commons.imaging.formats.tiff.TiffField;
 import org.apache.commons.imaging.formats.tiff.fieldtypes.FieldType;
-import org.openjump.core.rasterimage.TiffTags.TiffMetadata;
 
 import com.sun.media.jai.codec.FileSeekableStream;
 import com.sun.media.jai.codec.TIFFDirectory;
@@ -38,8 +37,6 @@
 import com.vividsolutions.jts.geom.Envelope;
 import com.vividsolutions.jump.I18N;
 import com.vividsolutions.jump.workbench.WorkbenchContext;
-import com.vividsolutions.jump.workbench.imagery.ReferencedImageException;
-import com.vividsolutions.jump.workbench.imagery.geoimg.GeoReferencedRaster;
 import com.vividsolutions.jump.workbench.ui.Viewport;
 
 /**
@@ -146,7 +143,7 @@
   Envelope imageEnvelope = TiffUtilsV2.getEnvelope(tiffFile);
   Overviews overviews = OverviewsUtils.getOverviews(new 
File(fileNameOrURL), imageEnvelope);
 
-  return TiffUtils.readImage(tiffFile, viewPortEnvelope, requestedRes, 
overviews, stats);
+  return TiffUtilsV2.readImage(tiffFile, viewPortEnvelope, requestedRes, 
overviews, stats);
 
 } else if (fileNameOrURL.toLowerCase().endsWith(".flt")) {
 

Modified: core/trunk/src/org/openjump/core/rasterimage/TiffUtils.java
===
--- core/trunk/src/org/openjump/core/rasterimage/TiffUtils.java 2020-09-21 
13:32:21 UTC (rev 6506)
+++ core/trunk/src/org/openjump/core/rasterimage/TiffUtils.java 2020-09-22 
09:26:19 UTC (rev 6507)
@@ -5,7 +5,6 @@
 import java.awt.geom.NoninvertibleTransformException;
 import java.awt.image.BufferedImage;
 import java.awt.image.Raster;
-import java.awt.image.renderable.ParameterBlock;
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
@@ -16,9 +15,7 @@
 import javax.imageio.ImageReadParam;
 import javax.imageio.ImageReader;
 import javax.imageio.stream.ImageInputStream;
-import javax.media.jai.JAI;
 import javax.media.jai.RenderedOp;
-import javax.media.jai.util.ImagingListener;
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.transform.TransformerConfigurationException;
 import javax.xml.transform.TransformerException;
@@ -36,7 +33,10 @@
 /**
  *
  * @author AdL
+ * @deprecated moved all methods to newer
+ * org.openjump.core.rasterimage.TiffUtilsV2 class
  */
+@Deprecated
 public class TiffUtils {
 
   public static ImageAndMetadata readImage(File tiffFile, Envelope 
viewportEnvelope, Resolution requestedRes,

Modified: core/trunk/src/org/openjump/core/rasterimage/TiffUtilsV2.java
===
--- core/trunk/src/org/openjump/core/rasterimage/TiffUtilsV2.java   
2020-09-21 13:32:21 UTC (rev 6506)
+++ core/trunk/src/org/openjump/core/rasterimage/TiffUtilsV2.java   
2020-09-22 09:26:19 UTC (rev 6507)
@@ -1,14 +1,37 @@
 package org.openjump.core.rasterimage;
 
+import java.awt.Point;
+import java.awt.Rectangle;
+import java.awt.geom.NoninvertibleTransformException;
+import java.awt.image.BufferedImage;
+import java.awt.image.Raster;
 import java.awt.image.renderable.ParameterBlock;
 import java.io.File;
+import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
 
+import javax.imageio.ImageIO;
+import javax.imageio.ImageReadParam;
+import javax.imageio.ImageReader;
+import javax.imageio.stream.ImageInputStream;
 import javax.media.jai.JAI;
 import javax.media.jai.RenderedOp;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
 
+import org.apache.commons.imaging.ImageReadException;
+import org.apache.commons.imaging.formats.tiff.TiffField;
+import org.apache.commons.imaging.formats.tiff.TiffImageMetadata;
+import org.apache.commons.imaging.formats.tiff.TiffImageParser;
+import org.xml.sax.SAXException;
+
+import com.vividsolutions.jts.geom.Coordinate;
 import com.vividsolutions.jts.geom.Envelope;
+import com.vividsolutions.jump.workbench.Logger;
 import