ST_NumPoints

定义

ST_NumPoints 用于返回几何中的点(折点)数。

对于面要素,将一并对起始折点和结束折点进行计数,即使它们处于相同的位置。

请注意,该数值与 ST_Geometry 类型的 NUMPTS 属性不同。NUMPTS 属性包含几何的所有部件的折点计数(包括部件间的分隔符)。各部件间有一个分隔符。例如,具有三个部件的多部件线串具有两个分隔符。在 NUMPTS 属性中,每个分隔符被计作一个折点。相反,ST_NumPoints 函数在折点数中不包括分隔符。

语法

Oracle 和 PostgreSQL

sde.st_numpoints (geometry1 sde.st_geometry)

SQLite

st_numpoints (geometry1 geometryblob)

返回类型

整型

示例

创建包含 geotype 列(包含 g1 列中存储的几何类型)的 numpoints_test 表。

此 INSERT 语句用于插入点、线串和面。

对于每种要素类型的每个要素,SELECT 查询都使用 ST_NumPoints 函数获取其中的点数。

Oracle

CREATE TABLE numpoints_test (
 geotype varchar(12),
 g1 sde.st_geometry
);

INSERT INTO NUMPOINTS_TEST VALUES (
 'point',
 sde.st_pointfromtext ('point (10.02 20.01)', 4326)
);

INSERT INTO NUMPOINTS_TEST VALUES (
 'linestring',
 sde.st_linefromtext ('linestring (10.02 20.01, 23.73 21.92)', 4326)
);

INSERT INTO NUMPOINTS_TEST VALUES (
 'polygon',
 sde.st_polyfromtext ('polygon ((10.02 20.01, 23.73 21.92, 24.51 12.98, 11.64 13.42, 10.02 20.01))', 4326)
);
SELECT geotype, sde.st_numpoints (g1) Number_of_points
 FROM NUMPOINTS_TEST;

GEOTYPE     Number_of_points

point                       1
linestring                  2
polygon                     5

PostgreSQL

CREATE TABLE numpoints_test (
 geotype varchar(12),
 g1 sde.st_geometry
);

INSERT INTO numpoints_test VALUES (
 'point',
 sde.st_point ('point (10.02 20.01)', 4326)
);

INSERT INTO numpoints_test VALUES (
 'linestring',
 sde.st_linestring ('linestring (10.02 20.01, 23.73 21.92)', 4326)
);

INSERT INTO numpoints_test VALUES (
 'polygon',
 sde.st_polygon ('polygon ((10.02 20.01, 23.73 21.92, 24.51 12.98, 11.64 13.42, 10.02 20.01))', 4326)
);
SELECT geotype, sde.st_numpoints (g1)
 AS Number_of_points
 FROM numpoints_test;

geotype     number_of_points

point                       1
linestring                  2
polygon                     5

SQLite

CREATE TABLE numpoints_test (
 geotype text(12)
);

SELECT AddGeometryColumn(
 NULL,
 'numpoints_test',
 'g1',
 4326,
 'geometry',
 'xy',
 'null'
);

INSERT INTO numpoints_test VALUES (
 'point',
 st_point ('point (10.02 20.01)', 4326)
);

INSERT INTO numpoints_test VALUES (
 'linestring',
 st_linestring ('linestring (10.02 20.01, 23.73 21.92)', 4326)
);

INSERT INTO numpoints_test VALUES (
 'polygon',
 st_polygon ('polygon ((10.02 20.01, 23.73 21.92, 24.51 12.98, 11.64 13.42, 10.02 20.01))', 4326)
);
SELECT geotype AS "Type of geometry", st_numpoints (g1) AS "Number of points"
 FROM numpoints_test;

Type of geometry     Number of points

point                       1
linestring                  2
polygon                     5

相关主题

5/25/2014