注册 ST_Geometry 列

如果使用 SQL 创建包含 ST_Geometry 列的表,可注册该列以使用特定的空间参考和维数。这样,当通过 SQL 插入记录时,就不会意外插入使用不同空间参考的记录。

在 PostgreSQL 中注册 ST_Geometry 列

使用 st_register_spatial_column 在通过 SQL 创建的 PostgreSQL 表中注册 ST_Geometry 列。st_register_spatial_column 函数的语法如下:

SELECT st_register_spatial_column (
 '<database_name>',
 '<schema_name>',
 '<table_name>',
 '<spatial_column_name>',
 <srid>,
 <coordinate_dimension>
);

PostgreSQL 中的 public.sde_spatial_references 表中必须存在您指定的 SRID。坐标维度表示数据仅有 x,y 坐标 (2) 还是有 x,y,z 坐标 (3)、x,y,z,m 坐标 (4) 或 x,y,m 坐标 (5)。默认情况下,如果不指定坐标维度,则数据将注册为仅有 x,y 维度

以下步骤提供一个示例,介绍如何在 PostgreSQL 中注册 ST_Geometry 列以使用特定 SRID 和维数:

步骤:
  1. 打开命令提示符或 shell 提示符。
  2. 登录 SQL 编辑器,然后连接到含有要注册 ST_Geometry 列的表的数据库。

    此例中,用户 horace 连接到数据库 spatdat。

    psql spatdat horace

  3. 在 SQL 提示符处,调用 st_register_spatial_column 函数来注册表的空间列,以使用特定 SRID 和维数。

    此处,方案 cleo 中 waypoints 表的 geo 列注册为 SRID 等于 104199 和 x,y,z 维数:

    SELECT sde.st_register_spatial_column(
     'spatdat',
     'cleo',
     'waypoints',
     'geo',
     104199,
     3
    );
    

    用户 horace 对 cleo.waypoints 表必须至少有 SELECT 权限才能注册空间列。

  4. 要确认表已正确注册,可使用 st_isregistered_spatial_column 和 st_get_coord_dimension 函数返回注册信息。

    如果列已注册为指定 SRID,st_isregistered_spatial_column 函数返回 1(真)。

    SELECT sde.st_isregistered_spatial_column(
     'spatdat',
     'cleo',
     'waypoints',
     'geo',
     104199
    );
    
    st_isregistered_spatial_column
    --------------------------------
    1
    

    st_get_coord_dimension 函数返回表可存储的坐标维度:

    SELECT sde.st_get_coord_dimension(
     'cleo',
     'waypoints',
     'geo',
     104199
    );
    
    st_get_coord_dimension
    --------------------------------
    xyz
    

在 SQLite 中注册 ST_Geometry 列

使用 AddGeometryColumn 将 ST_Geometry 列添加到 SQLite 的表中并使用特定的 SRID 和坐标维度进行注册。AddGeometryColumn 的语法如下:

SELECT AddGeometryColumn (
 <'main'|null>,
 <table_name>,
 <spatial_column_name>,
 <srid>,
 <geometry_type>
 <coordinate_dimension>,
 <'null'|'not null'>
);

当通过 SQL 客户端连接 SQLite 时,您将会连接到主数据库。您可以指定主数据库或使用空值,使用空值时会假设您将连接到主数据库。坐标维度为 xy (2)、xyz (3)、xyzm (4) 或 xyzm (5)。如果您将维度指定为 xy 或 2,则不必包括几何类型的维度。如果您指定任何其他维度,则必须同时包括指定几何类型时的信息。您可以键入几何类型或几何类型的代码。可能的值如下:

几何类型值

代码

st_geometry 或 geometry

0

st_point 或 point

1

st_linestring 或 linestring

2

st_polygon 或 polygon

3

st_multipoint 或 multipoint

4

st_multilinestring 或 multilinestring

5

st_multipolygon 或 multipolygon

6

st_geometryz 或 geometryz

1000

st_pointz 或 pointz

1001

st_linestringz 或 linestringz

1002

st_polygonz 或 polygonz

1003

st_multipointz 或 multipointz

1004

st_multilinestringz 或 multilinestringz

1005

st_multipolygonz 或 multipolygonz

1006

st_geometrym 或 geometrym

2000

st_pointm 或 pointm

2001

st_linestringm 或 linestringm

2002

st_polygonm 或 polygonm

2003

st_multipointm 或 multipointm

2004

st_multilinestringm 或 multilinestringm

2005

st_multipolygonm 或 multipolygonm

2006

st_geometryzm 或 geometryzm

3000

st_pointzm 或 pointzm

3001

st_linestringzm 或 linestringzm

3002

st_polygonzm 或 polygonzm

3003

st_multipointzm 或 multipointzm

3004

st_multilinestringzm 或 linestringzm

3005

st_multipolygonzm 或 multipolygonzm

3006

有关在 SQLite 中创建表以及使用 AddGeometryColumn 来添加和注册 ST_Geometry 列的示例,请参阅创建包含 ST_Geometry 列的表

在 Oracle 中注册 ST_Geometry 列

在 Oracle 中,于 ST_Geometry 列中创建空间索引将会注册列以使用特定空间参考。有关使用 SQL 在 Oracle 中创建空间索引的示例,请参阅为包含 ST_Geometry 列的表创建空间索引

相关主题

5/25/2014