全部产品

空间对象编辑函数

更新时间:2019-07-08 18:09:58

ST_AddPoint

描述

将一个坐标点添加到LineString之中。

函数声明

  1. geometry ST_AddPoint(geometry linestring, geometry point);

使用示例

  1. --guarantee all linestrings in a table are closed
  2. --by adding the start point of each linestring to the end of the line string
  3. --only for those that are not closed
  4. UPDATE sometable
  5. SET the_geom = ST_AddPoint(the_geom, ST_StartPoint(the_geom))
  6. FROM sometable
  7. WHERE ST_IsClosed(the_geom) = false;
  8. --Adding point to a 3-d line
  9. SELECT ST_AsEWKT(ST_AddPoint(ST_GeomFromEWKT('LINESTRING(0 0 1, 1 1 1)'), ST_MakePoint(1, 2, 3)));
  10. --result
  11. st_asewkt
  12. ----------
  13. LINESTRING(0 0 1,1 1 1,1 2 3)

ST_Affine

描述

对一个2D或3D几何对象应用给定的仿射变换。

函数声明

  1. geometry ST_Affine(geometry geomA, float a, float b, float c, float d, float e, float f, float g, float h, float i, float xoff, float yoff, float zoff);
  2. geometry ST_Affine(geometry geomA, float a, float b, float d, float e, float xoff, float yoff);

使用示例

  1. --Rotate a 3d line 180 degrees about the z axis. Note this is long-hand for doing ST_Rotate();
  2. SELECT ST_AsEWKT(ST_Affine(the_geom, cos(pi()), -sin(pi()), 0, sin(pi()), cos(pi()), 0, 0, 0, 1, 0, 0, 0)) As using_affine,
  3. ST_AsEWKT(ST_Rotate(the_geom, pi())) As using_rotate
  4. FROM (SELECT ST_GeomFromEWKT('LINESTRING(1 2 3, 1 4 3)') As the_geom) As foo;
  5. using_affine | using_rotate
  6. -----------------------------+-----------------------------
  7. LINESTRING(-1 -2 3,-1 -4 3) | LINESTRING(-1 -2 3,-1 -4 3)
  8. (1 row)
  9. --Rotate a 3d line 180 degrees in both the x and z axis
  10. SELECT ST_AsEWKT(ST_Affine(the_geom, cos(pi()), -sin(pi()), 0, sin(pi()), cos(pi()), -sin(pi()), 0, sin(pi()), cos(pi()), 0, 0, 0))
  11. FROM (SELECT ST_GeomFromEWKT('LINESTRING(1 2 3, 1 4 3)') As the_geom) As foo;
  12. st_asewkt
  13. -------------------------------
  14. LINESTRING(-1 -2 -3,-1 -4 -3)
  15. (1 row)

ST_Force2D

描述

强制转换输入几何对象到2D模式。

函数声明

  1. geometry ST_Force2D(geometry geomA);

使用示例

  1. SELECT ST_AsEWKT(ST_Force2D(ST_GeomFromEWKT('CIRCULARSTRING(1 1 2, 2 3 2, 4 5 2, 6 7 2, 5 6 2)')));
  2. st_asewkt
  3. -------------------------------------
  4. CIRCULARSTRING(1 1,2 3,4 5,6 7,5 6)
  5. SELECT ST_AsEWKT(ST_Force2D('POLYGON((0 0 2,0 5 2,5 0 2,0 0 2),(1 1 2,3 1 2,1 3 2,1 1 2))'));
  6. st_asewkt
  7. ----------------------------------------------
  8. POLYGON((0 0,0 5,5 0,0 0),(1 1,3 1,1 3,1 1))

ST_Force3D

描述

强制转换几何对象到3D(XYZ)模式。这是ST_Force3DZ的别名。

函数声明

  1. geometry ST_Force3D(geometry geomA);

使用示例

  1. --Nothing happens to an already 3D geometry
  2. SELECT ST_AsEWKT(ST_Force3D(ST_GeomFromEWKT('CIRCULARSTRING(1 1 2, 2 3 2, 4 5 2, 6 7 2, 5 6 2)')));
  3. st_asewkt
  4. -----------------------------------------------
  5. CIRCULARSTRING(1 1 2,2 3 2,4 5 2,6 7 2,5 6 2)
  6. SELECT ST_AsEWKT(ST_Force3D('POLYGON((0 0,0 5,5 0,0 0),(1 1,3 1,1 3,1 1))'));
  7. st_asewkt
  8. --------------------------------------------------------------
  9. POLYGON((0 0 0,0 5 0,5 0 0,0 0 0),(1 1 0,3 1 0,1 3 0,1 1 0))

ST_Force3DZ

描述

强制转换输入几何对象到3D(XYZ)模式。

函数声明

  1. geometry ST_Force3DZ(geometry geomA);

使用示例

  1. --Nothing happens to an already 3D geometry
  2. SELECT ST_AsEWKT(ST_Force3DZ(ST_GeomFromEWKT('CIRCULARSTRING(1 1 2, 2 3 2, 4 5 2, 6 7 2, 5 6 2)')));
  3. st_asewkt
  4. -----------------------------------------------
  5. CIRCULARSTRING(1 1 2,2 3 2,4 5 2,6 7 2,5 6 2)
  6. SELECT ST_AsEWKT(ST_Force3DZ('POLYGON((0 0,0 5,5 0,0 0),(1 1,3 1,1 3,1 1))'));
  7. st_asewkt
  8. --------------------------------------------------------------
  9. POLYGON((0 0 0,0 5 0,5 0 0,0 0 0),(1 1 0,3 1 0,1 3 0,1 1 0))

ST_Force3DM

描述

强制转换输入几何对象到3D(XYM)模式。

函数声明

  1. geometry ST_Force3DM(geometry geomA);

使用示例

  1. --Nothing happens to an already 3D geometry
  2. SELECT ST_AsEWKT(ST_Force3DM(ST_GeomFromEWKT('CIRCULARSTRING(1 1 2, 2 3 2, 4 5 2, 6 7 2, 5 6 2)')));
  3. st_asewkt
  4. ------------------------------------------------
  5. CIRCULARSTRINGM(1 1 0,2 3 0,4 5 0,6 7 0,5 6 0)
  6. SELECT ST_AsEWKT(ST_Force3DM('POLYGON((0 0 1,0 5 1,5 0 1,0 0 1),(1 1 1,3 1 1,1 3 1,1 1 1))'));
  7. st_asewkt
  8. ---------------------------------------------------------------
  9. POLYGONM((0 0 0,0 5 0,5 0 0,0 0 0),(1 1 0,3 1 0,1 3 0,1 1 0))

ST_Force4D

描述

强制转换输入几何对象到4D(XYZM)模式。

函数声明

  1. geometry ST_Force4D(geometry geomA);

使用示例

  1. --Nothing happens to an already 3D geometry
  2. SELECT ST_AsEWKT(ST_Force4D(ST_GeomFromEWKT('CIRCULARSTRING(1 1 2, 2 3 2, 4 5 2, 6 7 2, 5 6 2)')));
  3. st_asewkt
  4. ---------------------------------------------------------
  5. CIRCULARSTRING(1 1 2 0,2 3 2 0,4 5 2 0,6 7 2 0,5 6 2 0)
  6. SELECT ST_AsEWKT(ST_Force4D('MULTILINESTRINGM((0 0 1,0 5 2,5 0 3,0 0 4),(1 1 1,3 1 1,1 3 1,1 1 1))'));
  7. st_asewkt
  8. --------------------------------------------------------------------------------------
  9. MULTILINESTRING((0 0 0 1,0 5 0 2,5 0 0 3,0 0 0 4),(1 1 0 1,3 1 0 1,1 3 0 1,1 1 0 1))

ST_ForcePolygonCCW

描述

将输入的Polygon参数的外部边界按逆时针安排且将所有内部边界按顺时针方向安排。

函数声明

  1. geometry ST_ForcePolygonCCW(geometry geom);

使用示例

  1. None

ST_ForceCollection

描述

将一个几何对象转换成GEOMETRYCOLLECTION。

函数声明

  1. geometry ST_ForceCollection(geometry geomA);

使用示例

  1. SELECT ST_AsEWKT(ST_ForceCollection('POLYGON((0 0 1,0 5 1,5 0 1,0 0 1),(1 1 1,3 1 1,1 3 1,1 1 1))'));
  2. st_asewkt
  3. ----------------------------------------------------------------------------------
  4. GEOMETRYCOLLECTION(POLYGON((0 0 1,0 5 1,5 0 1,0 0 1),(1 1 1,3 1 1,1 3 1,1 1 1)))
  5. SELECT ST_AsText(ST_ForceCollection('CIRCULARSTRING(220227 150406,2220227 150407,220227 150406)'));
  6. st_astext
  7. --------------------------------------------------------------------------------
  8. GEOMETRYCOLLECTION(CIRCULARSTRING(220227 150406,2220227 150407,220227 150406))
  9. (1 row)

ST_ForcePolygonCW

描述

将输入的Polygon参数的外部边界按顺时针安排且将所有内部边界按逆时针方向安排。

函数声明

  1. geometry ST_ForcePolygonCW(geometry geom);

使用示例

  1. None

ST_ForceSFS

描述

强制转换几何对象到SFS 1.1中的几何对象类型。

函数声明

  1. geometry ST_ForceSFS(geometry geomA);
  2. geometry ST_ForceSFS(geometry geomA, text version);

使用示例

  1. None

ST_ForceRHR

描述

强制给定几何对象Polygon的顶点按右手法则顺序排列。

函数声明

  1. geometry ST_ForceRHR(geometry g);

使用示例

  1. SELECT ST_AsEWKT(
  2. ST_ForceRHR(
  3. 'POLYGON((0 0 2, 5 0 2, 0 5 2, 0 0 2),(1 1 2, 1 3 2, 3 1 2, 1 1 2))'
  4. )
  5. );
  6. st_asewkt
  7. --------------------------------------------------------------
  8. POLYGON((0 0 2,0 5 2,5 0 2,0 0 2),(1 1 2,3 1 2,1 3 2,1 1 2))
  9. (1 row)

ST_ForceCurve

描述

如果可行地话,将一个几何对象转换为对应的曲线版本。

函数声明

  1. geometry ST_ForceCurve(geometry g);

使用示例

  1. SELECT ST_AsText(
  2. ST_ForceCurve(
  3. 'POLYGON((0 0 2, 5 0 2, 0 5 2, 0 0 2),(1 1 2, 1 3 2, 3 1 2, 1 1 2))'::geometry
  4. )
  5. );
  6. st_astext
  7. ----------------------------------------------------------------------
  8. CURVEPOLYGON Z ((0 0 2,5 0 2,0 5 2,0 0 2),(1 1 2,1 3 2,3 1 2,1 1 2))
  9. (1 row)

ST_LineMerge

描述

如果可以,将输入的MultiLineString连接成一个或多个LineString。

函数声明

  1. geometry ST_LineMerge(geometry amultilinestring);

使用示例

  1. SELECT ST_AsText(ST_LineMerge(
  2. ST_GeomFromText('MULTILINESTRING((-29 -27,-30 -29.7,-36 -31,-45 -33),(-45 -33,-46 -32))')
  3. )
  4. );
  5. st_astext
  6. --------------------------------------------------------------------------------------------------
  7. LINESTRING(-29 -27,-30 -29.7,-36 -31,-45 -33,-46 -32)
  8. (1 row)
  9. --If can't be merged - original MULTILINESTRING is returned
  10. SELECT ST_AsText(ST_LineMerge(
  11. ST_GeomFromText('MULTILINESTRING((-29 -27,-30 -29.7,-36 -31,-45 -33),(-45.2 -33.2,-46 -32))')
  12. )
  13. );
  14. st_astext
  15. ----------------
  16. MULTILINESTRING((-45.2 -33.2,-46 -32),(-29 -27,-30 -29.7,-36 -31,-45 -33))
  17. -- example with Z dimension
  18. SELECT ST_AsText(ST_LineMerge(
  19. ST_GeomFromText('MULTILINESTRING((-29 -27 11,-30 -29.7 10,-36 -31 5,-45 -33 6), (-29 -27 12,-30 -29.7 5), (-45 -33 1,-46 -32 11))')
  20. )
  21. );
  22. st_astext
  23. --------------------------------------------------------------------------------------------------
  24. LINESTRING Z (-30 -29.7 5,-29 -27 11,-30 -29.7 10,-36 -31 5,-45 -33 1,-46 -32 11)
  25. (1 row)

ST_CollectionExtract

描述

从一个几何对象集合对象中,找出并返回指定类型的几何对象。

函数声明

  1. geometry ST_CollectionExtract(geometry collection, integer type);

使用示例

  1. -- Constants: 1 == POINT, 2 == LINESTRING, 3 == POLYGON
  2. SELECT ST_AsText(ST_CollectionExtract(ST_GeomFromText('GEOMETRYCOLLECTION(GEOMETRYCOLLECTION(POINT(0 0)))'),1));
  3. st_astext
  4. ---------------
  5. MULTIPOINT(0 0)
  6. (1 row)
  7. SELECT ST_AsText(ST_CollectionExtract(ST_GeomFromText('GEOMETRYCOLLECTION(GEOMETRYCOLLECTION(LINESTRING(0 0, 1 1)),LINESTRING(2 2, 3 3))'),2));
  8. st_astext
  9. ---------------
  10. MULTILINESTRING((0 0, 1 1), (2 2, 3 3))
  11. (1 row)

ST_CollectionHomogenize

描述

对于给定的几何对象集合,返回一个对它所包含对象的“最简单”的表示方式。

函数声明

  1. geometry ST_CollectionHomogenize(geometry collection);

使用示例

  1. SELECT ST_AsText(ST_CollectionHomogenize('GEOMETRYCOLLECTION(POINT(0 0))'));
  2. st_astext
  3. ------------
  4. POINT(0 0)
  5. (1 row)
  6. SELECT ST_AsText(ST_CollectionHomogenize('GEOMETRYCOLLECTION(POINT(0 0),POINT(1 1))'));
  7. st_astext
  8. ---------------------
  9. MULTIPOINT(0 0,1 1)
  10. (1 row)

ST_Multi

描述

将给定的几何对象转换为对应的Multi*版本。

函数声明

  1. geometry ST_Multi(geometry g1);

使用示例

  1. SELECT ST_AsText(ST_Multi(ST_GeomFromText('POLYGON((743238 2967416,743238 2967450,743265 2967450,743265.625 2967416,743238 2967416))')));
  2. st_astext
  3. --------------------------------------------------------------------------------------------------
  4. MULTIPOLYGON(((743238 2967416,743238 2967450,743265 2967450,743265.625 2967416,743238 2967416)))
  5. (1 row)

ST_Normalize

描述

返回给定输入几何对象的规范形式。

函数声明

  1. geometry ST_Normalize(geometry geom);

使用示例

  1. SELECT ST_AsText(ST_Normalize(ST_GeomFromText(
  2. 'GEOMETRYCOLLECTION(
  3. POINT(2 3),
  4. MULTILINESTRING((0 0, 1 1),(2 2, 3 3)),
  5. POLYGON(
  6. (0 10,0 0,10 0,10 10,0 10),
  7. (4 2,2 2,2 4,4 4,4 2),
  8. (6 8,8 8,8 6,6 6,6 8)
  9. )
  10. )'
  11. )));
  12. st_astext
  13. ----------------------------------------------------------------------------------------------------------------------------------------------------
  14. GEOMETRYCOLLECTION(POLYGON((0 0,0 10,10 10,10 0,0 0),(6 6,8 6,8 8,6 8,6 6),(2 2,4 2,4 4,2 4,2 2)),MULTILINESTRING((2 2,3 3),(0 0,1 1)),POINT(2 3))
  15. (1 row)

ST_QuantizeCoordinates

描述

将几何对象中的点的坐标值保留指定位数的有效数字。

函数声明

  1. geometry ST_QuantizeCoordinates ( geometry g , int prec_x , int prec_y , int prec_z , int prec_m );

使用示例

  1. SELECT ST_AsText(ST_QuantizeCoordinates('POINT (100.123456 0)'::geometry, 4));
  2. st_astext
  3. -------------------------
  4. POINT(100.123455047607 0)

ST_RemovePoint

描述

从一个LineString之中移除指定编号的点。

函数声明

  1. geometry ST_RemovePoint(geometry linestring, integer offset);

使用示例

  1. --guarantee no LINESTRINGS are closed
  2. --by removing the end point. The below assumes the_geom is of type LINESTRING
  3. UPDATE sometable
  4. SET the_geom = ST_RemovePoint(the_geom, ST_NPoints(the_geom) - 1)
  5. FROM sometable
  6. WHERE ST_IsClosed(the_geom) = true;

ST_Reverse

描述

返回输入几何对象的顶点逆序排列之后的几何对象。

函数声明

  1. geometry ST_Reverse(geometry g1);

使用示例

  1. SELECT ST_AsText(the_geom) as line, ST_AsText(ST_Reverse(the_geom)) As reverseline
  2. FROM
  3. (SELECT ST_MakeLine(ST_MakePoint(1,2),
  4. ST_MakePoint(1,10)) As the_geom) as foo;
  5. --result
  6. line | reverseline
  7. ---------------------+----------------------
  8. LINESTRING(1 2,1 10) | LINESTRING(1 10,1 2)

ST_Rotate

描述

将一个几何对象逆时针旋转给定的角度。

函数声明

  1. geometry ST_Rotate(geometry geomA, float rotRadians);
  2. geometry ST_Rotate(geometry geomA, float rotRadians, float x0, float y0);
  3. geometry ST_Rotate(geometry geomA, float rotRadians, geometry pointOrigin);

使用示例

  1. --Rotate 180 degrees
  2. SELECT ST_AsEWKT(ST_Rotate('LINESTRING (50 160, 50 50, 100 50)', pi()));
  3. st_asewkt
  4. ---------------------------------------
  5. LINESTRING(-50 -160,-50 -50,-100 -50)
  6. (1 row)
  7. --Rotate 30 degrees counter-clockwise at x=50, y=160
  8. SELECT ST_AsEWKT(ST_Rotate('LINESTRING (50 160, 50 50, 100 50)', pi()/6, 50, 160));
  9. st_asewkt
  10. ---------------------------------------------------------------------------
  11. LINESTRING(50 160,105 64.7372055837117,148.301270189222 89.7372055837117)
  12. (1 row)
  13. --Rotate 60 degrees clockwise from centroid
  14. SELECT ST_AsEWKT(ST_Rotate(geom, -pi()/3, ST_Centroid(geom)))
  15. FROM (SELECT 'LINESTRING (50 160, 50 50, 100 50)'::geometry AS geom) AS foo;
  16. st_asewkt
  17. --------------------------------------------------------------
  18. LINESTRING(116.4225 130.6721,21.1597 75.6721,46.1597 32.3708)
  19. (1 row)

ST_RotateX

描述

将给定几何对象沿X轴旋转指定角度。

函数声明

  1. geometry ST_RotateX(geometry geomA, float rotRadians);

使用示例

  1. --Rotate a line 90 degrees along x-axis
  2. SELECT ST_AsEWKT(ST_RotateX(ST_GeomFromEWKT('LINESTRING(1 2 3, 1 1 1)'), pi()/2));
  3. st_asewkt
  4. ---------------------------
  5. LINESTRING(1 -3 2,1 -1 1)

ST_RotateY

描述

将给定几何对象沿Y轴旋转指定角度。

函数声明

  1. geometry ST_RotateY(geometry geomA, float rotRadians);

使用示例

  1. --Rotate a line 90 degrees along y-axis
  2. SELECT ST_AsEWKT(ST_RotateY(ST_GeomFromEWKT('LINESTRING(1 2 3, 1 1 1)'), pi()/2));
  3. st_asewkt
  4. ---------------------------
  5. LINESTRING(3 2 -1,1 1 -1)

ST_RotateZ

描述

将给定几何对象沿Y轴旋转指定角度。

函数声明

  1. geometry ST_RotateZ(geometry geomA, float rotRadians);

使用示例

  1. --Rotate a line 90 degrees along z-axis
  2. SELECT ST_AsEWKT(ST_RotateZ(ST_GeomFromEWKT('LINESTRING(1 2 3, 1 1 1)'), pi()/2));
  3. st_asewkt
  4. ---------------------------
  5. LINESTRING(-2 1 3,-1 1 1)
  6. --Rotate a curved circle around z-axis
  7. SELECT ST_AsEWKT(ST_RotateZ(the_geom, pi()/2))
  8. FROM (SELECT ST_LineToCurve(ST_Buffer(ST_GeomFromText('POINT(234 567)'), 3)) As the_geom) As foo;
  9. st_asewkt
  10. ----------------------------------------------------------------------------------------------------------------------------
  11. CURVEPOLYGON(CIRCULARSTRING(-567 237,-564.87867965644 236.12132034356,-564 234,-569.12132034356 231.87867965644,-567 237))

ST_Scale

描述

将给定几何对象按指定的因子进行缩放。

函数声明

  1. geometry ST_Scale(geometry geomA, float XFactor, float YFactor, float ZFactor);
  2. geometry ST_Scale(geometry geomA, float XFactor, float YFactor);
  3. geometry ST_Scale(geometry geom, geometry factor);
  4. geometry ST_Scale(geometry geom, geometry factor, geometry origin);

使用示例

  1. --Version 1: scale X, Y, Z
  2. SELECT ST_AsEWKT(ST_Scale(ST_GeomFromEWKT('LINESTRING(1 2 3, 1 1 1)'), 0.5, 0.75, 0.8));
  3. st_asewkt
  4. --------------------------------------
  5. LINESTRING(0.5 1.5 2.4,0.5 0.75 0.8)
  6. --Version 2: Scale X Y
  7. SELECT ST_AsEWKT(ST_Scale(ST_GeomFromEWKT('LINESTRING(1 2 3, 1 1 1)'), 0.5, 0.75));
  8. st_asewkt
  9. ----------------------------------
  10. LINESTRING(0.5 1.5 3,0.5 0.75 1)
  11. --Version 3: Scale X Y Z M
  12. SELECT ST_AsEWKT(ST_Scale(ST_GeomFromEWKT('LINESTRING(1 2 3 4, 1 1 1 1)'),
  13. ST_MakePoint(0.5, 0.75, 2, -1)));
  14. st_asewkt
  15. ----------------------------------------
  16. LINESTRING(0.5 1.5 6 -4,0.5 0.75 2 -1)
  17. --Version 4: Scale X Y using false origin
  18. SELECT ST_AsText(ST_Scale('LINESTRING(1 1, 2 2)', 'POINT(2 2)', 'POINT(1 1)'::geometry));
  19. st_astext
  20. ---------------------
  21. LINESTRING(1 1,3 3)

ST_Segmentize

描述

将一个几何对象或地理对象重新分段,使得最大段长度不大于给定值。

函数声明

  1. geometry ST_Segmentize(geometry geom, float max_segment_length);
  2. geography ST_Segmentize(geography geog, float max_segment_length);

使用示例

  1. SELECT ST_AsText(ST_Segmentize(
  2. ST_GeomFromText('MULTILINESTRING((-29 -27,-30 -29.7,-36 -31,-45 -33),(-45 -33,-46 -32))')
  3. ,5)
  4. );
  5. st_astext
  6. --------------------------------------------------------------------------------------------------
  7. MULTILINESTRING((-29 -27,-30 -29.7,-34.886615700134 -30.758766735029,-36 -31,-40.8809353009198 -32.0846522890933,-45 -33),(-45 -33,-46 -32))
  8. (1 row)
  9. SELECT ST_AsText(ST_Segmentize(ST_GeomFromText('POLYGON((-29 28, -30 40, -29 28))'),10));
  10. st_astext
  11. -----------------------
  12. POLYGON((-29 28,-29.8304547985374 37.9654575824488,-30 40,-29.1695452014626 30.0345424175512,-29 28))
  13. (1 row)

ST_SetPoint

描述

将LineString中的给定序号的坐标点替换为参数中指定的坐标点。

函数声明

  1. geometry ST_SetPoint(geometry linestring, integer zerobasedposition, geometry point);

使用示例

  1. --Change first point in line string from -1 3 to -1 1
  2. SELECT ST_AsText(ST_SetPoint('LINESTRING(-1 2,-1 3)', 0, 'POINT(-1 1)'));
  3. st_astext
  4. -----------------------
  5. LINESTRING(-1 1,-1 3)
  6. ---Change last point in a line string (lets play with 3d linestring this time)
  7. SELECT ST_AsEWKT(ST_SetPoint(foo.the_geom, ST_NumPoints(foo.the_geom) - 1, ST_GeomFromEWKT('POINT(-1 1 3)')))
  8. FROM (SELECT ST_GeomFromEWKT('LINESTRING(-1 2 3,-1 3 4, 5 6 7)') As the_geom) As foo;
  9. st_asewkt
  10. -----------------------
  11. LINESTRING(-1 2 3,-1 3 4,-1 1 3)
  12. SELECT ST_AsText(ST_SetPoint(g, -3, p))
  13. FROM ST_GEomFromText('LINESTRING(0 0, 1 1, 2 2, 3 3, 4 4)') AS g
  14. , ST_PointN(g,1) as p;
  15. st_astext
  16. -----------------------
  17. LINESTRING(0 0,1 1,0 0,3 3,4 4)

ST_SetSRID

描述

设置几何对象的SRID。

函数声明

  1. geometry ST_SetSRID(geometry geom, integer srid);

使用示例

  1. SELECT ST_SetSRID(ST_Point(-123.365556, 48.428611),4326) As wgs84long_lat;
  2. -- the ewkt representation (wrap with ST_AsEWKT) -
  3. SRID=4326;POINT(-123.365556 48.428611)

ST_Transform

描述

将传入的几何对象的坐标参考系转换成指定的坐标参考系的几何对象,并返回这个对象。

函数声明

  1. geometry ST_Transform(geometry g1, integer srid);
  2. geometry ST_Transform(geometry geom, text to_proj);
  3. geometry ST_Transform(geometry geom, text from_proj, text to_proj);
  4. geometry ST_Transform(geometry geom, text from_proj, integer to_srid);

使用示例

  1. SELECT ST_AsText(ST_Transform(ST_GeomFromText('POLYGON((743238 2967416,743238 2967450,743265 2967450,743265.625 2967416,743238 2967416))',2249),4326)) As wgs_geom;
  2. wgs_geom
  3. ---------------------------
  4. POLYGON((-71.1776848522251 42.3902896512902,-71.1776843766326 42.3903829478009,-71.1775844305465 42.3903826677917,-71.1775825927231 42.3902893647987,-71.1776848522251 42.3902896512902));
  5. (1 row)
  6. --3D Circular String example
  7. SELECT ST_AsEWKT(ST_Transform(ST_GeomFromEWKT('SRID=2249;CIRCULARSTRING(743238 2967416 1,743238 2967450 2,743265 2967450 3,743265.625 2967416 3,743238 2967416 4)'),4326));
  8. st_asewkt
  9. --------------------------------------------------------------------------------------
  10. SRID=4326;CIRCULARSTRING(-71.1776848522251 42.3902896512902 1,-71.1776843766326 42.3903829478009 2,
  11. -71.1775844305465 42.3903826677917 3,
  12. -71.1775825927231 42.3902893647987 3,-71.1776848522251 42.3902896512902 4)

ST_Translate

描述

将一个几何对象偏移给定的数值。

函数声明

  1. geometry ST_Translate(geometry g1, float deltax, float deltay);
  2. geometry ST_Translate(geometry g1, float deltax, float deltay, float deltaz);

使用示例

  1. SELECT ST_AsText(ST_Translate(ST_GeomFromText('POINT(-71.01 42.37)',4326),1,0)) As wgs_transgeomtxt;
  2. wgs_transgeomtxt
  3. ---------------------
  4. POINT(-70.01 42.37)

ST_TransScale

描述

将几何对象的坐标值偏移指定的数值和因子。

函数声明

  1. geometry ST_TransScale(geometry geomA, float deltaX, float deltaY, float XFactor, float YFactor);

使用示例

  1. SELECT ST_AsEWKT(ST_TransScale(ST_GeomFromEWKT('LINESTRING(1 2 3, 1 1 1)'), 0.5, 1, 1, 2));
  2. st_asewkt
  3. -----------------------------
  4. LINESTRING(1.5 6 3,1.5 4 1)
  5. --Buffer a point to get an approximation of a circle, convert to curve and then translate 1,2 and scale it 3,4
  6. SELECT ST_AsText(ST_Transscale(ST_LineToCurve(ST_Buffer('POINT(234 567)', 3)),1,2,3,4));
  7. st_astext
  8. ------------------------------------------------------------------------------------------------------------------------------
  9. CURVEPOLYGON(CIRCULARSTRING(714 2276,711.363961030679 2267.51471862576,705 2264,698.636038969321 2284.48528137424,714 2276))