-
Notifications
You must be signed in to change notification settings - Fork 133
Supported PostGIS Function: STNumPoints for Geospatial datatypes #4510
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
cce0cb2
05575eb
b3d80e1
abe951b
fe1c5e9
b920386
51e7b6c
5f2696c
52de55b
6919fab
8c60d16
f7ee44e
c7a0702
6df506d
294d73d
255b941
511e761
0484446
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -428,6 +428,19 @@ CREATE OR REPLACE FUNCTION sys.STDimension(geom sys.GEOMETRY) | |
| END; | ||
| $$ LANGUAGE plpgsql IMMUTABLE STRICT PARALLEL SAFE; | ||
|
|
||
| --STNumPoints | ||
| CREATE OR REPLACE FUNCTION sys.STNumPoints(geom sys.GEOMETRY) | ||
| RETURNS integer | ||
| AS $$ | ||
| BEGIN | ||
| IF STIsValid(geom) = 0 THEN | ||
| RAISE EXCEPTION 'The geometry instance is not valid'; | ||
| ELSE | ||
| RETURN sys.STNumPoints_helper(geom); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't we need to check whether geometry is empty or not?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually it is handled by the c functions |
||
| END IF; | ||
| END; | ||
| $$ LANGUAGE plpgsql IMMUTABLE STRICT PARALLEL SAFE; | ||
|
|
||
| -- STDisjoint | ||
| -- Checks if two geometries have no points in common | ||
| CREATE OR REPLACE FUNCTION sys.STDisjoint(geom1 sys.GEOMETRY, geom2 sys.GEOMETRY) | ||
|
|
@@ -622,6 +635,11 @@ CREATE OR REPLACE FUNCTION sys.STDimension_helper(sys.GEOMETRY) | |
| RETURNS integer | ||
| AS '$libdir/postgis-3','LWGEOM_dimension' | ||
| LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE; | ||
|
|
||
| CREATE OR REPLACE FUNCTION sys.STNumPoints_helper(sys.GEOMETRY) | ||
| RETURNS integer | ||
| AS '$libdir/postgis-3','LWGEOM_npoints' | ||
| LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE; | ||
|
|
||
| CREATE OR REPLACE FUNCTION sys.STIntersects_helper(geom1 sys.GEOMETRY, geom2 sys.GEOMETRY) | ||
| RETURNS sys.BIT | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,42 @@ | ||
| ------------------------------------------------------- | ||
| ---- Include changes related to spatial types here ---- | ||
| ------------------------------------------------------- | ||
|
|
||
| --STNumPoints | ||
| -- geometry | ||
|
|
||
| CREATE OR REPLACE FUNCTION sys.STNumPoints(geom sys.GEOMETRY) | ||
| RETURNS integer | ||
| AS $$ | ||
| BEGIN | ||
| IF STIsValid(geom) = 0 THEN | ||
| RAISE EXCEPTION 'The geometry instance is not valid'; | ||
| ELSE | ||
| RETURN sys.STNumPoints_helper(geom); | ||
| END IF; | ||
| END; | ||
| $$ LANGUAGE plpgsql IMMUTABLE STRICT PARALLEL SAFE; | ||
|
|
||
| CREATE OR REPLACE FUNCTION sys.STNumPoints_helper(sys.GEOMETRY) | ||
| RETURNS integer | ||
| AS '$libdir/postgis-3','LWGEOM_npoints' | ||
| LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE; | ||
|
|
||
| -- Geography | ||
|
|
||
| CREATE OR REPLACE FUNCTION sys.STNumPoints(geog sys.GEOGRAPHY) | ||
| RETURNS integer | ||
| AS $$ | ||
| BEGIN | ||
| IF sys.STIsValid(geog) = 0 THEN | ||
| RAISE EXCEPTION 'The geography instance is not valid. Use MakeValid() to convert to valid geography.'; | ||
|
||
| ELSE | ||
| RETURN sys.STNumPoints_helper(geog); | ||
| END IF; | ||
| END; | ||
| $$ LANGUAGE plpgsql IMMUTABLE STRICT PARALLEL SAFE; | ||
|
|
||
| CREATE OR REPLACE FUNCTION sys.STNumPoints_helper(sys.GEOGRAPHY) | ||
| RETURNS integer | ||
| AS '$libdir/postgis-3', 'LWGEOM_npoints' | ||
| LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| USE TestSTNumPoints_DB | ||
|
|
||
| USE MASTER | ||
|
|
||
| DROP VIEW STNumPoints_geom_view; | ||
|
|
||
| DROP VIEW STNumPoints_geog_view; | ||
|
|
||
| DROP TABLE STNumPoints_geom_test; | ||
|
|
||
| DROP TABLE STNumPoints_geog_test; | ||
|
|
||
| DROP DATABASE TestSTNumPoints_DB |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| CREATE DATABASE TestSTNumPoints_DB; | ||
|
|
||
| USE TestSTNumPoints_DB; | ||
|
|
||
| USE MASTER | ||
|
|
||
| CREATE TABLE STNumPoints_geom_test ( ID INT PRIMARY KEY, geom_type VARCHAR(50), geom geometry ); | ||
|
|
||
| INSERT INTO STNumPoints_geom_test (ID, geom_type, geom) VALUES (1, 'Point', geometry::STPointFromText('POINT(0 0)', 0)); | ||
| ~~ROW COUNT: 1~~ | ||
|
|
||
| INSERT INTO STNumPoints_geom_test (ID, geom_type, geom) VALUES (2, 'Point with SRID', geometry::STPointFromText('POINT(-122.349 47.651)', 4326)); | ||
| ~~ROW COUNT: 1~~ | ||
|
|
||
| INSERT INTO STNumPoints_geom_test (ID, geom_type, geom) VALUES (3, 'Point constructor', geometry::Point(3.0, 4.0, 4326)); | ||
| ~~ROW COUNT: 1~~ | ||
|
|
||
| INSERT INTO STNumPoints_geom_test (ID, geom_type, geom) VALUES (4, 'LineString 2pts', geometry::STGeomFromText('LINESTRING(0 0, 1 1)', 0)); | ||
| ~~ROW COUNT: 1~~ | ||
|
|
||
| INSERT INTO STNumPoints_geom_test (ID, geom_type, geom) VALUES (5, 'LineString 3pts', geometry::STGeomFromText('LINESTRING(0 0, 1 1, 2 2)', 0)); | ||
| ~~ROW COUNT: 1~~ | ||
|
|
||
| INSERT INTO STNumPoints_geom_test (ID, geom_type, geom) VALUES (6, 'LineString 5pts', geometry::STGeomFromText('LINESTRING(0 0, 1 1, 2 2, 3 3, 4 4)', 0)); | ||
| ~~ROW COUNT: 1~~ | ||
|
|
||
| INSERT INTO STNumPoints_geom_test (ID, geom_type, geom) VALUES (7, 'Polygon triangle', geometry::STGeomFromText('POLYGON((0 0, 1 0, 0 1, 0 0))', 0)); | ||
| ~~ROW COUNT: 1~~ | ||
|
|
||
| INSERT INTO STNumPoints_geom_test (ID, geom_type, geom) VALUES (8, 'Polygon square', geometry::STGeomFromText('POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))', 0)); | ||
| ~~ROW COUNT: 1~~ | ||
|
|
||
| INSERT INTO STNumPoints_geom_test (ID, geom_type, geom) VALUES (9, 'Polygon with hole', geometry::STGeomFromText('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0), (2 2, 8 2, 8 8, 2 8, 2 2))', 0)); | ||
| ~~ROW COUNT: 1~~ | ||
|
|
||
| INSERT INTO STNumPoints_geom_test (ID, geom_type, geom) VALUES (10, 'Empty Point', geometry::STGeomFromText('POINT EMPTY', 0)); | ||
| ~~ROW COUNT: 1~~ | ||
|
|
||
| INSERT INTO STNumPoints_geom_test (ID, geom_type, geom) VALUES (11, 'Empty LineString', geometry::STGeomFromText('LINESTRING EMPTY', 0)); | ||
| ~~ROW COUNT: 1~~ | ||
|
|
||
| INSERT INTO STNumPoints_geom_test (ID, geom_type, geom) VALUES (12, 'Empty Polygon', geometry::STGeomFromText('POLYGON EMPTY', 0)); | ||
| ~~ROW COUNT: 1~~ | ||
|
|
||
| INSERT INTO STNumPoints_geom_test (ID, geom_type, geom) VALUES (13, 'Point Z', geometry::STGeomFromText('POINT Z(1 2 3)', 0)); | ||
| ~~ROW COUNT: 1~~ | ||
|
|
||
| INSERT INTO STNumPoints_geom_test (ID, geom_type, geom) VALUES (14, 'Empty Point', geometry::STGeomFromText('POINT EMPTY', 0)); | ||
| ~~ROW COUNT: 1~~ | ||
|
|
||
| INSERT INTO STNumPoints_geom_test (ID, geom_type, geom) VALUES (15, 'Empty LineString', geometry::STGeomFromText('LINESTRING EMPTY', 0)); | ||
| ~~ROW COUNT: 1~~ | ||
|
|
||
| INSERT INTO STNumPoints_geom_test (ID, geom_type, geom) VALUES (16, 'Empty Polygon', geometry::STGeomFromText('POLYGON EMPTY', 0)); | ||
| ~~ROW COUNT: 1~~ | ||
|
|
||
|
|
||
| CREATE TABLE STNumPoints_geog_test ( ID INT PRIMARY KEY, geog_type VARCHAR(50), geog geography ); | ||
| INSERT INTO STNumPoints_geog_test (ID, geog_type, geog) VALUES (1, 'Point', geography::STPointFromText('POINT(-122.349 47.651)', 4326)); | ||
| ~~ROW COUNT: 1~~ | ||
|
|
||
| INSERT INTO STNumPoints_geog_test (ID, geog_type, geog) VALUES (2, 'Point constructor', geography::Point(47.651, -122.349, 4326)); | ||
| ~~ROW COUNT: 1~~ | ||
|
|
||
| INSERT INTO STNumPoints_geog_test (ID, geog_type, geog) VALUES (3, 'LineString 2pts', geography::STGeomFromText('LINESTRING(-122.36 47.65, -122.34 47.66)', 4326)); | ||
| ~~ROW COUNT: 1~~ | ||
|
|
||
| INSERT INTO STNumPoints_geog_test (ID, geog_type, geog) VALUES (4, 'LineString 3pts', geography::STGeomFromText('LINESTRING(-122.36 47.65, -122.34 47.66, -122.32 47.67)', 4326)); | ||
| ~~ROW COUNT: 1~~ | ||
|
|
||
| INSERT INTO STNumPoints_geog_test (ID, geog_type, geog) VALUES (5, 'LineString 5pts', geography::STGeomFromText('LINESTRING(-122.36 47.65, -122.35 47.66, -122.34 47.67, -122.33 47.68, -122.32 47.69)', 4326)); | ||
| ~~ROW COUNT: 1~~ | ||
|
|
||
| INSERT INTO STNumPoints_geog_test (ID, geog_type, geog) VALUES (6, 'Polygon triangle', geography::STGeomFromText('POLYGON((-122.36 47.65, -122.34 47.65, -122.35 47.67, -122.36 47.65))', 4326)); | ||
| ~~ROW COUNT: 1~~ | ||
|
|
||
| INSERT INTO STNumPoints_geog_test (ID, geog_type, geog) VALUES (7, 'Polygon square', geography::STGeomFromText('POLYGON((-122.36 47.65, -122.34 47.65, -122.34 47.67, -122.36 47.67, -122.36 47.65))', 4326)); | ||
| ~~ROW COUNT: 1~~ | ||
|
|
||
| INSERT INTO STNumPoints_geog_test (ID, geog_type, geog) VALUES (8, 'Empty Point', geography::STGeomFromText('POINT EMPTY', 4326)); | ||
| ~~ROW COUNT: 1~~ | ||
|
|
||
| INSERT INTO STNumPoints_geog_test (ID, geog_type, geog) VALUES (9, 'Empty LineString', geography::STGeomFromText('LINESTRING EMPTY', 4326)); | ||
| ~~ROW COUNT: 1~~ | ||
|
|
||
| INSERT INTO STNumPoints_geog_test (ID, geog_type, geog) VALUES (10, 'Point Z', geography::STGeomFromText('POINT Z(-122.349 47.651 100)', 4326)); | ||
| ~~ROW COUNT: 1~~ | ||
|
|
||
| INSERT INTO STNumPoints_geog_test (ID, geog_type, geog) VALUES (11, 'Empty Point', geography::STGeomFromText('POINT EMPTY', 4326)); | ||
| ~~ROW COUNT: 1~~ | ||
|
|
||
| INSERT INTO STNumPoints_geog_test (ID, geog_type, geog) VALUES (12, 'Empty LineString', geography::STGeomFromText('LINESTRING EMPTY', 4326)); | ||
| ~~ROW COUNT: 1~~ | ||
|
|
||
|
|
||
| CREATE VIEW STNumPoints_geom_view AS SELECT ID, geom_type, geom.STNumPoints() AS num_points FROM STNumPoints_geom_test; | ||
|
|
||
| CREATE VIEW STNumPoints_geog_view AS SELECT ID, geog_type, geog.STNumPoints() AS num_points FROM STNumPoints_geog_test; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we need to check whether geography is empty or not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually it is handled by the c functions