Commit 26a346df authored by Bborie Park's avatar Bborie Park

Merge branch '2221_WKB_HexWKB'

git-svn-id: http://svn.osgeo.org/postgis/trunk@16385 b70326c6-7e19-0410-871a-916f4a2858ee
parent cc08d6c6
Pipeline #17746644 failed with stage
in 53 seconds
......@@ -8300,11 +8300,122 @@ SELECT rid, ST_ValueCount(rast,2,100) As count
</refentry>
</sect1>
<sect1 id="Raster_Inputs">
<title>Raster Inputs</title>
<refentry id="RT_ST_RastFromWKB">
<refnamediv>
<refname>ST_RastFromWKB</refname>
<refpurpose>Return a raster value from a Well-Known Binary (WKB) raster.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>raster <function>ST_RastFromWKB</function></funcdef>
<paramdef><type>bytea </type> <parameter>wkb</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>
Given a Well-Known Binary (WKB) raster, return a raster.
</para>
<para>Availability: 2.5.0</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>
SELECT (ST_Metadata(
ST_RastFromWKB(
'\001\000\000\000\000\000\000\000\000\000\000\000@\000\000\000\000\000\000\010@\000\000\000\000\000\000\340?\000\000\000\000\000\000\340?\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\012\000\000\000\012\000\024\000'::bytea
)
)).* AS metadata;
upperleftx | upperlefty | width | height | scalex | scaley | skewx | skewy | srid | numbands
------------+------------+-------+--------+--------+--------+-------+-------+------+----------
0.5 | 0.5 | 10 | 20 | 2 | 3 | 0 | 0 | 10 | 0
</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para>
<xref linkend="RT_ST_MetaData" />,
<xref linkend="RT_ST_RastFromHexWKB" />,
<xref linkend="RT_ST_AsBinary" />,
<xref linkend="RT_ST_AsHexWKB" />
</para>
</refsection>
</refentry>
<refentry id="RT_ST_RastFromHexWKB">
<refnamediv>
<refname>ST_RastFromHexWKB</refname>
<refpurpose>Return a raster value from a Hex representation of Well-Known Binary (WKB) raster.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>raster <function>ST_RastFromHexWKB</function></funcdef>
<paramdef><type>text </type> <parameter>wkb</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>
Given a Well-Known Binary (WKB) raster in Hex representation, return a raster.
</para>
<para>Availability: 2.5.0</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>
SELECT (ST_Metadata(
ST_RastFromHexWKB(
'010000000000000000000000400000000000000840000000000000E03F000000000000E03F000000000000000000000000000000000A0000000A001400'
)
)).* AS metadata;
upperleftx | upperlefty | width | height | scalex | scaley | skewx | skewy | srid | numbands
------------+------------+-------+--------+--------+--------+-------+-------+------+----------
0.5 | 0.5 | 10 | 20 | 2 | 3 | 0 | 0 | 10 | 0
</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para>
<xref linkend="RT_ST_MetaData" />,
<xref linkend="RT_ST_RastFromWKB" />,
<xref linkend="RT_ST_AsBinary" />,
<xref linkend="RT_ST_AsHexWKB" />
</para>
</refsection>
</refentry>
</sect1>
<sect1 id="Raster_Outputs">
<title>Raster Outputs</title>
<refentry id="RT_ST_AsBinary">
<refnamediv>
<refname>ST_AsBinary</refname>
<refname>ST_AsBinary/ST_AsWKB</refname>
<refpurpose>Return the Well-Known Binary (WKB) representation of the raster.</refpurpose>
</refnamediv>
......@@ -8315,6 +8426,11 @@ SELECT rid, ST_ValueCount(rast,2,100) As count
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef choice="opt"><type>boolean </type> <parameter>outasin=FALSE</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>bytea <function>ST_AsWKB</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef choice="opt"><type>boolean </type> <parameter>outasin=FALSE</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
......@@ -8336,6 +8452,7 @@ SELECT rid, ST_ValueCount(rast,2,100) As count
</note>
<para>Enhanced: 2.1.0 Addition of <varname>outasin</varname></para>
<para>Enhanced: 2.5.0 Addition of <varname>ST_AsWKB</varname></para>
</refsection>
<refsection>
......@@ -8346,12 +8463,73 @@ SELECT ST_AsBinary(rast) As rastbin FROM dummy_rast WHERE rid=1;
rastbin
---------------------------------------------------------------------------------
\001\000\000\000\000\000\000\000\000\000\000\000@\000\000\000\000\000\000\010@\
000\000\000\000\000\000\340?\000\000\000\000\000\000\340?\000\000\000\000\000\00
0\000\000\000\000\000\000\000\000\000\000\012\000\000\000\012\000\024\000
\001\000\000\000\000\000\000\000\000\000\000\000@\000\000\000\000\000\000\010@\000\000\000\000\000\000\340?\000\000\000\000\000\000\340?\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\012\000\000\000\012\000\024\000
</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para>
<xref linkend="RT_ST_RastFromWKB" />,
<xref linkend="RT_ST_AsHexWKB" />
</para>
</refsection>
</refentry>
<refentry id="RT_ST_AsHexWKB">
<refnamediv>
<refname>ST_AsHexWKB</refname>
<refpurpose>Return the Well-Known Binary (WKB) in Hex representation of the raster.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>bytea <function>ST_AsHexWKB</function></funcdef>
<paramdef><type>raster </type> <parameter>rast</parameter></paramdef>
<paramdef choice="opt"><type>boolean </type> <parameter>outasin=FALSE</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>
Returns the Binary representation in Hex representation of the raster. If <varname>outasin</varname> is TRUE, out-db bands are treated as in-db.
Refer to raster/doc/RFC2-WellKnownBinaryFormat located in the PostGIS source folder for details of the representation.
</para>
<note>
<para>
By default, Hex WKB output contains the external file path for out-db bands. If the client does not have access to the raster file underlying an out-db band, set <varname>outasin</varname> to TRUE.</para>
</note>
<para>Availability: 2.5.0 </para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>
SELECT ST_AsHexWKB(rast) As rastbin FROM dummy_rast WHERE rid=1;
st_ashexwkb
----------------------------------------------------------------------------------------------------------------------------
010000000000000000000000400000000000000840000000000000E03F000000000000E03F000000000000000000000000000000000A0000000A001400
</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<para>
<xref linkend="RT_ST_RastFromHexWKB" />,
<xref linkend="RT_ST_AsBinary" />
</para>
</refsection>
</refentry>
<refentry id="RT_ST_AsGDALRaster">
......
......@@ -41,6 +41,7 @@ OBJS = \
rtpg_mapalgebra.o \
rtpg_utility.o \
rtpg_inout.o \
rtpg_wkb.o \
rtpg_geometry.o \
rtpg_raster_properties.o \
rtpg_band_properties.o \
......
......@@ -331,9 +331,7 @@ Datum RASTER_getBandPath(PG_FUNCTION_ARGS)
PG_RETURN_NULL();
}
result = (text *) palloc(VARHDRSZ + strlen(bandpath) + 1);
SET_VARSIZE(result, VARHDRSZ + strlen(bandpath) + 1);
strcpy((char *) VARDATA(result), bandpath);
result = cstring_to_text(bandpath);
rt_band_destroy(band);
rt_raster_destroy(raster);
......
......@@ -34,14 +34,14 @@
Datum RASTER_in(PG_FUNCTION_ARGS);
Datum RASTER_out(PG_FUNCTION_ARGS);
Datum RASTER_noop(PG_FUNCTION_ARGS);
Datum RASTER_to_bytea(PG_FUNCTION_ARGS);
Datum RASTER_to_binary(PG_FUNCTION_ARGS);
Datum RASTER_noop(PG_FUNCTION_ARGS);
/**
* Input is a string with hex chars in it.
* Convert to binary and put in the result
* Input is Hex WKB
* Used as the input function of the raster type
*/
PG_FUNCTION_INFO_V1(RASTER_in);
Datum RASTER_in(PG_FUNCTION_ARGS)
......@@ -66,7 +66,8 @@ Datum RASTER_in(PG_FUNCTION_ARGS)
}
/**
* Given a RASTER structure, convert it to Hex and put it in a string
* Output is Hex WKB
* Used as the output function of the raster type
*/
PG_FUNCTION_INFO_V1(RASTER_out);
Datum RASTER_out(PG_FUNCTION_ARGS)
......@@ -84,7 +85,7 @@ Datum RASTER_out(PG_FUNCTION_ARGS)
raster = rt_raster_deserialize(pgraster, FALSE);
if (!raster) {
PG_FREE_IF_COPY(pgraster, 0);
elog(ERROR, "RASTER_out: Could not deserialize raster");
elog(ERROR, "RASTER_out: Cannot deserialize raster");
PG_RETURN_NULL();
}
......@@ -92,7 +93,7 @@ Datum RASTER_out(PG_FUNCTION_ARGS)
if (!hexwkb) {
rt_raster_destroy(raster);
PG_FREE_IF_COPY(pgraster, 0);
elog(ERROR, "RASTER_out: Could not HEX-WKBize raster");
elog(ERROR, "RASTER_out: Cannot HEX-WKBize raster");
PG_RETURN_NULL();
}
......@@ -104,7 +105,8 @@ Datum RASTER_out(PG_FUNCTION_ARGS)
}
/**
* Return bytea object with raster in Well-Known-Binary form.
* Output is WKB
* Used to cast a raster to a bytea
*/
PG_FUNCTION_INFO_V1(RASTER_to_bytea);
Datum RASTER_to_bytea(PG_FUNCTION_ARGS)
......@@ -123,7 +125,7 @@ Datum RASTER_to_bytea(PG_FUNCTION_ARGS)
raster = rt_raster_deserialize(pgraster, FALSE);
if (!raster) {
PG_FREE_IF_COPY(pgraster, 0);
elog(ERROR, "RASTER_to_bytea: Could not deserialize raster");
elog(ERROR, "RASTER_to_bytea: Cannot deserialize raster");
PG_RETURN_NULL();
}
......@@ -132,7 +134,7 @@ Datum RASTER_to_bytea(PG_FUNCTION_ARGS)
if (!wkb) {
rt_raster_destroy(raster);
PG_FREE_IF_COPY(pgraster, 0);
elog(ERROR, "RASTER_to_bytea: Could not allocate and generate WKB data");
elog(ERROR, "RASTER_to_bytea: Cannot allocate and generate WKB data");
PG_RETURN_NULL();
}
......@@ -151,56 +153,8 @@ Datum RASTER_to_bytea(PG_FUNCTION_ARGS)
}
/**
* Return bytea object with raster in Well-Known-Binary form requested using ST_AsBinary function.
* Deserialize and then immediately serialize. Debugging function
*/
PG_FUNCTION_INFO_V1(RASTER_to_binary);
Datum RASTER_to_binary(PG_FUNCTION_ARGS)
{
rt_pgraster *pgraster = NULL;
rt_raster raster = NULL;
uint8_t *wkb = NULL;
uint32_t wkb_size = 0;
char *result = NULL;
int result_size = 0;
int outasin = FALSE;
if (PG_ARGISNULL(0)) PG_RETURN_NULL();
pgraster = (rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
/* Get raster object */
raster = rt_raster_deserialize(pgraster, FALSE);
if (!raster) {
PG_FREE_IF_COPY(pgraster, 0);
elog(ERROR, "RASTER_to_binary: Could not deserialize raster");
PG_RETURN_NULL();
}
if (!PG_ARGISNULL(1))
outasin = PG_GETARG_BOOL(1);
/* Parse raster to wkb object */
wkb = rt_raster_to_wkb(raster, outasin, &wkb_size);
if (!wkb) {
rt_raster_destroy(raster);
PG_FREE_IF_COPY(pgraster, 0);
elog(ERROR, "RASTER_to_binary: Could not allocate and generate WKB data");
PG_RETURN_NULL();
}
/* Create varlena object */
result_size = wkb_size + VARHDRSZ;
result = (char *)palloc(result_size);
SET_VARSIZE(result, result_size);
memcpy(VARDATA(result), wkb, VARSIZE(result) - VARHDRSZ);
/* Free raster objects used */
rt_raster_destroy(raster);
pfree(wkb);
PG_FREE_IF_COPY(pgraster, 0);
PG_RETURN_POINTER(result);
}
PG_FUNCTION_INFO_V1(RASTER_noop);
Datum RASTER_noop(PG_FUNCTION_ARGS)
{
......@@ -210,7 +164,7 @@ Datum RASTER_noop(PG_FUNCTION_ARGS)
raster = rt_raster_deserialize(pgraster, FALSE);
if (!raster) {
PG_FREE_IF_COPY(pgraster, 0);
elog(ERROR, "RASTER_noop: Could not deserialize raster");
elog(ERROR, "RASTER_noop: Cannot deserialize raster");
PG_RETURN_NULL();
}
result = rt_raster_serialize(raster);
......
......@@ -36,7 +36,7 @@
#include <executor/spi.h>
#include <utils/lsyscache.h> /* for get_typlenbyvalalign */
#include <utils/array.h> /* for ArrayType */
#include <utils/builtins.h>
#include <utils/builtins.h> /* for cstring_to_text */
#include <catalog/pg_type.h> /* for INT2OID, INT4OID, FLOAT4OID, FLOAT8OID and TEXTOID */
#include <executor/executor.h> /* for GetAttributeByName */
......
/*
*
* WKTRaster - Raster Types for PostGIS
* http://trac.osgeo.org/postgis/wiki/WKTRaster
*
* Copyright (C) 2018-2018 Bborie Park <dustymugs@gmail.com>
* Copyright (C) 2011-2013 Regents of the University of California
* <bkpark@ucdavis.edu>
* Copyright (C) 2010-2011 Jorge Arevalo <jorge.arevalo@deimos-space.com>
* Copyright (C) 2010-2011 David Zwarg <dzwarg@azavea.com>
* Copyright (C) 2009-2011 Pierre Racine <pierre.racine@sbf.ulaval.ca>
* Copyright (C) 2009-2011 Mateusz Loskot <mateusz@loskot.net>
* Copyright (C) 2008-2009 Sandro Santilli <strk@kbt.io>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include <postgres.h> /* for palloc */
#include <fmgr.h> /* for PG_*, Datum* */
#include <utils/builtins.h> /* for cstring_to_text */
#include "rtpostgis.h"
Datum RASTER_asWKB(PG_FUNCTION_ARGS);
Datum RASTER_asHexWKB(PG_FUNCTION_ARGS);
Datum RASTER_fromWKB(PG_FUNCTION_ARGS);
Datum RASTER_fromHexWKB(PG_FUNCTION_ARGS);
/**
* Output is WKB
*/
PG_FUNCTION_INFO_V1(RASTER_asWKB);
Datum RASTER_asWKB(PG_FUNCTION_ARGS)
{
rt_pgraster *pgraster = NULL;
rt_raster raster = NULL;
uint8_t *wkb = NULL;
uint32_t wkb_size = 0;
char *result = NULL;
int result_size = 0;
int outasin = FALSE;
if (PG_ARGISNULL(0)) PG_RETURN_NULL();
pgraster = (rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
/* Get raster object */
raster = rt_raster_deserialize(pgraster, FALSE);
if (!raster) {
PG_FREE_IF_COPY(pgraster, 0);
elog(ERROR, "RASTER_asWKB: Cannot deserialize raster");
PG_RETURN_NULL();
}
if (!PG_ARGISNULL(1))
outasin = PG_GETARG_BOOL(1);
/* Parse raster to wkb object */
wkb = rt_raster_to_wkb(raster, outasin, &wkb_size);
if (!wkb) {
rt_raster_destroy(raster);
PG_FREE_IF_COPY(pgraster, 0);
elog(ERROR, "RASTER_asWKB: Cannot allocate and generate WKB data");
PG_RETURN_NULL();
}
/* Create varlena object */
result_size = wkb_size + VARHDRSZ;
result = (char *)palloc(result_size);
SET_VARSIZE(result, result_size);
memcpy(VARDATA(result), wkb, VARSIZE(result) - VARHDRSZ);
/* Free raster objects used */
rt_raster_destroy(raster);
pfree(wkb);
PG_FREE_IF_COPY(pgraster, 0);
PG_RETURN_POINTER(result);
}
/**
* Output is Hex WKB
*/
PG_FUNCTION_INFO_V1(RASTER_asHexWKB);
Datum RASTER_asHexWKB(PG_FUNCTION_ARGS)
{
rt_pgraster *pgraster = NULL;
rt_raster raster = NULL;
int outasin = FALSE;
uint32_t hexwkbsize = 0;
char *hexwkb = NULL;
text *result = NULL;
POSTGIS_RT_DEBUG(3, "Starting");
if (PG_ARGISNULL(0)) PG_RETURN_NULL();
pgraster = (rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
raster = rt_raster_deserialize(pgraster, FALSE);
if (!raster) {
PG_FREE_IF_COPY(pgraster, 0);
elog(ERROR, "RASTER_asHexWKB: Cannot deserialize raster");
PG_RETURN_NULL();
}
if (!PG_ARGISNULL(1))
outasin = PG_GETARG_BOOL(1);
hexwkb = rt_raster_to_hexwkb(raster, outasin, &hexwkbsize);
if (!hexwkb) {
rt_raster_destroy(raster);
PG_FREE_IF_COPY(pgraster, 0);
elog(ERROR, "RASTER_asHexWKB: Cannot allocate and generate Hex WKB data");
PG_RETURN_NULL();
}
/* Free the raster objects used */
rt_raster_destroy(raster);
PG_FREE_IF_COPY(pgraster, 0);
result = cstring_to_text(hexwkb);
PG_RETURN_TEXT_P(result);
}
/**
* Input is WKB
*/
PG_FUNCTION_INFO_V1(RASTER_fromWKB);
Datum RASTER_fromWKB(PG_FUNCTION_ARGS)
{
bytea *bytea_data;
uint8_t *data;
int data_len = 0;
rt_raster raster;
void *result = NULL;
POSTGIS_RT_DEBUG(3, "Starting");
bytea_data = (bytea *) PG_GETARG_BYTEA_P(0);
data = (uint8_t *) VARDATA(bytea_data);
data_len = VARSIZE(bytea_data) - VARHDRSZ;
raster = rt_raster_from_wkb(data, data_len);
PG_FREE_IF_COPY(bytea_data, 0);
if (raster == NULL)
PG_RETURN_NULL();
result = rt_raster_serialize(raster);
rt_raster_destroy(raster);
if (result == NULL)
PG_RETURN_NULL();
SET_VARSIZE(result, ((rt_pgraster*)result)->size);
PG_RETURN_POINTER(result);
}
/**
* Input is Hex WKB
*/
PG_FUNCTION_INFO_V1(RASTER_fromHexWKB);
Datum RASTER_fromHexWKB(PG_FUNCTION_ARGS)
{
text *hexwkb_text = PG_GETARG_TEXT_P(0);
char *hexwkb;
rt_raster raster;
void *result = NULL;
POSTGIS_RT_DEBUG(3, "Starting");
hexwkb = text2cstring(hexwkb_text);
raster = rt_raster_from_hexwkb(hexwkb, strlen(hexwkb));
PG_FREE_IF_COPY(hexwkb_text, 0);
if (raster == NULL)
PG_RETURN_NULL();
result = rt_raster_serialize(raster);
rt_raster_destroy(raster);
if (result == NULL)
PG_RETURN_NULL();
SET_VARSIZE(result, ((rt_pgraster*)result)->size);
PG_RETURN_POINTER(result);
}
......@@ -79,11 +79,15 @@ $$ LANGUAGE 'plpgsql';
-- RASTER Type
------------------------------------------------------------------------------
-- part of Raster type
-- expects input to be Hex WKB
CREATE OR REPLACE FUNCTION raster_in(cstring)
RETURNS raster
AS 'MODULE_PATHNAME','RASTER_in'
LANGUAGE 'c' IMMUTABLE STRICT _PARALLEL;
-- part of Raster type
-- expects output to be Hex WKB
CREATE OR REPLACE FUNCTION raster_out(raster)
RETURNS cstring
AS 'MODULE_PATHNAME','RASTER_out'
......@@ -156,6 +160,7 @@ CREATE OR REPLACE FUNCTION st_envelope(raster)
-- Availability: 2.0.0
-- Changed: 2.1.4 raised cost
-- used to cast raster -> geometry
CREATE OR REPLACE FUNCTION st_convexhull(raster)
RETURNS geometry
AS 'MODULE_PATHNAME','RASTER_convex_hull'
......@@ -170,6 +175,7 @@ CREATE OR REPLACE FUNCTION st_minconvexhull(
AS 'MODULE_PATHNAME','RASTER_convex_hull'
LANGUAGE 'c' IMMUTABLE _PARALLEL;
-- used to cast raster -> box3d
CREATE OR REPLACE FUNCTION box3d(raster)
RETURNS box3d
AS 'select box3d( @extschema@.ST_convexhull($1))'
......@@ -5835,15 +5841,50 @@ CREATE OR REPLACE FUNCTION st_minpossiblevalue(pixeltype text)
AS 'MODULE_PATHNAME', 'RASTER_minPossibleValue'
LANGUAGE 'c' IMMUTABLE STRICT _PARALLEL;
-----------------------------------------------------------------------
-- Raster Inputs
-----------------------------------------------------------------------
-- expects input to be WKB
CREATE OR REPLACE FUNCTION st_rastfromwkb(bytea)
RETURNS raster
AS 'MODULE_PATHNAME', 'RASTER_fromWKB'
LANGUAGE 'c' IMMUTABLE STRICT _PARALLEL;
-- expectes input to be Hex WKB
CREATE OR REPLACE FUNCTION st_rastfromhexwkb(text)
RETURNS raster
AS 'MODULE_PATHNAME', 'RASTER_fromHexWKB'
LANGUAGE 'c' IMMUTABLE STRICT _PARALLEL;
-----------------------------------------------------------------------
-- Raster Outputs
-----------------------------------------------------------------------
-- Availability: 2.5.0
-- expects output to be WKB
-- ST_AsWKB() is functionally identitical to bytea()
-- kept separate as bytea(raster) is for casting
CREATE OR REPLACE FUNCTION st_aswkb(raster, outasin boolean DEFAULT FALSE)
RETURNS bytea
AS 'MODULE_PATHNAME', 'RASTER_asWKB'
LANGUAGE 'c' IMMUTABLE STRICT _PARALLEL;
-- Changed: 2.5.0 change logic to use ST_AsWKB. Deprecate in 2.6.0
-- expects output to be WKB
CREATE OR REPLACE FUNCTION st_asbinary(raster, outasin boolean DEFAULT FALSE)
RETURNS bytea
AS 'MODULE_PATHNAME', 'RASTER_to_binary'
AS $$ SELECT @extschema@.ST_AsWKB($1, $2) $$
LANGUAGE 'sql' IMMUTABLE STRICT _PARALLEL;
-- Availability: 2.5.0
-- expect output to be Hex WKB
CREATE OR REPLACE FUNCTION st_ashexwkb(raster, outasin boolean DEFAULT FALSE)
RETURNS text
AS 'MODULE_PATHNAME', 'RASTER_asHexWKB'
LANGUAGE 'c' IMMUTABLE STRICT _PARALLEL;
-- used to cast raster -> bytea
CREATE OR REPLACE FUNCTION bytea(raster)
RETURNS bytea
AS 'MODULE_PATHNAME', 'RASTER_to_bytea'
......
......@@ -57,6 +57,7 @@ TEST_IO = \
TEST_BASIC_FUNC = \
rt_bytea \
rt_wkb \
box3d \
rt_addband \
rt_band \
......
......@@ -177,42 +177,3 @@ WHERE
-- Cleanup
DROP TABLE rt_bytea_test;
-----------------------------------------------------------------------
--- Test out-db as in-db
-----------------------------------------------------------------------
SET postgis.gdal_enabled_drivers = 'GTiff';
SET postgis.enable_outdb_rasters = TRUE;
WITH foo AS (
SELECT
rid,
ST_AsBinary(rast, FALSE) AS outout,
ST_AsBinary(rast, TRUE) AS outin
FROM raster_outdb_template
)
SELECT
rid
FROM foo
WHERE encode(outout, 'base64') = encode(outin, 'base64');
WITH foo AS (
SELECT
rid,
rast::bytea AS outbytea,
ST_AsBinary(rast, FALSE) AS outout
FROM raster_outdb_template
)
SELECT
rid
FROM foo
WHERE encode(outbytea, 'base64') != encode(outout, 'base64');
WITH foo AS (
SELECT
rid,
rast::bytea AS outbytea,
ST_AsBinary(rast, TRUE) AS outin
FROM raster_outdb_template
)
SELECT
rid
FROM foo
WHERE encode(outbytea, 'base64') = encode(outin, 'base64');
SET postgis.gdal_enabled_drivers = 'GTiff';
SET postgis.enable_outdb_rasters = TRUE;
-----------------------------------------------------------------------
--- ST_AsWKB
-----------------------------------------------------------------------
WITH foo AS (
SELECT
rid,
ST_AsWKB(rast, FALSE) AS outout,
ST_AsWKB(rast, TRUE) AS outin
FROM raster_outdb_template
)
SELECT
rid
FROM foo
WHERE encode(outout, 'base64') = encode(outin, 'base64');
WITH foo AS (
SELECT
rid,
rast::bytea AS outbytea,
ST_AsWKB(rast, FALSE) AS outout
FROM raster_outdb_template