[postgis-users] Problem with st_translate

Maxime van Noppen maxime at altribe.org
Wed Oct 21 10:16:54 PDT 2009


Bob Pawley wrote:
> Hi
>  
> I have a table holding a number of rows of points which I want to
> translate from covering Box 1 to covering Box 2.
>  
> When I use the following all of the points are translated to the same
> central position (200 points stacked upon each other)
>  
>  insert into fluids (one)
>  select st_translate(graphics.point_grid.the_geom,
>  st_x(st_centroid(library.dgm_process.the_geom)) -
>  st_x(st_centroid(graphics.point_grid.the_geom)),
>  st_y(st_centroid(library.dgm_process.the_geom)) -
>  st_y(st_centroid(graphics.point_grid.the_geom)))
>  from  library.dgm_process, graphics.point_grid
>  where library.dgm_process.process_number = '1'
>  and graphics.point_grid.number = '1' ;
> I've tried variations of the above without success.
> 
> When the same points are collected in a st_union operation occupying a
> single row the preceding works well.

Hi,

>From what I understand the behaviour is normal. You ask to translate all
the points to the st_centroid of the destination geometry. The
ST_Translate arguments that you provide are those of the vector between
the points and the centroid of the destination geometry, which therefore
translates all the points to this place.

To achieve what you want you'll have to compute the vector from the
centroid of the first geometry to the second, and apply this to your
points. The arguments to the st_translate you should be using are :

vec_x = st_x(st_centroid(geom_2)) - st_x(st_centroid(geom_1))
vec_y = st_y(st_centroid(geom_2)) - st_y(st_centroid(geom_1))

This also explains why it worked with all the points packed into a
single geometry.

-- 
Maxime



More information about the postgis-users mailing list