[postgis-users] How to use ST_Affine

Dylan Beaudette dylan.beaudette at gmail.com
Wed Jan 16 13:52:06 PST 2008


On Wednesday 16 January 2008 09:09:01 am Frank Durstewitz wrote:
> Hi,
>
> i wonder how i would use ST_Affine. I found a small note how to use
> (with R), but that's over my mind.
>
> I want to shift the coordinates of some points. On a map i show the
> points, then i select at least 3 of them to move them manually to the
> correct coordinates and use the new coordinates as reference for the
> shift. So i have 3 "old" coordinates and 3 "new" cordinates. But i don't
> know what goes where...
>
> Can someone please explain what to do?
>
> Regards, Frank
>

Hi Frank,

Was it this page (http://casoilresource.lawr.ucdavis.edu/drupal/node/433) 
which caused the confusion?

I was recently confronted with the same problem: I knew the locations 
of 'good' and 'bad' coordinates (control points) but did not know how to 
compute the transformation matrix, which ST_Affine() wants.

There are two approaches:

1. use R to 'fit' the transformation 
2. use GRASS and v.transform to 'fit' the transformation

Both approaches can be used to compute and print the transformation matrix 
based on a set of control points.

If you use R, the trick is interpreting the format of the transformation 
matrix:

use the coef() function and transpose the results:

t(coef(l))

... and the format will be :
 
 xoff a b 
 yoff d e 


put the resulting numbers into the order that postgis wants:
ST_Affine(geom, a, b, d, e, xoff, yoff)


If you use GRASS and v.transform, be sure to include the '-m' flag, and the 
transformation matrix will be printed, along with a note on the format.


As the linked page suggests this approach works well when there is a 
systematic shift in coordinates which can be modeled by an affine transform.

Cheers,

Dylan



More information about the postgis-users mailing list