文档

空间对象处理函数

更新时间:
一键部署

ST_Buffer

描述

对于给定的几何对象或地理对象,返回一个覆盖了所有的到它的距离小于给定值的坐标点的相应几何对象或地理对象。

函数声明

  1. geometry ST_Buffer(geometry g1, float radius_of_buffer);

使用示例

  1. SELECT ST_Buffer(ST_GeomFromText('POINT(100 90)'), 50);
  2. st_buffer(st_geomfromtext('POINT(100 90)'), 50)
  3. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  4. POLYGON ((150 90, 149.0392640201615 80.24548389919359, 146.19397662556435 70.86582838174552, 141.57348061512727 62.22148834901989, 135.35533905932738 54.64466094067263, 127.77851165098011 48.42651938487274, 119.1341716182545 43.80602337443566, 109.75451610080641 40.960735979838475, 100 40, 90.24548389919359 40.960735979838475, 80.86582838174552 43.80602337443566, 72.2214883490199 48.42651938487273, 64.64466094067262 54.64466094067262, 58.426519384872734 62.22148834901989, 53.80602337443566 70.86582838174553, 50.960735979838475 80.24548389919362, 50 90.00000000000004, 50.96073597983849 99.75451610080646, 53.80602337443568 109.13417161825454, 58.426519384872776 117.77851165098016, 64.64466094067268 125.35533905932743, 72.22148834901996 131.57348061512732, 80.8658283817456 136.19397662556437, 90.2454838991937 139.03926402016154, 100.00000000000013 140, 109.75451610080654 139.0392640201615, 119.13417161825463 136.1939766255643, 127.77851165098025 131.57348061512718, 135.3553390593275 125.35533905932726, 141.57348061512735 117.77851165097996, 146.1939766255644 109.13417161825431, 149.03926402016157 99.75451610080621, 150 90))
  5. (1 row)

ST_ConvexHull

描述

返回给定几何对象的最小凸包。

函数声明

  1. geometry ST_ConvexHull(geometry geomA);

使用示例

  1. SELECT ST_ConvexHull(ST_GeomFromText('LINESTRING (0 0, 1 1, 1 2, 1 3)'));
  2. st_convexhull(st_geomfromtext('LINESTRING (0 0, 1 1, 1 2, 1 3)'))
  3. -------------------------------------------------------------------
  4. POLYGON ((0 0, 1 3, 1 1, 0 0))
  5. (1 row)

ST_Difference

描述

返回一个几何对象,代表给定几何对象A中与几何对象B不相交的部分。

函数声明

  1. geometry ST_Difference(geometry geomA, geometry geomB);

使用示例

  1. --Safe for 2d. This is same geometries as what is shown for st_symdifference
  2. SELECT ST_AsText(
  3. ST_Difference(
  4. ST_GeomFromText('LINESTRING(50 80, 50 40)'),
  5. ST_GeomFromText('LINESTRING(50 50, 50 10)')
  6. )
  7. );
  8. st_astext(st_difference(st_geomfromtext('LINESTRING(50 80, 50 40)'), st_geomfromtext('LINESTRING(50 50, 50 10)')))
  9. --------------------------------------------------------------------------------------------------------------------
  10. LINESTRING (50 80, 50 50)
  11. (1 row)

ST_Intersection

描述

返回一个代表了给定几何对象或地理对象A与B的重叠部分的几何对象或地理对象。如果两个对象没有交集,返回null。

函数声明

  1. geometry ST_Intersection( geometry geomA , geometry geomB );

使用示例

  1. SELECT ST_AsText(ST_Intersection('POINT(0 0)'::geometry, 'LINESTRING ( 2 0, 0 2 )'::geometry));
  2. st_astext(st_intersection(CAST('POINT(0 0)' AS geometry), CAST('LINESTRING ( 2 0, 0 2 )' AS geometry)))
  3. ---------------------------------------------------------------------------------------------------------
  4. (1 row)
  5. SELECT ST_AsText(ST_Intersection('POINT(0 0)'::geometry, 'LINESTRING ( 0 0, 0 2 )'::geometry));
  6. st_astext(st_intersection(CAST('POINT(0 0)' AS geometry), CAST('LINESTRING ( 0 0, 0 2 )' AS geometry)))
  7. ---------------------------------------------------------------------------------------------------------
  8. POINT (0 0)
  9. (1 row)

ST_Simplify

描述

返回给定几何对象的简化版本,使用道格拉斯-普克算法生成该几何对象的近似表示。

函数声明

  1. geometry ST_Simplify(geometry geomA, float tolerance);

使用示例

  1. SELECT ST_Npoints(the_geom) As np_before, ST_NPoints(ST_Simplify(the_geom,0.1)) As np01_notbadcircle, ST_NPoints(ST_Simplify(the_geom,0.5)) As np05_notquitecircle,
  2. ST_NPoints(ST_Simplify(the_geom,1)) As np1_octagon, ST_NPoints(ST_Simplify(the_geom,10)) As np10_triangle,
  3. (ST_Simplify(the_geom,100) is null) As np100_geometrygoesaway
  4. FROM (SELECT ST_Buffer('POINT(1 3)', 10) As the_geom) As foo;
  5. -result
  6. np_before | np01_notbadcircle | np05_notquitecircle | np1_octagon | np10_triangle | np100_geometrygoesaway
  7. -----------+-------------------+---------------------+-------------+---------------+------------------------
  8. 33 | 33 | 17 | 9 | 4 | f
  9. (1 row)

ST_SimplifyPreserveTopology

描述

返回给定几何对象的简化版本,使用道格拉斯-普克算法生成该几何对象的近似表示。同时避免构造无效(Invalid)的几何对象(特别是Polygon)。

函数声明

  1. geometry ST_SimplifyPreserveTopology(geometry geomA, float tolerance);

使用示例

  1. SELECT ST_Npoints(the_geom) As np_before, ST_NPoints(ST_SimplifyPreserveTopology(the_geom,0.1)) As np01_notbadcircle, ST_NPoints(ST_SimplifyPreserveTopology(the_geom,0.5)) As np05_notquitecircle,
  2. ST_NPoints(ST_SimplifyPreserveTopology(the_geom,1)) As np1_octagon, ST_NPoints(ST_SimplifyPreserveTopology(the_geom,10)) As np10_square,
  3. ST_NPoints(ST_SimplifyPreserveTopology(the_geom,100)) As np100_stillsquare
  4. FROM (SELECT ST_Buffer('POINT(1 3)', 10) As the_geom) As foo;
  5. --result--
  6. np_before | np01_notbadcircle | np05_notquitecircle | np1_octagon | np10_square | np100_stillsquare
  7. -----------+-------------------+---------------------+-------------+-------------+-------------------
  8. 33 | 33 | 17 | 9 | 5 | 5
  9. (1 row)

ST_SymDifference

描述

返回给定几何对象A和B中不相交的部分。

函数声明

  1. geometry ST_SymDifference(geometry geomA, geometry geomB);

使用示例

  1. --Safe for 2d - symmetric difference of 2 linestrings
  2. SELECT ST_AsText(
  3. ST_SymDifference(
  4. ST_GeomFromText('LINESTRING(50 40, 50 80)'),
  5. ST_GeomFromText('LINESTRING(50 10, 50 50)')
  6. )
  7. );
  8. st_astext(st_symdifference(st_geomfromtext('LINESTRING(50 40, 50 80)'), st_geomfromtext('LINESTRING(50 10, 50 50)')))
  9. -----------------------------------------------------------------------------------------------------------------------
  10. MULTILINESTRING ((50 50, 50 80), (50 10, 50 40))
  11. (1 row)

ST_Union

描述

返回给定两个几何对象的并集。

函数声明

  1. geometry ST_Union(geometry g1, geometry g2);

使用示例

  1. SELECT ST_AsText(ST_Union(ST_GeomFromText('POINT(1 2)'),
  2. ST_GeomFromText('POINT(-2 3)') ) );
  3. st_astext
  4. ----------
  5. MULTIPOINT(-2 3,1 2)
  6. SELECT ST_AsText(ST_Union(ST_GeomFromText('POINT(1 2)'),
  7. ST_GeomFromText('POINT(1 2)') ) );
  8. st_astext
  9. ----------
  10. POINT(1 2)
  • 本页导读 (1)
文档反馈