Opened 11 years ago

Last modified 3 years ago

#381 new enhancement

Add an optional parameter to ST_Scale to specify the anchor point

Reported by: kneufeld Owned by: kneufeld
Priority: low Milestone: PostGIS Fund Me
Component: postgis Version: master
Keywords: Cc:

Description

ST_Scale is a simple wrapper around ST_Affine, but it's missing a very common "scale about the midpoint or lower left" option.

IE. simply scaling about the midpoint of a geometry is currently a complicated two step approach:

SELECT 
  ST_AsText(
    ST_Translate(
      ST_Scale(geom, 3, 2),
      -3 * (ST_Xmin(geom)+ST_XMax(geom))/2 + ((ST_Xmin(geom)+ST_XMax(geom))/2),
      -2 * (ST_Ymin(geom)+ST_YMax(geom))/2 + ((ST_Ymin(geom)+ST_YMax(geom))/2)
    )
  )
  
FROM 
  (SELECT 'POLYGON (( 2 5, 2 6, 3 6, 3 5, 2 5 ))'::geometry AS geom) a;   
                st_astext                 
------------------------------------------
 POLYGON((1 4.5,1 6.5,4 6.5,4 4.5,1 4.5))
(1 row)

I recommend a new optional char(2) parameter be added to ST_Scale that will permit a user to scale based on various common anchor points:

'SW' | 'BL' - south west (bottom left) corner
'NE' | 'TR' - north east (top right) corner
...
'MP' | 'C' - midpoint (centre) of the geometry

All the complicated xmin/ymin translation stuff could then be automatically computed and placed in xoffset/yoffset parameters of ST_Affine.

Change History (5)

comment:1 Changed 11 years ago by kneufeld

Owner: changed from pramsey to kneufeld

comment:2 Changed 9 years ago by strk

Milestone: PostGIS 2.0.0PostGIS 2.1.0

enhancements pushed to 2.1

comment:3 Changed 9 years ago by Mike Taves

For CAD systems, you need to specify a point of origin, not just midpoint or corner. A similar enhancement for ST_Rotate (#1251) could also be adapted for ST_Scale to provide:

ST_Scale (geometry geomA, float XFactor, float YFactor, [float ZFactor,] geometry pointOrigin);

then a user could do, for example:

-- Scale down feet to metres from the top left corner
SELECT ST_Scale(geom, 0.3048, 0.3048, ST_MakePoint(ST_XMin(geom), ST_YMax(geom)));

-- Scale up by 2x from centre
SELECT ST_Scale(geom, 2.0, 2.0, ST_Centroid(geom));

comment:4 Changed 8 years ago by robe

Milestone: PostGIS 2.1.0PostGIS Future

comment:5 Changed 3 years ago by robe

Milestone: PostGIS FuturePostGIS Fund Me

Milestone renamed

Note: See TracTickets for help on using tickets.