[GRASS5] i.ortho.photo DEM reading problem

We have found a problem in i.ortho.photo. Under certain
conditions it doesn't seem to read the DEM properly.
With a FCELL DEM, all pixels with values, we get
in photo.rectify:

src/imagery/i.ortho.photo/photo.rectify/rectify.c
(DEBUG3 activated, a few more messages added)

The problem is 'z2' (elevation for the current region)
which is not read properly:

Looking for elevation file in group: calicox
Block elevation: calico_dem2_10 in gans
Starting exec_rectify...
Looking for elevation file in group: calicox
Block elevation: calico_dem2_10 in gans
Starting exec_rectify...
I look for files to ortho rectify
ORTHO RECTIFYING:
NAME calicox
MAPSET gans
RESULT prova3
select_current_env...
reading was fine...
Starting the rectification...
Open temp elevation file:
In ortho meanz = 1981.491860
In ortho meanz = 4105.594400
In ortho meanz = 6044.492130
In ortho meanz = 8499.625060
In ortho meanz = 11986.389780
In ortho meanz = 14705.948310
In ortho meanz = 17462.712000
In ortho meanz = 20178.161920
In ortho meanz = 22569.874530
In ortho meanz = 25390.171480
In ortho meanz = 28556.122850
In ortho meanz = 31404.389700
In ortho meanz = 34332.579390
In ortho meanz = 37071.233800
In ortho meanz = 39519.127710
In ortho meanz = 42506.338760
In ortho meanz = 45473.638940
In ortho meanz = 47459.940670
In ortho meanz = 49599.415350
In ortho meanz = 52443.623050
In ortho meanz = 54617.288820
In ortho aver_z = 2600.823277
elev layer = calico_dem2_10 mapset elev = gans elevfd = 5
Number Tie_Points: y_ties 4 x_ties 3
Tie_Point row 0 col 0
   east 515815.780000 north 3865611.070000
     row2 = 1.369863 col2 = 1.282051
     e2 = 515815.780000 n2 = 3865611.070000 z2 = 1993021027927436296192.000000
     XC = 514766.737986 YC = 3866269.858695 ZC = 6949.693774
     omega = 0.100463 phi = -0.000917 kappa = 0.010939
    After ortho ref (photo cords): ex = -0.308563 nx = -15.397396
    After geo ref: ex = 4558.802339 nx = 4035.160015
Tie_Point row 0 col 1
   east 515915.620000 north 3865611.070000
     row2 = 1.369863 col2 = 129.282051
     e2 = 515915.620000 n2 = 3865611.070000 z2 = 2600.823277
     XC = 514766.737986 YC = 3866269.858695 ZC = 6949.693774
     omega = 0.100463 phi = -0.000917 kappa = 0.010939
    After ortho ref (photo cords): ex = 40.612004 nx = -39.577139
    After geo ref: ex = 6166.688446 nx = 3079.855145
Tie_Point row 0 col 2
   east 515952.620000 north 3865611.070000
     row2 = 1.369863 col2 = 176.717949
     e2 = 515952.620000 n2 = 3865611.070000 z2 = 95917520192290147783385833979221332562976575379988380225229060000308889360004605604578786802040922330470743956690410476049963279975522776677706661993737019538977683164047063273113230284820270563648225822899223761746994861110302432192091832986624596337458801955455408611274111793977775568287956992.000000
     XC = 514766.737986 YC = 3866269.858695 ZC = 6949.693774
     omega = 0.100463 phi = -0.000917 kappa = 0.010939
    After ortho ref (photo cords): ex = -0.308563 nx = -15.397396
    After geo ref: ex = 4558.802339 nx = 4035.160015
Tie_Point row 1 col 0
   east 515815.780000 north 3865517.630000
     row2 = 129.369863 col2 = 1.282051
     e2 = 515815.780000 n2 = 3865517.630000 z2 = 1364078703119920529408.000000
     XC = 514766.737986 YC = 3866269.858695 ZC = 6949.693774
     omega = 0.100463 phi = -0.000917 kappa = 0.010939
    After ortho ref (photo cords): ex = -0.308563 nx = -15.397396
    After geo ref: ex = 4558.802339 nx = 4035.160015
Tie_Point row 1 col 1
   east 515915.620000 north 3865517.630000
     row2 = 129.369863 col2 = 129.282051
     e2 = 515915.620000 n2 = 3865517.630000 z2 = 2600.823277
     XC = 514766.737986 YC = 3866269.858695 ZC = 6949.693774
     omega = 0.100463 phi = -0.000917 kappa = 0.010939
    After ortho ref (photo cords): ex = 40.665277 nx = -43.004048
    After geo ref: ex = 6168.587430 nx = 2944.950114
Tie_Point row 1 col 2
   east 515952.620000 north 3865517.630000
     row2 = 129.369863 col2 = 176.717949
     e2 = 515952.620000 n2 = 3865517.630000 z2 = 0.000000
     XC = 514766.737986 YC = 3866269.858695 ZC = 6949.693774
     omega = 0.100463 phi = -0.000917 kappa = 0.010939
    After ortho ref (photo cords): ex = 25.990831 nx = -32.569173
    After geo ref: ex = 5592.087381 nx = 3356.963178
Tie_Point row 2 col 0
   east 515815.780000 north 3865424.190000
     row2 = 257.369863 col2 = 1.282051
     e2 = 515815.780000 n2 = 3865424.190000 z2 = 1608115256185064783872.000000
     XC = 514766.737986 YC = 3866269.858695 ZC = 6949.693774
     omega = 0.100463 phi = -0.000917 kappa = 0.010939
    After ortho ref (photo cords): ex = -0.308563 nx = -15.397396
    After geo ref: ex = 4558.802339 nx = 4035.160015
Tie_Point row 2 col 1
   east 515915.620000 north 3865424.190000
     row2 = 257.369863 col2 = 129.282051
     e2 = 515915.620000 n2 = 3865424.190000 z2 = 2600.823277
     XC = 514766.737986 YC = 3866269.858695 ZC = 6949.693774
     omega = 0.100463 phi = -0.000917 kappa = 0.010939
    After ortho ref (photo cords): ex = 40.718785 nx = -46.446094
    After geo ref: ex = 6170.494801 nx = 2809.449179
Tie_Point row 2 col 2
   east 515952.620000 north 3865424.190000
     row2 = 257.369863 col2 = 176.717949
     e2 = 515952.620000 n2 = 3865424.190000 z2 = -50661935924014.710938
     XC = 514766.737986 YC = 3866269.858695 ZC = 6949.693774
     omega = 0.100463 phi = -0.000917 kappa = 0.010939
    After ortho ref (photo cords): ex = -0.308563 nx = -15.397396
    After geo ref: ex = 4558.802340 nx = 4035.160015
Tie_Point row 3 col 0
   east 515815.780000 north 3865362.680000
     row2 = 341.630137 col2 = 1.282051
     e2 = 515815.780000 n2 = 3865362.680000 z2 = 1712506443772004663296.000000
     XC = 514766.737986 YC = 3866269.858695 ZC = 6949.693774
     omega = 0.100463 phi = -0.000917 kappa = 0.010939
    After ortho ref (photo cords): ex = -0.308563 nx = -15.397396
    After geo ref: ex = 4558.802339 nx = 4035.160015
Tie_Point row 3 col 1
   east 515915.620000 north 3865362.680000
     row2 = 341.630137 col2 = 129.282051
     e2 = 515915.620000 n2 = 3865362.680000 z2 = 2600.823277
     XC = 514766.737986 YC = 3866269.858695 ZC = 6949.693774
     omega = 0.100463 phi = -0.000917 kappa = 0.010939
    After ortho ref (photo cords): ex = 40.754138 nx = -48.720246
    After geo ref: ex = 6171.754998 nx = 2719.924000
Tie_Point row 3 col 2
   east 515952.620000 north 3865362.680000
     row2 = 341.630137 col2 = 176.717949
     e2 = 515952.620000 n2 = 3865362.680000 z2 = 0.000000
     XC = 514766.737986 YC = 3866269.858695 ZC = 6949.693774
     omega = 0.100463 phi = -0.000917 kappa = 0.010939
    After ortho ref (photo cords): ex = 26.012583 nx = -36.094199
    After geo ref: ex = 5592.741155 nx = 3218.198448
Patching column 178:
Patching 343 row:
[...]
Done. Writing results...

Somehow line 91
        if ( (G_get_raster_row (elevfd, elevbuf, r2, data_type)) < 0)
fails.

Any ideas (maybe just from looking into the rectify.c)?

Thanks in advance

Markus

Hello Markus

On Tue, 25 Nov 2003, Markus Neteler wrote:

We have found a problem in i.ortho.photo. Under certain
conditions it doesn't seem to read the DEM properly.
With a FCELL DEM, all pixels with values, we get
in photo.rectify:

[...]

Somehow line 91
        if ( (G_get_raster_row (elevfd, elevbuf, r2, data_type)) < 0)
fails.

Can you not force it to always read the map as a DCELL_TYPE (especially
seeing elevbuf is a pointer to a DCELL)? From reading previous messages
on the list I think this is a good practice unless you need to preserve
integer values as it will automatically convert the values to DCELL if the
map is CELL or FCELL?.

Also further down
zz2 = (double) elevbuf[c2];
/* if target TIE point has no elevation, set to aver_z */
if (zz2 == 0) zz2 = aver_z;
z2 = zz2;
looks very suspicious and should probably be using something like
G_is_d_null_value() instead of if (zz2 == 0).

Any ideas (maybe just from looking into the rectify.c)?

Yes that's all they are---I haven't really done any raster programming so
just provided some ideas that might help you to find something.

Paul

Hello Paul,

sorry for not writing earlier - we have implemented your suggestion
and it seems to work well (the first solution from below).
I have submitted to CVS already.

Thanks for the quick help,

Markus

On Wed, Nov 26, 2003 at 10:11:51AM +0000, Paul Kelly wrote:

Hello Markus

On Tue, 25 Nov 2003, Paul Kelly wrote:

> Can you not force it to always read the map as a DCELL_TYPE (especially
> seeing elevbuf is a pointer to a DCELL)? From reading previous messages
> on the list I think this is a good practice unless you need to preserve
> integer values as it will automatically convert the values to DCELL if the
> map is CELL or FCELL?.
>
> Also further down
> zz2 = (double) elevbuf[c2];
> /* if target TIE point has no elevation, set to aver_z */
> if (zz2 == 0) zz2 = aver_z;
> z2 = zz2;
> looks very suspicious and should probably be using something like
> G_is_d_null_value() instead of if (zz2 == 0).

Did your change work? My CVS write access isn't working right now
(firewall problem here I think) and I can't test it anyway but if you
still have problems with that part I would suggest changing

zz2 = (DCELL) elevbuf[c2];
/* if target TIE point has no elevation, set to aver_z */
if ( G_is_d_null_value(&zz2) ) zz2 = aver_z;
z2 = zz2;

to the following

/* if target TIE point has no elevation, set to aver_z */
if ( G_is_d_null_value( &elevbuf[c2] ) )
    z2 = aver_z;
else
    z2 = (double) elevbuf[c2];

and getting rid of zz2. The pointer use looks better to me but don't try
it unless you're having trouble!

Paul

--
Markus Neteler <neteler@itc.it> http://mpa.itc.it
ITC-irst - Centro per la Ricerca Scientifica e Tecnologica
MPBA - Predictive Models for Biol. & Environ. Data Analysis
Via Sommarive, 18 - 38050 Povo (Trento), Italy