[GRASS5] Re: [GRASSLIST:2842] import raster

On Thu, Mar 04, 2004 at 04:55:44PM +0100, Daniele Scarselli wrote:

Hi,
I've a problem importing some raster:
I use r.in.gdal to import a raster and the results are files over 100 mb for
every raster.
With r.compress I reduce to 17,4 mb.
Is there a method to reduce again these files?
I think that GRASS take the raster as a 8 bit image while the original is
black and white (1 bit)
thanks
Daniele Scarselli

The code portion in question will be (main.c from r.in.gdal):

   switch(eRawGDT) {
      case GDT_Float32:
      case GDT_Float64:
        data_type = FCELL_TYPE;
        eGDT = GDT_Float32;
        complex = FALSE;
        break;

      case GDT_Byte:
        data_type = CELL_TYPE;
        eGDT = GDT_Int32;
        complex = FALSE;
        G_set_cell_format(0);
        raster_open_new_func = G_open_raster_new_uncompressed;
        break;

      case GDT_Int16:
      case GDT_UInt16:
        data_type = CELL_TYPE;
        eGDT = GDT_Int32;
        complex = FALSE;
        G_set_cell_format(1);
        raster_open_new_func = G_open_raster_new_uncompressed;
        break;

      default:
        data_type = CELL_TYPE;
        eGDT = GDT_Int32;
        complex = FALSE;
        G_set_cell_format(3);
        break;
    }

Anything to improve there?
The code portion in question will be (main.c from r.in.gdal):

   switch(eRawGDT) {
      case GDT_Float32:
      case GDT_Float64:
        data_type = FCELL_TYPE;
        eGDT = GDT_Float32;
        complex = FALSE;
        break;

      case GDT_Byte:
        data_type = CELL_TYPE;
        eGDT = GDT_Int32;
        complex = FALSE;
        G_set_cell_format(0);
        raster_open_new_func = G_open_raster_new_uncompressed;
        break;

      case GDT_Int16:
      case GDT_UInt16:
        data_type = CELL_TYPE;
        eGDT = GDT_Int32;
        complex = FALSE;
        G_set_cell_format(1);
        raster_open_new_func = G_open_raster_new_uncompressed;
        break;

      default:
        data_type = CELL_TYPE;
        eGDT = GDT_Int32;
        complex = FALSE;
        G_set_cell_format(3);
        break;
    }

Anything to improve ther
The code portion in question will be (main.c from r.in.gdal):

   switch(eRawGDT) {
      case GDT_Float32:
      case GDT_Float64:
        data_type = FCELL_TYPE;
        eGDT = GDT_Float32;
        complex = FALSE;
        break;

      case GDT_Byte:
        data_type = CELL_TYPE;
        eGDT = GDT_Int32;
        complex = FALSE;
        G_set_cell_format(0);
        raster_open_new_func = G_open_raster_new_uncompressed;
        break;

      case GDT_Int16:
      case GDT_UInt16:
        data_type = CELL_TYPE;
        eGDT = GDT_Int32;
        complex = FALSE;
        G_set_cell_format(1);
        raster_open_new_func = G_open_raster_new_uncompressed;
        break;

      default:
        data_type = CELL_TYPE;
        eGDT = GDT_Int32;
        complex = FALSE;
        G_set_cell_format(3);
        break;
    }

GDAL provides:

./gcore/gdal.h

/*! Pixel data types */
typedef enum {
    GDT_Unknown = 0,
    /*! Eight bit unsigned integer */ GDT_Byte = 1,
    /*! Sixteen bit unsigned integer */ GDT_UInt16 = 2,
    /*! Sixteen bit signed integer */ GDT_Int16 = 3,
    /*! Thirty two bit unsigned integer */ GDT_UInt32 = 4,
    /*! Thirty two bit signed integer */ GDT_Int32 = 5,
    /*! Thirty two bit floating point */ GDT_Float32 = 6,
    /*! Sixty four bit floating point */ GDT_Float64 = 7,
    /*! Complex Int16 */ GDT_CInt16 = 8,
    /*! Complex Int32 */ GDT_CInt32 = 9,
    /*! Complex Float32 */ GDT_CFloat32 = 10,
    /*! Complex Float64 */ GDT_CFloat64 = 11,
    GDT_TypeCount = 12 /* maximum type # + 1 */
} GDALDataType;

Anything to improve in r.in.gdal (we all like small files)?

Markus

On Thu, Mar 04, 2004 at 04:55:44PM +0100, Daniele Scarselli wrote:

Hi,
I've a problem importing some raster:
I use r.in.gdal to import a raster and the results are files over 100 mb for every raster.
With r.compress I reduce to 17,4 mb.
Is there a method to reduce again these files?
I think that GRASS take the raster as a 8 bit image while the original is black and white (1 bit)
thanks
Daniele Scarselli

Markus says:

Anything to improve in r.in.gdal (we all like small files)?

Daniele / Markus,

If you are reading a 1bit file, it will usually be treated as byte data by
the GDAL (depends on the driver). Byte data is written as integer cells.
I don't think there is anything else that would be appropriate.

I am curious what r.compress does that is special? Don't grass rasters normally
get compressed as they are written? Are import programs supposed to write
them compressed? It may be that the steps taking ... import and then compress
are normal practice?

Best regards,
--
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up | Frank Warmerdam, warmerdam@pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush | Geospatial Programmer for Rent

Markus Neteler wrote:

> I've a problem importing some raster:
> I use r.in.gdal to import a raster and the results are files over 100 mb for
> every raster.
> With r.compress I reduce to 17,4 mb.
> Is there a method to reduce again these files?
> I think that GRASS take the raster as a 8 bit image while the original is
> black and white (1 bit)

Anything to improve in r.in.gdal (we all like small files)?

If the file is being compressed, the underlying format (1/2/4 bytes)
won't make much difference.

The only way to get any significant reduction in the file sizes would
be to use zlib (or similar) rather than RLE compression.

--
Glynn Clements <glynn.clements@virgin.net>

On Fri, Mar 05, 2004 at 05:58:43PM +0000, Glynn Clements wrote:

Markus Neteler wrote:

> > I've a problem importing some raster:
> > I use r.in.gdal to import a raster and the results are files over 100 mb for
> > every raster.
> > With r.compress I reduce to 17,4 mb.
> > Is there a method to reduce again these files?
> > I think that GRASS take the raster as a 8 bit image while the original is
> > black and white (1 bit)

> Anything to improve in r.in.gdal (we all like small files)?

If the file is being compressed, the underlying format (1/2/4 bytes)
won't make much difference.

The only way to get any significant reduction in the file sizes would
be to use zlib (or similar) rather than RLE compression.

Do you refer to CELL type only? For FCELL/DCELL deflate should
be used aready, right?

To change from RLE to deflate (zlib) compression would need an
update for all CELL maps, I assume (a pity that it wasn't done
when we eliminated LZW).

Markus

Markus Neteler wrote:

> > > I've a problem importing some raster:
> > > I use r.in.gdal to import a raster and the results are files over 100 mb for
> > > every raster.
> > > With r.compress I reduce to 17,4 mb.
> > > Is there a method to reduce again these files?
> > > I think that GRASS take the raster as a 8 bit image while the original is
> > > black and white (1 bit)
>
> > Anything to improve in r.in.gdal (we all like small files)?
>
> If the file is being compressed, the underlying format (1/2/4 bytes)
> won't make much difference.
>
> The only way to get any significant reduction in the file sizes would
> be to use zlib (or similar) rather than RLE compression.

Do you refer to CELL type only? For FCELL/DCELL deflate should
be used aready, right?

Yes.

--
Glynn Clements <glynn.clements@virgin.net>