空间构造函数

使用空间构造函数可获取Point、Line或Polygon Geometry数据类型的二进制表示。您也可以使用这些函数来将二进制数据转换为文本数据,以及获取以已知文本(WKT)格式表示的Geometry数据的二进制值。

ST_Point

ST_Point(x, y)
  • 命令说明:返回以x,y为坐标的Point类型的值。

  • 返回值类型:Geometry类型的Point对象,直接通过SELECT查询函数结果将显示乱码。

  • 示例:

    SELECT ST_Point(1,1);
                

    返回结果:

    +-----------------------+
    | ST_Point(1,1)         |
    +-----------------------+
    |        �?      �?   |        

    可以使用ST_AsText函数将返回结果转换为可识别的文本,示例:

    SELECT ST_AsText(ST_Point(1,1));

    返回结果:

    +-----------------------+
    | ST_Point(1,1)         |
    +-----------------------+
    |        POINT (1 1)    | 

ST_AsText

ST_AsText(geometry)
  • 命令说明:将每个指定的Geometry数据类型转换为文本。

  • 返回值类型:返回Geometry的WKT(Well-Known Text)格式。

  • 示例:

    SELECT ST_AsText(ST_Point(1,1));                

    返回结果:

    +--------------------------+
    | ST_AsText(ST_Point(1,1)) |
    +--------------------------+
    | POINT (1 1)              |   

ST_GeometryFromText或ST_GeomFromText

ST_GeometryFromText(wkt)
  • 命令说明:使用WKT格式的字符串构造Geometry值。

  • 返回值类型:Geometry类型的对象,直接通过SELECT查询函数结果将显示乱码,可以使用ST_AsText函数将返回结果转换为可识别的文本。

  • 示例:

    SELECT ST_AsText(ST_GeometryFromText('Point(1 1)'));      

    返回结果:

    +----------------------------------------------+
    | ST_AsText(ST_GeometryFromText('Point(1 1)')) |
    +----------------------------------------------+
    | POINT (1 1)                                  |    

ST_IsValidWKT

ST_IsValidWKT(wkt)
  • 命令说明:返回WKT的是否是正确的WKT格式的文本,1为True,0为False。

  • 返回值类型:INT。

  • 示例:

    SELECT ST_IsValidWKT('MULTIPOINT (1 2, 2 4, 3 6, 4 8)');

    返回结果:

    +-------------------------------------------------------------+
    |        ST_IsValidWKT('MULTIPOINT (1 2, 2 4, 3 6, 4 8)')     |
    +-------------------------------------------------------------+
    |                        1                                    |

ST_LineFromText

ST_LineFromText(wkt)
  • 命令说明:返回WKT的文本对应的LineString的对象。

  • 返回值类型:Geometry类型的对象,直接通过SELECT查询函数结果将显示乱码,可以使用ST_AsText函数将返回结果转换为可识别的文本。

  • 示例:

    SELECT ST_AsText(ST_LineFromText('LINESTRING (1 1, 2 2, 1 3)'));

    返回结果:

    +-----------------------------------------------------------------------+
    |        ST_AsText(ST_LineFromText('LINESTRING (1 1, 2 2, 1 3)'))       |
    +-----------------------------------------------------------------------+
    |                        LINESTRING (1 1, 2 2, 1 3)                     |

ST_PointFromText

ST_PointFromText(wkt)
  • 命令说明:返回WKT的文本对应的PointString的对象。

  • 返回值类型:Geometry类型的对象,直接通过SELECT查询函数结果将显示乱码,可以使用ST_AsText函数将返回结果转换为可识别的文本。

  • 示例:

    SELECT ST_AsText(ST_PointFromText('POINT (1 2)'));

    返回结果:

    +-------------------------------------------------------------+
    |        ST_AsText(ST_PointFromText('POINT (1 2)'))           |
    +-------------------------------------------------------------+
    |                       POINT (1 2)                           |

ST_PolygonFromText

ST_PolygonFromText(wkt)
  • 命令说明:返回WKT的文本对应的PolygonString的对象。

  • 返回值类型:Geometry类型的对象,直接通过SELECT查询函数结果将显示乱码,可以使用ST_AsText函数将返回结果转换为可识别的文本。

  • 示例:

    SELECT ST_AsText(ST_PolygonFromText('POLYGON ((1 1, 1 4, 4 4, 4 1))'));

    返回结果:

    +------------------------------------------------------------------------+
    |        ST_AsText(ST_PolygonFromText('POLYGON ((1 1, 1 4, 4 4, 4 1))')) |
    +------------------------------------------------------------------------+
    |                        POLYGON ((1 1, 1 4, 4 4, 4 1))                  | 

ST_LineString

ST_LineString(array(g1,g2...))
  • 命令说明:返回g1,g2,g3一组点的LineString。

  • 返回值类型:Geometry类型的对象,直接通过SELECT查询函数结果将显示乱码,可以使用ST_AsText函数将返回结果转换为可识别的文本。

  • 示例:

    SELECT ST_AsText(ST_LineString(array[ST_Point(1,2), ST_Point(3,4)]));

    返回结果:

    +------------------------------------------------------------------------+
    | ST_AsText(ST_LineString(array[ST_Point(1,2), ST_Point(3,4)]))          |
    +------------------------------------------------------------------------+
    |           LINESTRING (1 2, 3 4)                                        |    

ST_MultiPoint

ST_MultiPoint(array(g1,g2...))
  • 命令说明:返回g1,g2,g3等一组点组成的多点Geometry对象。

  • 返回值类型:Geometry类型的对象,直接通过SELECT查询函数结果将显示乱码,可以使用ST_AsText函数将返回结果转换为可识别的文本。

  • 示例:

    SELECT ST_AsText(ST_MultiPoint(array[ST_GeometryFromText('POINT(1 2)'), ST_GeometryFromText('POINT (3 4)')]));

    返回结果:

    +----------------------------------------------------------------------------------------------------------+
    |  ST_AsText(ST_MultiPoint(array[ST_GeometryFromText('POINT(1 2)'), ST_GeometryFromText('POINT (3 4)')]))  |
    +----------------------------------------------------------------------------------------------------------+
    |          MULTIPOINT ((1 2), (3 4))                                                                       | 

ST_GeomFromBinary

ST_GeomFromBinary(wkb)
  • 命令说明:返回WKB类型对象的Geometry对象。

  • 返回值类型:Geometry类型的对象,直接通过SELECT查询函数结果将显示乱码,可以使用ST_AsText函数将返回结果转换为可识别的文本。

  • 示例:

    SELECT ST_AsText(ST_GeomFromBinary(ST_AsBinary(ST_GeometryFromText('MULTIPOINT ((1 2), (3 4))'))));
    +------------------------------------------------------------------------------------------------+
    |  ST_AsText(ST_GeomFromBinary(ST_AsBinary(ST_GeometryFromText('MULTIPOINT ((1 2), (3 4))'))))   |
    +------------------------------------------------------------------------------------------------+
    |          MULTIPOINT ((1 2), (3 4))                                                             |

Geometry_from_hadoop_shape

Geometry_from_hadoop_shape(wkb)
  • 命令说明:返回Spatial Framework for Hadoop类型对象的Geometry对象。

  • 返回值类型:Geometry类型的对象,直接通过SELECT查询函数结果将显示乱码,可以使用ST_AsText函数将返回结果转换为可识别的文本。

  • 示例:

    SELECT ST_AsText(Geometry_from_hadoop_shape(from_hex('000000000101000000000000000000F03F0000000000000040')));

    返回结果:

    +-------------------------------------------------------------------------------------------------------+
    | ST_AsText(Geometry_from_hadoop_shape(from_hex('000000000101000000000000000000F03F0000000000000040'))) |
    +-------------------------------------------------------------------------------------------------------+
    |                         POINT (1 2)                                                                   |

To_spherical_geography

To_spherical_geography(g1)
  • 命令说明:从Geometry对象转换成Spherical Geography对象,即从2D的标识到3D的标识。

  • 返回值类型:Geometry类型的对象,直接通过SELECT查询函数结果将显示乱码。

  • 示例:

    SELECT To_spherical_geography(ST_Point(-71.0882, 42.3607));

    返回结果:

    +-----------------------------------------------------------+
    | To_spherical_geography(ST_Point(-71.0882, 42.3607))       |
    +-----------------------------------------------------------+
    |          �?      �?                                      |

To_geometry

To_geometry(g1)
  • 命令说明:从Spherical Geography对象转换成Geometry对象,其实每个Geography都是一个合理的Geometry的对象。

  • 返回值类型:Geometry类型的对象,直接通过SELECT查询函数结果将显示乱码,可以使用ST_AsText函数将返回结果转换为可识别的文本。

  • 示例:

    SELECT ST_ASText(To_geometry(To_spherical_geography(ST_Point(61.56, -58.54))));

    返回结果:

    +----------------------------------------------------------------------------+
    | ST_ASText(To_geometry(To_spherical_geography(ST_Point(61.56, -58.54))))    |
    +----------------------------------------------------------------------------+
    |           POINT (61.56 -58.54)                                             |

ST_AsBinary

ST_AsBinary(g1)
  • 命令说明:返回g1对应的WKB格式内容。

  • 返回值类型:VARBINARY。

  • 示例:

    SELECT ST_AsText(ST_GeomFromBinary(ST_AsBinary(ST_GeometryFromText('MULTIPOINT ((1 2), (3 4))'))));

    返回结果:

    +--------------------------------------------------------------------------------------------------+
    |  ST_AsText(ST_GeomFromBinary(ST_AsBinary(ST_GeometryFromText('MULTIPOINT ((1 2), (3 4))'))))     |
    +--------------------------------------------------------------------------------------------------+
    |          MULTIPOINT ((1 2), (3 4))                                                               |

ST_Buffer

ST_Buffer(g1, d)
  • 命令说明:返回离g1的举例小于或等于d对应的所有点。

  • 返回值类型:Geometry类型的对象,直接通过SELECT查询函数结果将显示乱码,可以使用ST_AsText函数将返回结果转换为可识别的文本。

  • 示例:

    SELECT ST_AsText(ST_Buffer(ST_Point(0, 0), 0.5));

    返回结果:

    +----------------------------------------------------------------------------------------------+
    |  ST_AsText(ST_Buffer(ST_Point(0, 0), 0.5))                                                   |
    +----------------------------------------------------------------------------------------------+
    |          POLYGON ((0.5 0, 0.4989294616193014 0.03270156461507146, 
    0.49572243068690486 0.0652630961100257, 0.4903926402016149 0.09754516100806403,
    0.4829629131445338 0.12940952255126026, 0.47346506474755257 0.16071973265158065, 
    0.46193976625564315 0.19134171618254472, 0.4484363707663439 0.22114434510950046, 
    0.43301270189221913 0.2499999999999998, 0.41573480615127245 0.2777851165098009, 
    0.39667667014561747 0.30438071450436016, 0.3759199037394886 0.32967290755003426, 
    0.3535533905932737 0.3535533905932736, 0.32967290755003437 0.3759199037394886, 
    0.3043807145043603 0.39667667014561747, 0.2777851165098011 0.4157348061512725, 
    0.24999999999999997 0.43301270189221924, 0.22114434510950062 0.4484363707663441, 
    0.19134171618254486 0.4619397662556433, 0.16071973265158077 0.4734650647475528, 
    0.12940952255126037 0.48296291314453416, 0.09754516100806412 0.4903926402016152, 
    0.06526309611002579 0.4957224306869052, 0.03270156461507153 0.49892946161930174, 
    0 0.5, -0.03270156461507146 0.4989294616193014, -0.0652630961100257 
    0.49572243068690486, -0.09754516100806403 0.4903926402016149, -0.12940952255126026 
    0.4829629131445338, -0.16071973265158065 0.47346506474755257, -0.19134171618254472 
    0.46193976625564315, -0.22114434510950046 0.4484363707663439, -0.2499999999999998 
    0.43301270189221913, -0.2777851165098009 0.41573480615127245, -0.30438071450436016 
    0.39667667014561747, -0.32967290755003426 0.3759199037394886, -0.3535533905932736 
    0.3535533905932737, -0.3759199037394886 0.32967290755003437, -0.39667667014561747 
    0.3043807145043603, -0.4157348061512725 0.2777851165098011, -0.43301270189221924 
    0.24999999999999997, -0.4484363707663441 0.22114434510950062, -0.4619397662556433 
    0.19134171618254486, -0.4734650647475528 0.16071973265158077, -0.48296291314453416 
    0.12940952255126037, -0.4903926402016152 0.09754516100806412, -0.4957224306869052 
    0.06526309611002579, -0.49892946161930174 0.03270156461507153, -0.5 0, 
    -0.4989294616193014 -0.03270156461507146, -0.49572243068690486 -0.0652630961100257, 
    -0.4903926402016149 -0.09754516100806403, -0.4829629131445338 -0.12940952255126026, 
    -0.47346506474755257 -0.16071973265158065, -0.46193976625564315 
    -0.19134171618254472, -0.4484363707663439 -0.22114434510950046, 
    -0.43301270189221913 -0.2499999999999998, -0.41573480615127245 -0.2777851165098009, 
    -0.39667667014561747 -0.30438071450436016, -0.3759199037394886 -0.32967290755003426, 
    -0.3535533905932737 -0.3535533905932736, -0.32967290755003437 -0.3759199037394886, 
    -0.3043807145043603 -0.39667667014561747, -0.2777851165098011 -0.4157348061512725, 
    -0.24999999999999997 -0.43301270189221924, -0.22114434510950062 -0.4484363707663441, 
    -0.19134171618254486 -0.4619397662556433, -0.16071973265158077 -0.4734650647475528, 
    -0.12940952255126037 -0.48296291314453416, -0.09754516100806412 -0.4903926402016152, 
    -0.06526309611002579 -0.4957224306869052, -0.03270156461507153 -0.49892946161930174, 
    0 -0.5, 0.03270156461507146 -0.4989294616193014, 0.0652630961100257 
    -0.49572243068690486, 0.09754516100806403 -0.4903926402016149, 0.12940952255126026 
    -0.4829629131445338, 0.16071973265158065 -0.47346506474755257, 0.19134171618254472 
    -0.46193976625564315, 0.22114434510950046 -0.4484363707663439, 0.2499999999999998 
    -0.43301270189221913, 0.2777851165098009 -0.41573480615127245, 0.30438071450436016 
    -0.39667667014561747, 0.32967290755003426 -0.3759199037394886, 0.3535533905932736 
    -0.3535533905932737, 0.3759199037394886 -0.32967290755003437, 0.39667667014561747 
    -0.3043807145043603, 0.4157348061512725 -0.2777851165098011, 0.43301270189221924 
    -0.24999999999999997, 0.4484363707663441 -0.22114434510950062, 0.4619397662556433 
    -0.19134171618254486, 0.4734650647475528 -0.16071973265158077, 0.48296291314453416 
    -0.12940952255126037, 0.4903926402016152 -0.09754516100806412, 0.4957224306869052 
    -0.06526309611002579, 0.49892946161930174 -0.03270156461507153, 0.5 0))                          |