[postgis-users] How to import/export PostGIS Raster data? Tools?

Paragon Corporation lr at pcorp.us
Thu Jan 6 13:02:27 PST 2011


Pierre,

> I plan to use GDAL not only for this ST_AsGDALRaster() function but also
to implement transparent use of out-of-db raster and for ST_Resample().

> Beside this Paul seemed to be happy that PostGIS could now use GDAL for I
don't remember which use.

>>I'd much rather have the deliberateness encoded in an enum.  Now that 
>> PostgreSQL 9.1 will allow altering enums, this will allow for infinite 
>> expansion of possibilities without function bloat and there are a a lot 
>> of raster types out there.
>>
>> http://developer.postgresql.org/pgdocs/postgres/sql-altertype.html

> You will have to elaborate a bit more on this for me to understand.
(Sometimes I'm very slow...)

Regarding the above, what I was thinking is that it would be nicer to have
an enum as input for the output format to the function since it's a
self-documenting structure.  That would allow for easy validation.
I've avoided it in the past since enums you couldn't add new entries to.  An
enum you can think of kind of like a lookup table packaged as a datatype.

So for example:

CREATE TYPE raster_format AS
ENUM('jpeg','gif','tiff');

CREATE FUNCTION  ST_AsGDALRaster(rast raster, fmt raster_format, options
text) RETURNS bytea AS
$$

$$

Then to use

SELECT ST_AsGDALRaster(rast, 'jpeg', '');

Or
SELECT ST_AsGDALRaster(rast, 'jpeg'::raster_format, '');


Since it's an enum,  it will throw an error if jpeg is not in the valid list
of options even before it enters the body of the function.

To get a list of valid options you would do:

SELECT enum_range(CAST(null AS raster_format));

Thanks,
Regina
http://www.postgis.us








More information about the postgis-users mailing list