ST_NumPoints

Définition

ST_NumPoints retourne le nombre de points (sommets) contenus dans une géométrie.

Pour les polygones, les sommets de début et de fin sont comptés, bien qu'ils occupent le même emplacement.

Notez que ce nombre est différent de l'attribut NUMPTS du type ST_Geometry. L'attribut NUMPTS contient le nombre des sommets présents dans toutes les parties de la géométrie, y compris les séparateurs qui se trouvent entre les parties. Un séparateur se trouve entre chaque partie. Par exemple, un objet multi-parties linestring contenant trois parties a deux séparateurs. Dans l'attribut NUMPTS, chaque séparateur est compté comme un sommet. Inversement, la fonction ST_NumPoints n'inclut pas les séparateurs dans le compte des sommets.

Syntaxe

Oracle et PostgreSQL

sde.st_numpoints (geometry1 sde.st_geometry)

SQLite

st_numpoints (geometry1 geometryblob)

Type de retour

Entier

Exemple

La table numpoints_test est créée avec la colonne Geotype, qui contient le type de géométrie stocké dans la colonne g1.

Les instructions INSERT insèrent un point, un objet linestring et un polygone.

La requête SELECT utilise la fonction ST_NumPoints pour calculer le nombre de points présents dans chaque entité pour chaque type d'entité.

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

Thèmes connexes

5/10/2014