Messages from list : cormas@cirad.fr

Choose a topic among the following archives :

"Real distance" between two cells.

New Message Reply Date view Thread view Subject view Author view

Subject: "Real distance" between two cells.
From: Jourdain, Damien (D.JOURDAIN@CGIAR.ORG)
Date: jeu nov 22 2001 - 15:43:25 CET

Dear all,

Correct me if I am wrong! There is no way to calculate a "real" distance
between two cells if we assume a certain scale for the environment. For
example, if we consider a plot of 1ha, we can reasonably think that the
distance between two adjacent point centers is 100 m.

If I use the function distCenter: I have a distance between the two cell
centers, but I think the result is dependant on the way the grid is
displayed (I do not get the same result with a grid taking half the screen
versus a grid taking all the screen).

If I use the function distCell: I have an integer result corresponding to
the number of cells , that just gives me an approximation of the real
distance once those two cells are not on the same line or on the same column
in the grid.

So I tried to develop my own routines:
Starting from the simple idea of the Pythagore theorem, I first calculte the
horizontal distance and the vertical distance between two cells. I put
these routines as MyModel_Cell procedures.

leModuloDeX
        " give the horizontal position whatever the row you are on"
        " we suppose the space is open and grid horizontal size is 20"
        | x |
        x := (self id \\ 20 = 0) ifTrue: [20] ifFalse: [self id \\ 20].
        ^x.

distanceHorizontale: uneCellule
        "give the distance in number of cells "
        | x y |
        x := self leModuloDeX.
        y := uneCellule leModuloDeX.
        ^( x - y ) .

distanceVerticale: uneCellule
        " we suppose the space is open and grid vertical size is 20"

        | idVertical x |
        x:= self distanceHorizontale: uneCellule.
        idVertical := (uneCellule id) + x.

        ^(idVertical - (self id))/20.

distance: uneCellule
| x y |
x := (self distanceHorizontale: uneCellule) * 100. "on suppose que les
parcelles font un ha"
y := (self distanceVerticale: uneCellule) * 100.
x := x * x.
y := y * y.
^(x + y) sqrt "reponse en m"

First, I have this awfull feeling that I did reinvent the wheel but in a
degraded version ... so if you have something simpler that I missed ....
please let me know and do not read the rest!

Second, if there is nothing simpler, there is a certain number of things I
could extract from the grid (20 is the size of the grid, 100 is the scale)
... Where are these variables so I could make these commands more portable,
when my environment is changing?

Third, maybe these procedures should be placed at a superior level (e.g.
Spatial Entity?) But where?

Cheers.

Damien
Damien Jourdain
CIMMYT-CIRAD / Economics Program
Apdo Postal 6-641
06600 Mexico D.F.
Mexico
Tel.: + 52 (55) 58 04 20 04 poste 22 38
Fax: + 52 (55) 58 04 75 58
e-mail: d.jourdain@cgiar.org

New Message Reply Date view Thread view Subject view Author view
 

Back to home