Removed geotransform type. Fixed rounding, so Hudson will be my friend in raster regression tests.

git-svn-id: http://svn.osgeo.org/postgis/trunk@9114 b70326c6-7e19-0410-871a-916f4a2858ee
This commit is contained in:
David Zwarg 2012-02-08 21:03:39 +00:00
parent b8fc690fa5
commit b3b27f387b
4 changed files with 94 additions and 80 deletions

View file

@ -1607,32 +1607,34 @@ Datum RASTER_setGeotransform(PG_FUNCTION_ARGS)
PG_FUNCTION_INFO_V1(RASTER_getGeotransform);
Datum RASTER_getGeotransform(PG_FUNCTION_ARGS)
{
rt_pgraster *rast ;
rt_raster raster ;
float8 imag, jmag, theta_i, theta_ij, xoffset, yoffset ;
TupleDesc result_tuple ; /* for returning a composite */
HeapTuple heap_tuple ; /* instance of the tuple to return */
Oid result_oid ; /* internal code for the specific return type */
TypeFuncClass return_type ; /* is the return type a composite? */
Datum return_values[6] ;
bool nulls[6] ;
rt_pgraster *pgraster = NULL;
rt_raster raster = NULL;
/* setup the return value infrastructure */
return_type = get_call_result_type(fcinfo, &result_oid, &result_tuple) ;
if (return_type != TYPEFUNC_COMPOSITE) {
rterror("RASTER_getGeotransform(): function returning record called in context that cannot accept type record") ;
PG_RETURN_NULL() ;
}
result_tuple = BlessTupleDesc(result_tuple) ;
double imag;
double jmag;
double theta_i;
double theta_ij;
double xoffset;
double yoffset;
TupleDesc result_tuple; /* for returning a composite */
bool *nulls = NULL;
int values_length = 6;
Datum values[values_length];
HeapTuple heap_tuple ; /* instance of the tuple to return */
Datum result;
POSTGIS_RT_DEBUG(3, "RASTER_getGeotransform: Starting");
/* get argument */
if (PG_ARGISNULL(0)) PG_RETURN_NULL();
rast = (rt_pgraster *)PG_DETOAST_DATUM_SLICE(PG_GETARG_DATUM(0),
0, sizeof(struct rt_raster_serialized_t));
if (PG_ARGISNULL(0))
PG_RETURN_NULL();
pgraster = (rt_pgraster *)PG_DETOAST_DATUM_SLICE(PG_GETARG_DATUM(0), 0, sizeof(struct rt_raster_serialized_t));
raster = rt_raster_deserialize(rast, TRUE);
/* raster */
raster = rt_raster_deserialize(pgraster, TRUE);
if (!raster) {
elog(ERROR, "RASTER_detGeotransform: Could not deserialize raster");
elog(ERROR, "RASTER_getGeotransform: Could not deserialize raster");
PG_RETURN_NULL();
}
@ -1646,21 +1648,41 @@ Datum RASTER_getGeotransform(PG_FUNCTION_ARGS)
rt_raster_destroy(raster);
/* setup the return value infrastructure */
if (get_call_result_type(fcinfo, NULL, &result_tuple) != TYPEFUNC_COMPOSITE) {
ereport(ERROR, (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("RASTER_getGeotransform(): function returning record called in context that cannot accept type record"
)
));
PG_RETURN_NULL();
}
BlessTupleDesc(result_tuple);
/* get argument */
/* prep the composite return value */
/* construct datum array */
return_values[0] = Float8GetDatum(imag) ;
return_values[1] = Float8GetDatum(jmag) ;
return_values[2] = Float8GetDatum(theta_i) ;
return_values[3] = Float8GetDatum(theta_ij) ;
return_values[4] = Float8GetDatum(rt_raster_get_x_offset(raster)) ;
return_values[5] = Float8GetDatum(rt_raster_get_y_offset(raster)) ;
memset(nulls, FALSE, 6);
values[0] = Float8GetDatum(imag);
values[1] = Float8GetDatum(jmag);
values[2] = Float8GetDatum(theta_i);
values[3] = Float8GetDatum(theta_ij);
values[4] = Float8GetDatum(rt_raster_get_x_offset(raster));
values[5] = Float8GetDatum(rt_raster_get_y_offset(raster));
nulls = palloc(sizeof(bool) * values_length);
memset(nulls, FALSE, values_length);
/* stick em on the heap */
heap_tuple = heap_form_tuple(result_tuple, return_values, nulls) ;
heap_tuple = heap_form_tuple(result_tuple, values, nulls);
/* return */
PG_RETURN_DATUM(HeapTupleGetDatum(heap_tuple)) ;
/* make the tuple into a datum */
result = HeapTupleGetDatum(heap_tuple);
/* clean up */
pfree(nulls);
PG_RETURN_DATUM(result);
}

View file

@ -150,16 +150,13 @@ CREATE OR REPLACE FUNCTION st_pixelheight(raster)
AS 'MODULE_PATHNAME', 'RASTER_getPixelHeight'
LANGUAGE 'C' IMMUTABLE STRICT;
CREATE TYPE geotransform AS (
imag double precision,
jmag double precision,
theta_i double precision,
theta_ij double precision,
xoffset double precision,
yoffset double precision);
CREATE OR REPLACE FUNCTION st_geotransform(raster)
RETURNS geotransform
CREATE OR REPLACE FUNCTION st_geotransform(raster,
OUT imag double precision,
OUT jmag double precision,
OUT theta_i double precision,
OUT theta_ij double precision,
OUT xoffset double precision,
OUT yoffset double precision)
AS 'MODULE_PATHNAME', 'RASTER_getGeotransform'
LANGUAGE 'C' IMMUTABLE;
@ -2309,13 +2306,6 @@ CREATE OR REPLACE FUNCTION st_setgeotransform(rast raster,
AS 'MODULE_PATHNAME','RASTER_setGeotransform'
LANGUAGE 'C' IMMUTABLE;
CREATE OR REPLACE FUNCTION st_setgeotransform(rast raster, gt geotransform)
RETURNS raster
AS $$ SELECT st_setgeotransform($1, ($2).imag, ($2).jmag,
($2).theta_i, ($2).theta_ij,
($2).xoffset, ($2).yoffset) $$
LANGUAGE 'sql' VOLATILE;
-----------------------------------------------------------------------
-- Raster Editors ST_SetGeoreference()
-----------------------------------------------------------------------

View file

@ -12,7 +12,7 @@
-- st_skewx
-----------------------------------------------------------------------
SELECT id, name, skewx
SELECT 'T1', id, name, skewx
FROM rt_properties_test
WHERE st_skewx(rast) != skewx;
@ -20,7 +20,7 @@ SELECT id, name, skewx
-- st_skewy
-----------------------------------------------------------------------
SELECT id, name, skewy
SELECT 'T2', id, name, skewy
FROM rt_properties_test
WHERE st_skewy(rast) != skewy;
@ -28,7 +28,7 @@ SELECT id, name, skewy
-- st_setrotation
-----------------------------------------------------------------------
SELECT id, name, st_rotation(rast) as rotation
SELECT 'T3', id, name, round(st_rotation(rast)*1000000000000) as rotation
FROM rt_properties_test
WHERE st_rotation(rast) != 0;
@ -39,15 +39,15 @@ INSERT INTO rt_properties_test
WHERE st_rotation(rast) != 0);
UPDATE rt_properties_test
SET scalex = st_scalex(rast),
scaley = st_scaley(rast),
skewx = st_skewx(rast),
skewy = st_skewy(rast),
ipx = st_upperleftx(rast),
ipy = st_upperlefty(rast)
SET scalex = round(st_scalex(rast)*1000000000000),
scaley = round(st_scaley(rast)*1000000000000),
skewx = round(st_skewx(rast)*1000000000000),
skewy = round(st_skewy(rast)*1000000000000),
ipx = round(st_upperleftx(rast)*1000000000000),
ipy = round(st_upperlefty(rast)*1000000000000)
WHERE id > 100;
SELECT id, scalex, scaley, skewx, skewy, st_rotation(rast)
SELECT 'T4', id, scalex, scaley, skewx, skewy, st_rotation(rast)
FROM rt_properties_test
WHERE id > 100;
@ -56,15 +56,16 @@ UPDATE rt_properties_test
WHERE id > 100;
UPDATE rt_properties_test
SET scalex = st_scalex(rast),
scaley = st_scaley(rast),
skewx = st_skewx(rast),
skewy = st_skewy(rast),
ipx = st_upperleftx(rast),
ipy = st_upperlefty(rast)
SET scalex = round(st_scalex(rast)*1000000000000),
scaley = round(st_scaley(rast)*1000000000000),
skewx = round(st_skewx(rast)*1000000000000),
skewy = round(st_skewy(rast)*1000000000000),
ipx = round(st_upperleftx(rast)*1000000000000),
ipy = round(st_upperlefty(rast)*1000000000000)
WHERE id > 100;
SELECT id, scalex, scaley, skewx, skewy, st_rotation(rast)
SELECT 'T5', id, scalex, scaley, skewx, skewy,
round(st_rotation(rast)*1000000000000)
FROM rt_properties_test
WHERE id > 100;
@ -73,15 +74,16 @@ UPDATE rt_properties_test
WHERE id > 100;
UPDATE rt_properties_test
SET scalex = st_scalex(rast),
scaley = st_scaley(rast),
skewx = st_skewx(rast),
skewy = st_skewy(rast),
ipx = st_upperleftx(rast),
ipy = st_upperlefty(rast)
SET scalex = round(st_scalex(rast)*1000000000000),
scaley = round(st_scaley(rast)*1000000000000),
skewx = round(st_skewx(rast)*1000000000000),
skewy = round(st_skewy(rast)*1000000000000),
ipx = round(st_upperleftx(rast)*1000000000000),
ipy = round(st_upperlefty(rast)*1000000000000)
WHERE id > 100;
SELECT id, scalex, scaley, skewx, skewy, st_rotation(rast)
SELECT 'T6', id, scalex, scaley, skewx, skewy,
round(st_rotation(rast)*1000000000000)
FROM rt_properties_test
WHERE id > 100;

View file

@ -1,8 +1,8 @@
4|1x1, ip:7.5,2.5 scale:5,5 skew:1,1, srid:-1, width:1, height:1|-0.19739555984988
5|1x1, ip:7.5,2.5 scale:5,5 skew:3,7, srid:-1, width:1, height:1|-0.950546840812075
104|5.09901951359278|4.70678724331642|1.96116135138184|-0|0
105|8.60232526704263|0.464990554975281|5.81238193719096|-0|0
104|3.60555127546399|1.9414506867883|4.71495166791445|-3.60555127546399|0.785398163397448
105|6.08276253029822|-3.78117670802321|4.43877265724465|-6.08276253029822|0.785398163397448
104|4.41588043316392|3.09561664722963|4.0518091728751|-2.54950975679639|0.523598775598298
105|7.44983221287567|-2.50349733546706|5.26616569159282|-4.30116263352131|0.523598775598299
T3|4|1x1, ip:7.5,2.5 scale:5,5 skew:1,1, srid:-1, width:1, height:1|-197395559850
T3|5|1x1, ip:7.5,2.5 scale:5,5 skew:3,7, srid:-1, width:1, height:1|-950546840812
T4|104|5099019513593|4706787243316|1961161351382|-0|0
T4|105|8602325267043|464990554975|5812381937191|-0|0
T5|104|3605551275464|1941450686788|4714951667914|-3605551275464|785398163397
T5|105|6082762530298|-3781176708023|4438772657245|-6082762530298|785398163397
T6|104|4415880433164|3095616647230|4051809172875|-2549509756796|523598775598
T6|105|7449832212876|-2503497335467|5266165691593|-4301162633521|523598775598