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

  • geometry_from_hadoop_shape:返回spatial framework for hadoop 、类型对象的GEOMETRY对象。
  • to_spherical_geography:从GEOMETRY对象转换成SphericalGeography对象,也就是从2D的标识到3D的标识。
  • to_geometry:从SphericalGeography对象转换成GEOMETRY对象,其实每个Geography都是一个合理的geometry的对象。
  • ST_AsBinary:返回g1对应的WKB格式内容。
  • ST_Buffer:返回离g1的距离小于或等于d对应的所有点。

ST_Point

ST_Point(x, y)
  • 命令说明:先将两个DOUBLE类型的数值x和y进行除法运算x/y,然后将x/y的结果值为坐标构造一个POINT类型的值。
  • 返回值类型:GEOMETRY类型的POINT对象,直接通过SELECT查询函数结果将显示乱码。
  • 示例:
    SELECT ST_Point(1,1);
    +-----------------------+
    | ST_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查询函数结果将显示乱码。
  • 示例:
    SELECT ST_GeometryFromText('Point(1 1)');
    +-----------------------------------+
    | ST_GeometryFromText('Point(1 1)') |
    +-----------------------------------+
    |        �?      �?                 |              
    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格式的文本。
  • 返回值类型:BOOLEAN。
  • 示例:
    SELECT ST_IsValidWKT('MULTIPOINT (1 2, 2 4, 3 6, 4 8)');
    +-------------------------------------------------------------+
    |        ST_IsValidWKT('MULTIPOINT (1 2, 2 4, 3 6, 4 8)')     |
    +-------------------------------------------------------------+
    |                        true                                 |

ST_LineFromText

ST_LineFromText(wkt)
  • 命令说明:返回WKT的文本对应的LineString的对象。
  • 返回值类型:GEOMETRY类型的对象,直接通过SELECT查询函数结果将显示乱码。
  • 示例:
    SELECT ST_LineFromText('LINESTRING (1 1, 2 2, 1 3)');
    +-------------------------------------------------------------+
    |        ST_LineFromText('LINESTRING (1 1, 2 2, 1 3)')        |
    +-------------------------------------------------------------+
    |                         �?      �?                          |
    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查询函数结果将显示乱码。
  • 示例:
    SELECT ST_PointFromText('POINT (1 2)');
    +-------------------------------------------------------------+
    |        ST_PointFromText('POINT (1 2)')                      |
    +-------------------------------------------------------------+
    |                         �?      �?                          |
    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查询函数结果将显示乱码。
  • 示例:
    SELECT ST_PolygonFromText('POLYGON ((1 1, 1 4, 4 4, 4 1))');
    +-------------------------------------------------------------+
    |        ST_PolygonFromText('POLYGON ((1 1, 1 4, 4 4, 4 1))') |
    +-------------------------------------------------------------+
    |                         �?      �?                          |
    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查询函数结果将显示乱码。
  • 示例:
    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查询函数结果将显示乱码。
  • 示例:
    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查询函数结果将显示乱码。
  • 示例:
    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查询函数结果将显示乱码。
  • 示例:
    SELECT ST_AsText(geometry_from_hadoop_shape(from_hex('000000000101000000000000000000F03F0000000000000040')));
    +-------------------------------------------------------------------------------------------------------+
    | ST_AsText(geometry_from_hadoop_shape(from_hex('000000000101000000000000000000F03F0000000000000040'))) |
    +-------------------------------------------------------------------------------------------------------+
    |          MULTIPOINT ((1 2), (3 4))                                                                    |

to_spherical_geography

to_spherical_geography(g1)
  • 命令说明:从GEOMETRY对象转换成SphericalGeography对象,也就是从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)
  • 命令说明:从SphericalGeography对象转换成GEOMETRY对象,其实每个Geography都是一个合理的GEOMETRY的对象。
  • 返回值类型:GEOMETRY类型的对象,直接通过SELECT查询函数结果将显示乱码。
  • 示例:
    SELECT to_geometry(to_spherical_geography(ST_Point(61.56, -158.54)));
    +----------------------------------------------------------------------+
    | SELECT to_geometry(to_spherical_geography(ST_Point(61.56, -158.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查询函数结果将显示乱码。
  • 示例:
    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))                                |