Opened 14 years ago

Closed 23 months ago

#381 closed enhancement (duplicate)

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 (6)

comment:1 by kneufeld, 14 years ago

Owner: changed from pramsey to kneufeld

comment:2 by strk, 12 years ago

Milestone: PostGIS 2.0.0PostGIS 2.1.0

enhancements pushed to 2.1

comment:3 by Mike Taves, 12 years ago

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 by robe, 11 years ago

Milestone: PostGIS 2.1.0PostGIS Future

comment:5 by robe, 7 years ago

Milestone: PostGIS FuturePostGIS Fund Me

Milestone renamed

comment:6 by robe, 23 months ago

Resolution: duplicate
Status: newclosed

This was already done in - PostGIS 2.5.0

Note: See TracTickets for help on using tickets.