-
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 7 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,45 @@ | ||
| USE TestGeospatialMethods_DB | ||
|
|
||
| DROP TABLE TestGeospatialMethods_YourTable1Temp | ||
|
|
||
| DROP TABLE TestGeospatialMethods_YourTable3Temp | ||
|
|
||
| USE MASTER | ||
|
|
||
| DROP TABLE TestGeospatialMethods_YourTable2Temp | ||
|
|
||
| DROP TABLE TestGeospatialMethods_TableATemp | ||
|
|
||
| DROP TABLE TestGeospatialMethods_TableBTemp | ||
|
|
||
| DROP VIEW TestGeospatialMethods_ValFromGeomTemp | ||
|
|
||
| DROP VIEW TestGeospatialMethods_TextFromGeogTemp | ||
|
|
||
| DROP VIEW TestGeospatialMethods_point_intersect1Temp | ||
|
|
||
| DROP VIEW TestGeospatialMethods_disjointTemp | ||
|
|
||
| DROP VIEW TestGeospatialMethods_point_intersectTemp | ||
|
|
||
| DROP VIEW TestGeospatialMethods_point_disjointTemp | ||
|
|
||
| DROP TABLE TestGeospatialMethods_YourTableTemp | ||
|
|
||
| DROP VIEW TestGeospatialMethods_valid_ValFromGeomTemp | ||
|
|
||
| DROP VIEW TestGeospatialMethods_valid_TextFromGeogTemp | ||
|
|
||
| DROP VIEW TestGeospatialMethods_closed_ValFromGeomTemp | ||
|
|
||
| DROP VIEW TestGeospatialMethods_closed_TextFromGeogTemp | ||
|
|
||
| DROP VIEW TestGeospatialMethods_empty_ValFromGeomTemp | ||
|
|
||
| DROP VIEW TestGeospatialMethods_empty_TextFromGeomTemp | ||
|
|
||
| DROP TABLE TestGeospatialMethods_SPATIALPOINTGEOM_dttemp | ||
|
|
||
| DROP TABLE TestGeospatialMethods_SPATIALPOINTGEOG_dttemp | ||
|
|
||
| DROP DATABASE TestGeospatialMethods_DB |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| # This file tests support for these functions: STDimension, STDisjoint, STIntersects, STIsClosed, STIsEmpty, STIsValid | ||
|
|
||
| CREATE DATABASE TestGeospatialMethods_DB; | ||
|
|
||
| USE TestGeospatialMethods_DB; | ||
|
|
||
| CREATE TABLE TestGeospatialMethods_YourTable1Temp ( ID INT PRIMARY KEY, PointColumn geometry ); | ||
| INSERT INTO TestGeospatialMethods_YourTable1Temp (ID, PointColumn) VALUES (1, geometry::Point(3.0, 4.0, 4326)), (2, geometry::Point(5.0, 6.0, 4326)), (3, geometry::Point(3.0, 4.0, 0)), (4, geometry::STPointFromText('POINT EMPTY', 4123)); | ||
| ~~ROW COUNT: 4~~ | ||
|
|
||
|
|
||
| CREATE TABLE TestGeospatialMethods_YourTable3Temp ( ID INT PRIMARY KEY, PointColumn geography ); | ||
| INSERT INTO TestGeospatialMethods_YourTable3Temp (ID, PointColumn) VALUES (1, geography::Point(3.0, 4.0, 4326)), (2, geography::Point(5.0, 6.0, 4121)), (3, geography::Point(3.0, 4.0, 4122)), (4, geography::STPointFromText('POINT EMPTY', 4123)); | ||
| ~~ROW COUNT: 4~~ | ||
|
|
||
|
|
||
| USE MASTER | ||
|
|
||
| CREATE TABLE TestGeospatialMethods_YourTableTemp ( ID INT PRIMARY KEY, PointColumn geometry ); | ||
| INSERT INTO TestGeospatialMethods_YourTableTemp (ID, PointColumn) VALUES (1, geometry::Point(3.0, 4.0, 4326)), (2, geometry::Point(5.0, 6.0, 4326)), (3, geometry::Point(3.0, 4.0, 0)); | ||
| ~~ROW COUNT: 3~~ | ||
|
|
||
|
|
||
| CREATE TABLE TestGeospatialMethods_YourTable2Temp ( ID INT PRIMARY KEY, PointColumn1 geometry, PointColumn2 geometry ); | ||
| INSERT INTO TestGeospatialMethods_YourTable2Temp (ID, PointColumn1, PointColumn2) VALUES (1, geometry::Point(3.0, 4.0, 4326), geometry::Point(3.0, 4.0, 4326)); | ||
| ~~ROW COUNT: 1~~ | ||
|
|
||
|
|
||
| CREATE TABLE TestGeospatialMethods_TableATemp (ID INT PRIMARY KEY, PointA geometry); | ||
| INSERT INTO TestGeospatialMethods_TableATemp (ID, PointA) VALUES (1, geometry::Point(1.0, 2.0, 4326)); | ||
| ~~ROW COUNT: 1~~ | ||
|
|
||
|
|
||
| CREATE TABLE TestGeospatialMethods_TableBTemp (ID INT PRIMARY KEY, PointB geometry); | ||
| INSERT INTO TestGeospatialMethods_TableBTemp (ID, PointB) VALUES (1, geometry::Point(3.0, 4.0, 4326)); | ||
| ~~ROW COUNT: 1~~ | ||
|
|
||
|
|
||
| CREATE TABLE TestGeospatialMethods_SPATIALPOINTGEOG_dttemp (location geography); | ||
| INSERT INTO TestGeospatialMethods_SPATIALPOINTGEOG_dttemp (location) VALUES ( geography::STGeomFromText('Point(47.65100 -22.34900)', 4326) ); | ||
| ~~ROW COUNT: 1~~ | ||
|
|
||
| INSERT INTO TestGeospatialMethods_SPATIALPOINTGEOG_dttemp (location) VALUES ( geography::STGeomFromText('Point(1.0 2.0)', 4326) ); | ||
| ~~ROW COUNT: 1~~ | ||
|
|
||
| INSERT INTO TestGeospatialMethods_SPATIALPOINTGEOG_dttemp (location) VALUES ( geography::STGeomFromText('Point(1.0 2.0)', 4326) ); | ||
| ~~ROW COUNT: 1~~ | ||
|
|
||
| INSERT INTO TestGeospatialMethods_SPATIALPOINTGEOG_dttemp (location) VALUES ( geography::STPointFromText('Point(1.0 2.0)', 4326) ); | ||
| ~~ROW COUNT: 1~~ | ||
|
|
||
|
|
||
| CREATE TABLE TestGeospatialMethods_SPATIALPOINTGEOM_dttemp (location geometry); | ||
| INSERT INTO TestGeospatialMethods_SPATIALPOINTGEOM_dttemp (location) VALUES ( geometry::STGeomFromText('Point(47.65100 -22.34900)', 4326) ); | ||
| ~~ROW COUNT: 1~~ | ||
|
|
||
| INSERT INTO TestGeospatialMethods_SPATIALPOINTGEOM_dttemp (location) VALUES ( geometry::STGeomFromText('Point(1.0 2.0)', 4326) ); | ||
| ~~ROW COUNT: 1~~ | ||
|
|
||
| INSERT INTO TestGeospatialMethods_SPATIALPOINTGEOM_dttemp (location) VALUES ( geometry::STGeomFromText('Point(47.65100 -22.34900)', 0) ); | ||
| ~~ROW COUNT: 1~~ | ||
|
|
||
| INSERT INTO TestGeospatialMethods_SPATIALPOINTGEOM_dttemp (location) VALUES ( geometry::STPointFromText('Point(1.0 2.0)', 4326) ); | ||
| ~~ROW COUNT: 1~~ | ||
|
|
||
| INSERT INTO TestGeospatialMethods_SPATIALPOINTGEOM_dttemp (location) VALUES ( geometry::Point(47.65100, -22.34900, 4326) ); | ||
| ~~ROW COUNT: 1~~ | ||
|
|
||
|
|
||
| CREATE VIEW TestGeospatialMethods_point_intersect1Temp AS SELECT p1.location.STIntersects(p2.location) AS intersection FROM TestGeospatialMethods_SPATIALPOINTGEOM_dttemp p1 CROSS JOIN TestGeospatialMethods_SPATIALPOINTGEOM_dttemp p2; | ||
|
|
||
| CREATE VIEW TestGeospatialMethods_disjointTemp AS SELECT p1.location.STDisjoint(p2.location) AS isIN FROM TestGeospatialMethods_SPATIALPOINTGEOM_dttemp p1 CROSS JOIN TestGeospatialMethods_SPATIALPOINTGEOM_dttemp p2 ORDER BY p1.location.STX; | ||
|
|
||
| CREATE VIEW TestGeospatialMethods_ValFromGeomTemp AS SELECT location.STDimension() FROM TestGeospatialMethods_SPATIALPOINTGEOM_dttemp ORDER BY location.STX; | ||
|
|
||
| CREATE VIEW TestGeospatialMethods_TextFromGeogTemp AS SELECT location.STDimension() AS Dimension FROM TestGeospatialMethods_SPATIALPOINTGEOG_dttemp ORDER BY location.Lat; | ||
|
|
||
| CREATE VIEW TestGeospatialMethods_point_intersectTemp AS SELECT p1.location.STIntersects(p2.location) AS Intersection FROM TestGeospatialMethods_SPATIALPOINTGEOG_dttemp p1 CROSS JOIN TestGeospatialMethods_SPATIALPOINTGEOG_dttemp p2 ORDER BY p1.location.Lat; | ||
|
|
||
| CREATE VIEW TestGeospatialMethods_point_disjointTemp AS SELECT p1.location.STDisjoint(p2.location) AS disjoint FROM TestGeospatialMethods_SPATIALPOINTGEOG_dttemp p1 CROSS JOIN TestGeospatialMethods_SPATIALPOINTGEOG_dttemp p2 ORDER BY p1.location.Lat; | ||
|
|
||
| CREATE VIEW TestGeospatialMethods_valid_ValFromGeomTemp AS SELECT location.STIsValid() FROM TestGeospatialMethods_SPATIALPOINTGEOM_dttemp ORDER BY location.STX; | ||
|
|
||
| CREATE VIEW TestGeospatialMethods_valid_TextFromGeogTemp AS SELECT location.STIsValid() AS Dimension FROM TestGeospatialMethods_SPATIALPOINTGEOG_dttemp ORDER BY location.Lat; | ||
|
|
||
| CREATE VIEW TestGeospatialMethods_closed_ValFromGeomTemp AS SELECT location.STIsClosed() FROM TestGeospatialMethods_SPATIALPOINTGEOM_dttemp ORDER BY location.STX; | ||
|
|
||
| CREATE VIEW TestGeospatialMethods_closed_TextFromGeogTemp AS SELECT location.STIsClosed() AS Dimension FROM TestGeospatialMethods_SPATIALPOINTGEOG_dttemp ORDER BY location.Lat; | ||
|
|
||
| CREATE VIEW TestGeospatialMethods_empty_ValFromGeomTemp AS SELECT location.STIsEmpty() FROM TestGeospatialMethods_SPATIALPOINTGEOM_dttemp ORDER BY location.STX; | ||
|
|
||
| CREATE VIEW TestGeospatialMethods_empty_TextFromGeomTemp AS SELECT location.STIsEmpty() AS Dimension FROM TestGeospatialMethods_SPATIALPOINTGEOG_dttemp ORDER BY location.Lat; |
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