diff --git a/contrib/babelfishpg_common/sql/geography.sql b/contrib/babelfishpg_common/sql/geography.sql index f4ab4fbada..6ca2937892 100644 --- a/contrib/babelfishpg_common/sql/geography.sql +++ b/contrib/babelfishpg_common/sql/geography.sql @@ -443,18 +443,53 @@ CREATE OR REPLACE FUNCTION sys.ST_zmflag(sys.GEOGRAPHY) AS '$libdir/postgis-3', 'LWGEOM_zmflag' LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE; -CREATE FUNCTION sys.ST_Equals(leftarg sys.GEOGRAPHY, rightarg sys.GEOGRAPHY) - RETURNS boolean - AS $$ - DECLARE - leftvarBin sys.bbf_varbinary; - rightvarBin sys.bbf_varbinary; - BEGIN - leftvarBin := (SELECT sys.bbf_varbinary($1)); - rightvarBin := (SELECT sys.bbf_varbinary($2)); - RETURN (SELECT sys.varbinary_eq(leftvarBin, rightvarBin)); - END; - $$ LANGUAGE plpgsql IMMUTABLE STRICT PARALLEL SAFE; +CREATE OR REPLACE FUNCTION sys.STArea(sys.GEOGRAPHY) + RETURNS float8 + AS '$libdir/postgis-3','ST_Area' + LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE; + +CREATE OR REPLACE FUNCTION sys.STSrid(sys.GEOGRAPHY) + RETURNS integer + AS '$libdir/postgis-3','LWGEOM_get_srid' + LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE; + +CREATE OR REPLACE FUNCTION sys.STEquals(geom1 sys.GEOGRAPHY, geom2 sys.GEOGRAPHY) + RETURNS sys.BIT + AS $$ + BEGIN + IF STSrid(geom1) != STSrid(geom2) THEN + RETURN NULL; + ELSE + Return sys.STEquals_helper($1,$2); + END IF; + END; + $$ LANGUAGE plpgsql IMMUTABLE STRICT PARALLEL SAFE; + +CREATE OR REPLACE FUNCTION sys.STContains(geom1 sys.GEOGRAPHY, geom2 sys.GEOGRAPHY) + RETURNS sys.BIT + AS $$ + BEGIN + IF STSrid(geom1) != STSrid(geom2) THEN + RETURN NULL; + ELSE + Return sys.STContains_helper($1,$2); + END IF; + END; + $$ LANGUAGE plpgsql IMMUTABLE STRICT PARALLEL SAFE; + +CREATE OR REPLACE FUNCTION sys.ST_Equals(leftarg sys.GEOGRAPHY, rightarg sys.GEOGRAPHY) + RETURNS boolean + AS $$ + DECLARE + Result integer; + BEGIN + Result := STEquals(leftarg,rightarg); + IF Result IS NULL THEN + RETURN false; + END IF; + RETURN Result; + END; + $$ LANGUAGE plpgsql IMMUTABLE STRICT PARALLEL SAFE; CREATE OPERATOR sys.= ( LEFTARG = sys.GEOGRAPHY, @@ -464,18 +499,19 @@ CREATE OPERATOR sys.= ( RESTRICT = eqsel ); -CREATE FUNCTION sys.ST_NotEquals(leftarg sys.GEOGRAPHY, rightarg sys.GEOGRAPHY) +CREATE OR REPLACE FUNCTION sys.ST_NotEquals(leftarg sys.GEOGRAPHY, rightarg sys.GEOGRAPHY) RETURNS boolean AS $$ - DECLARE - leftvarBin sys.bbf_varbinary; - rightvarBin sys.bbf_varbinary; - BEGIN - leftvarBin := (SELECT sys.bbf_varbinary($1)); - rightvarBin := (SELECT sys.bbf_varbinary($2)); - RETURN (SELECT sys.varbinary_neq(leftvarBin, rightvarBin)); - END; - $$ LANGUAGE plpgsql IMMUTABLE STRICT PARALLEL SAFE; + DECLARE + Result integer; + BEGIN + Result := STEquals(leftarg,rightarg); + IF Result IS NULL THEN + RETURN true; + END IF; + RETURN 1 - Result; + END; + $$ LANGUAGE plpgsql IMMUTABLE STRICT PARALLEL SAFE; CREATE OPERATOR sys.<> ( LEFTARG = sys.GEOGRAPHY, @@ -512,6 +548,16 @@ CREATE OR REPLACE FUNCTION sys.ST_Transform(sys.GEOGRAPHY, integer) LANGUAGE 'c' IMMUTABLE STRICT; -- Helper functions for main T-SQL functions +CREATE OR REPLACE FUNCTION sys.STEquals_helper(geom1 sys.GEOGRAPHY, geom2 sys.GEOGRAPHY) + RETURNS sys.BIT + AS '$libdir/postgis-3','ST_Equals' + LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE; + +CREATE OR REPLACE FUNCTION sys.STContains_helper(geom1 sys.GEOGRAPHY, geom2 sys.GEOGRAPHY) + RETURNS sys.BIT + AS '$libdir/postgis-3','within' + LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE; + CREATE OR REPLACE FUNCTION sys.stgeogfromtext_helper(text, integer) RETURNS sys.GEOGRAPHY AS '$libdir/postgis-3','LWGEOM_from_text' diff --git a/contrib/babelfishpg_common/sql/geometry.sql b/contrib/babelfishpg_common/sql/geometry.sql index 251668cfac..47a8bfa945 100644 --- a/contrib/babelfishpg_common/sql/geometry.sql +++ b/contrib/babelfishpg_common/sql/geometry.sql @@ -338,18 +338,53 @@ CREATE OR REPLACE FUNCTION sys.ST_zmflag(sys.GEOMETRY) AS '$libdir/postgis-3', 'LWGEOM_zmflag' LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE; -CREATE FUNCTION sys.ST_Equals(leftarg sys.GEOMETRY, rightarg sys.GEOMETRY) +CREATE OR REPLACE FUNCTION sys.STArea(sys.GEOMETRY) + RETURNS float8 + AS '$libdir/postgis-3','ST_Area' + LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE; + +CREATE OR REPLACE FUNCTION sys.STSrid(sys.GEOMETRY) + RETURNS integer + AS '$libdir/postgis-3','LWGEOM_get_srid' + LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE; + +CREATE OR REPLACE FUNCTION sys.STEquals(geom1 sys.GEOMETRY, geom2 sys.GEOMETRY) + RETURNS sys.BIT + AS $$ + BEGIN + IF STSrid(geom1) != STSrid(geom2) THEN + RETURN NULL; + ELSE + Return sys.STEquals_helper($1,$2); + END IF; + END; + $$ LANGUAGE plpgsql IMMUTABLE STRICT PARALLEL SAFE; + +CREATE OR REPLACE FUNCTION sys.STContains(geom1 sys.GEOMETRY, geom2 sys.GEOMETRY) + RETURNS sys.BIT + AS $$ + BEGIN + IF STSrid(geom1) != STSrid(geom2) THEN + RETURN NULL; + ELSE + Return sys.STContains_helper($1,$2); + END IF; + END; + $$ LANGUAGE plpgsql IMMUTABLE STRICT PARALLEL SAFE; + +CREATE OR REPLACE FUNCTION sys.ST_Equals(leftarg sys.GEOMETRY, rightarg sys.GEOMETRY) RETURNS boolean - AS $$ - DECLARE - leftvarBin sys.bbf_varbinary; - rightvarBin sys.bbf_varbinary; - BEGIN - leftvarBin := (SELECT sys.bbf_varbinary($1)); - rightvarBin := (SELECT sys.bbf_varbinary($2)); - RETURN (SELECT sys.varbinary_eq(leftvarBin, rightvarBin)); - END; - $$ LANGUAGE plpgsql IMMUTABLE STRICT PARALLEL SAFE; + AS $$ + DECLARE + Result integer; + BEGIN + Result := STEquals(leftarg,rightarg); + IF Result IS NULL THEN + RETURN false; + END IF; + RETURN Result; + END; + $$ LANGUAGE plpgsql IMMUTABLE STRICT PARALLEL SAFE; CREATE OPERATOR sys.= ( LEFTARG = sys.GEOMETRY, @@ -359,18 +394,19 @@ CREATE OPERATOR sys.= ( RESTRICT = eqsel ); -CREATE FUNCTION sys.ST_NotEquals(leftarg sys.GEOMETRY, rightarg sys.GEOMETRY) +CREATE OR REPLACE FUNCTION sys.ST_NotEquals(leftarg sys.GEOMETRY, rightarg sys.GEOMETRY) RETURNS boolean AS $$ - DECLARE - leftvarBin sys.bbf_varbinary; - rightvarBin sys.bbf_varbinary; - BEGIN - leftvarBin := (SELECT sys.bbf_varbinary($1)); - rightvarBin := (SELECT sys.bbf_varbinary($2)); - RETURN (SELECT sys.varbinary_neq(leftvarBin, rightvarBin)); - END; - $$ LANGUAGE plpgsql IMMUTABLE STRICT PARALLEL SAFE; + DECLARE + Result integer; + BEGIN + Result := STEquals(leftarg,rightarg); + IF Result IS NULL THEN + RETURN true; + END IF; + RETURN 1 - Result; + END; + $$ LANGUAGE plpgsql IMMUTABLE STRICT PARALLEL SAFE; CREATE OPERATOR sys.<> ( LEFTARG = sys.GEOMETRY, @@ -396,6 +432,16 @@ CREATE OR REPLACE FUNCTION sys.sty(sys.GEOMETRY) LANGUAGE 'c' IMMUTABLE STRICT; -- Helper functions for main T-SQL functions +CREATE OR REPLACE FUNCTION sys.STContains_helper(geom1 sys.GEOMETRY, geom2 sys.GEOMETRY) + RETURNS sys.BIT + AS '$libdir/postgis-3','within' + LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE; + +CREATE OR REPLACE FUNCTION sys.STEquals_helper(geom1 sys.GEOMETRY, geom2 sys.GEOMETRY) + RETURNS sys.BIT + AS '$libdir/postgis-3','ST_Equals' + LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE; + CREATE OR REPLACE FUNCTION sys.stgeomfromtext_helper(text, integer) RETURNS sys.GEOMETRY AS '$libdir/postgis-3','LWGEOM_from_text' diff --git a/contrib/babelfishpg_common/sql/upgrades/spatial_types--4.2.0--4.3.0.sql b/contrib/babelfishpg_common/sql/upgrades/spatial_types--4.2.0--4.3.0.sql index 4a18af015f..22e59fba54 100644 --- a/contrib/babelfishpg_common/sql/upgrades/spatial_types--4.2.0--4.3.0.sql +++ b/contrib/babelfishpg_common/sql/upgrades/spatial_types--4.2.0--4.3.0.sql @@ -1,3 +1,147 @@ ------------------------------------------------------- ---- Include changes related to spatial types here ---- ------------------------------------------------------- +CREATE OR REPLACE FUNCTION sys.STArea(sys.GEOMETRY) + RETURNS float8 + AS '$libdir/postgis-3','ST_Area' + LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE; + +CREATE OR REPLACE FUNCTION sys.STSrid(sys.GEOMETRY) + RETURNS integer + AS '$libdir/postgis-3','LWGEOM_get_srid' + LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE; + +CREATE OR REPLACE FUNCTION sys.STEquals(geom1 sys.GEOMETRY, geom2 sys.GEOMETRY) + RETURNS sys.BIT + AS $$ + BEGIN + IF STSrid(geom1) != STSrid(geom2) THEN + RETURN NULL; + ELSE + Return sys.STEquals_helper($1,$2); + END IF; + END; + $$ LANGUAGE plpgsql IMMUTABLE STRICT PARALLEL SAFE; + +CREATE OR REPLACE FUNCTION sys.STContains(geom1 sys.GEOMETRY, geom2 sys.GEOMETRY) + RETURNS sys.BIT + AS $$ + DECLARE + BEGIN + IF STSrid(geom1) != STSrid(geom2) THEN + RETURN NULL; + ELSE + Return sys.STContains_helper($1,$2); + END IF; + END; + $$ LANGUAGE plpgsql IMMUTABLE STRICT PARALLEL SAFE; + +CREATE OR REPLACE FUNCTION sys.ST_Equals(leftarg sys.GEOMETRY, rightarg sys.GEOMETRY) + RETURNS boolean + AS $$ + DECLARE + Result integer; + BEGIN + Result := STEquals(leftarg,rightarg); + IF Result IS NULL THEN + RETURN false; + END IF; + RETURN Result; + END; + $$ LANGUAGE plpgsql IMMUTABLE STRICT PARALLEL SAFE; + +CREATE OR REPLACE FUNCTION sys.ST_NotEquals(leftarg sys.GEOMETRY, rightarg sys.GEOMETRY) + RETURNS boolean + AS $$ + DECLARE + Result integer; + BEGIN + Result := STEquals(leftarg,rightarg); + IF Result IS NULL THEN + RETURN true; + END IF; + RETURN 1 - Result; + END; + $$ LANGUAGE plpgsql IMMUTABLE STRICT PARALLEL SAFE; + +CREATE OR REPLACE FUNCTION sys.STContains_helper(geom1 sys.GEOMETRY, geom2 sys.GEOMETRY) + RETURNS sys.BIT + AS '$libdir/postgis-3','within' + LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE; + +CREATE OR REPLACE FUNCTION sys.STEquals_helper(geom1 sys.GEOMETRY, geom2 sys.GEOMETRY) + RETURNS sys.BIT + AS '$libdir/postgis-3','ST_Equals' + LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE; + +CREATE OR REPLACE FUNCTION sys.STArea(sys.GEOGRAPHY) + RETURNS float8 + AS '$libdir/postgis-3','ST_Area' + LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE; + +CREATE OR REPLACE FUNCTION sys.STSrid(sys.GEOGRAPHY) + RETURNS integer + AS '$libdir/postgis-3','LWGEOM_get_srid' + LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE; + +CREATE OR REPLACE FUNCTION sys.STEquals(geom1 sys.GEOGRAPHY, geom2 sys.GEOGRAPHY) + RETURNS sys.BIT + AS $$ + BEGIN + IF STSrid(geom1) != STSrid(geom2) THEN + RETURN NULL; + ELSE + Return sys.STEquals_helper($1,$2); + END IF; + END; + $$ LANGUAGE plpgsql IMMUTABLE STRICT PARALLEL SAFE; + +CREATE OR REPLACE FUNCTION sys.STContains(geom1 sys.GEOGRAPHY, geom2 sys.GEOGRAPHY) + RETURNS sys.BIT + AS $$ + BEGIN + IF STSrid(geom1) != STSrid(geom2) THEN + RETURN NULL; + ELSE + Return sys.STContains_helper($1,$2); + END IF; + END; + $$ LANGUAGE plpgsql IMMUTABLE STRICT PARALLEL SAFE; + +CREATE OR REPLACE FUNCTION sys.ST_Equals(leftarg sys.GEOGRAPHY, rightarg sys.GEOGRAPHY) + RETURNS boolean + AS $$ + DECLARE + Result integer; + BEGIN + Result := STEquals(leftarg,rightarg); + IF Result IS NULL THEN + RETURN false; + END IF; + RETURN Result; + END; + $$ LANGUAGE plpgsql IMMUTABLE STRICT PARALLEL SAFE; + +CREATE OR REPLACE FUNCTION sys.ST_NotEquals(leftarg sys.GEOGRAPHY, rightarg sys.GEOGRAPHY) + RETURNS boolean + AS $$ + DECLARE + Result integer; + BEGIN + Result := STEquals(leftarg,rightarg); + IF Result IS NULL THEN + RETURN true; + END IF; + RETURN 1 - Result; + END; + $$ LANGUAGE plpgsql IMMUTABLE STRICT PARALLEL SAFE; + +CREATE OR REPLACE FUNCTION sys.STEquals_helper(geom1 sys.GEOGRAPHY, geom2 sys.GEOGRAPHY) + RETURNS sys.BIT + AS '$libdir/postgis-3','ST_Equals' + LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE; + +CREATE OR REPLACE FUNCTION sys.STContains_helper(geom1 sys.GEOGRAPHY, geom2 sys.GEOGRAPHY) + RETURNS sys.BIT + AS '$libdir/postgis-3','within' + LANGUAGE 'c' IMMUTABLE STRICT PARALLEL SAFE; diff --git a/contrib/babelfishpg_tsql/antlr/TSqlLexer.g4 b/contrib/babelfishpg_tsql/antlr/TSqlLexer.g4 index 39e824b7cc..3d5554cea6 100644 --- a/contrib/babelfishpg_tsql/antlr/TSqlLexer.g4 +++ b/contrib/babelfishpg_tsql/antlr/TSqlLexer.g4 @@ -945,6 +945,7 @@ STALE_CAPTURE_POLICY_THRESHOLD: S T A L E UNDERLINE C A P T U STALE_QUERY_THRESHOLD_DAYS: S T A L E UNDERLINE Q U E R Y UNDERLINE T H R E S H O L D UNDERLINE D A Y S; STANDBY: S T A N D B Y; START: S T A R T; +STAREA: 'STArea'; STARTED: S T A R T E D; STARTUP_STATE: S T A R T U P UNDERLINE S T A T E; START_DATE: S T A R T UNDERLINE D A T E; @@ -959,9 +960,11 @@ STATS: S T A T S; STATS_STREAM: S T A T S UNDERLINE S T R E A M; STATUS: S T A T U S; STATUSONLY: S T A T U S O N L Y; +STCONTAINS: 'STContains'; STDEV: S T D E V; STDEVP: S T D E V P; STDISTANCE: 'STDistance'; +STEQUALS: 'STEquals'; STOP: S T O P; STOPAT: S T O P A T; STOPATMARK: S T O P A T M A R K; @@ -971,6 +974,9 @@ STOPPED: S T O P P E D; STOP_ON_ERROR: S T O P UNDERLINE O N UNDERLINE E R R O R; STRING_AGG: S T R I N G UNDERLINE A G G; STRING_DELIMITER: S T R I N G UNDERLINE D E L I M I T E R; +STSRID: 'STSrid'; +STSRID_DOUBLE_QUOTE: ["] STSRID ["] {pltsql_quoted_identifier == true}?; +STSRID_SQBRACKET: '[' STSRID ']'; STUFF: S T U F F; STX: 'STX'; STX_DOUBLE_QUOTE: ["] STX ["] {pltsql_quoted_identifier == true}?; diff --git a/contrib/babelfishpg_tsql/antlr/TSqlParser.g4 b/contrib/babelfishpg_tsql/antlr/TSqlParser.g4 index a0e9d94078..2285306061 100644 --- a/contrib/babelfishpg_tsql/antlr/TSqlParser.g4 +++ b/contrib/babelfishpg_tsql/antlr/TSqlParser.g4 @@ -3897,7 +3897,10 @@ spatial_methods ; geospatial_col - : STX + : STSRID + | STSRID_DOUBLE_QUOTE + | STSRID_SQBRACKET + | STX | STX_SQBRACKET | STX_DOUBLE_QUOTE | STY @@ -3914,10 +3917,13 @@ geospatial_col geospatial_func_no_arg : STASTEXT | STASBINARY + | STAREA ; geospatial_func_arg : STDISTANCE + | STEQUALS + | STCONTAINS ; hierarchyid_methods @@ -5020,6 +5026,7 @@ keyword | STALE_QUERY_THRESHOLD_DAYS | STANDBY | START + | STAREA | STARTED | STARTUP_STATE | START_DATE @@ -5033,9 +5040,11 @@ keyword | STATS_STREAM | STATUS | STATUSONLY + | STCONTAINS | STDEV | STDEVP | STDISTANCE + | STEQUALS | STOP | STOPAT | STOPATMARK @@ -5045,6 +5054,9 @@ keyword | STOP_ON_ERROR | STRING_AGG | STRING_DELIMITER + | STSRID + | STSRID_DOUBLE_QUOTE + | STSRID_SQBRACKET | STUFF | STX | STX_DOUBLE_QUOTE diff --git a/test/JDBC/expected/Test-spatial-functions-vu-cleanup.out b/test/JDBC/expected/Test-spatial-functions-vu-cleanup.out new file mode 100644 index 0000000000..458cca9199 --- /dev/null +++ b/test/JDBC/expected/Test-spatial-functions-vu-cleanup.out @@ -0,0 +1,35 @@ +USE TestSpatialFunction_DB + +DROP TABLE IF EXISTS TestSpatialFunction_YourTable1Temp + +USE MASTER + +DROP TABLE IF EXISTS TestSpatialFunction_YourTableTemp2 + +DROP TABLE IF EXISTS TestSpatialFunction_TableATemp + +DROP TABLE IF EXISTS TestSpatialFunction_TableBTemp + +DROP VIEW IF EXISTS TestSpatialFunction_ValFromGeomTemp + +DROP VIEW IF EXISTS TestSpatialFunction_TextFromGeogTemp + +DROP VIEW IF EXISTS TestSpatialFunction_point_equality1Temp + +DROP VIEW IF EXISTS TestSpatialFunction_isInTemp + +DROP VIEW IF EXISTS TestSpatialFunction_point_EqualityTemp + +DROP VIEW IF EXISTS TestSpatialFunction_point_inTemp + +DROP VIEW IF EXISTS TestSpatialFunction_SRIDFromGeom + +DROP VIEW IF EXISTS TestSpatialFunction_SRIDFromGeog + +DROP TABLE IF EXISTS TestSpatialFunction_SPATIALPOINTGEOM_dttemp + +DROP TABLE IF EXISTS TestSpatialFunction_SPATIALPOINTGEOG_dttemp + +DROP TABLE IF EXISTS TestSpatialFunction_YourTableTemp + +DROP DATABASE TestSpatialFunction_DB diff --git a/test/JDBC/expected/Test-spatial-functions-vu-prepare.out b/test/JDBC/expected/Test-spatial-functions-vu-prepare.out new file mode 100644 index 0000000000..ccc9d44658 --- /dev/null +++ b/test/JDBC/expected/Test-spatial-functions-vu-prepare.out @@ -0,0 +1,114 @@ +CREATE DATABASE TestSpatialFunction_DB; + +USE TestSpatialFunction_DB; + +CREATE TABLE TestSpatialFunction_YourTable1Temp ( ID INT PRIMARY KEY, PointColumn geometry ); +INSERT INTO TestSpatialFunction_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)); +~~ROW COUNT: 3~~ + + +USE MASTER + +CREATE TABLE TestSpatialFunction_YourTableTemp ( ID INT PRIMARY KEY, PointColumn geometry ); + +INSERT INTO TestSpatialFunction_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 TestSpatialFunction_YourTableTemp2 ( ID INT PRIMARY KEY, PointColumn1 geometry, PointColumn2 geometry ); +INSERT INTO TestSpatialFunction_YourTableTemp2 (ID, PointColumn1, PointColumn2) VALUES (1, geometry::Point(3.0, 4.0, 4326), geometry::Point(3.0, 4.0, 4326)); +~~ROW COUNT: 1~~ + + +CREATE TABLE TestSpatialFunction_TableATemp (ID INT PRIMARY KEY, PointA geometry); +CREATE TABLE TestSpatialFunction_TableBTemp (ID INT PRIMARY KEY, PointB geometry); +INSERT INTO TestSpatialFunction_TableATemp (ID, PointA) VALUES (1, geometry::Point(1.0, 2.0, 4326)); +~~ROW COUNT: 1~~ + +INSERT INTO TestSpatialFunction_TableBTemp (ID, PointB) VALUES (1, geometry::Point(3.0, 4.0, 4326)); +~~ROW COUNT: 1~~ + + +CREATE TABLE TestSpatialFunction_SPATIALPOINTGEOG_dttemp (location geography); +INSERT INTO TestSpatialFunction_SPATIALPOINTGEOG_dttemp (location) VALUES ( geography::STGeomFromText('Point(47.65100 -22.34900)', 4326) ); +~~ROW COUNT: 1~~ + +INSERT INTO TestSpatialFunction_SPATIALPOINTGEOG_dttemp (location) VALUES ( geography::STGeomFromText('Point(1.0 2.0)', 4326) ); +~~ROW COUNT: 1~~ + +INSERT INTO TestSpatialFunction_SPATIALPOINTGEOG_dttemp (location) VALUES ( geography::STGeomFromText('Point(1.0 2.0)', 4326) ); +~~ROW COUNT: 1~~ + +INSERT INTO TestSpatialFunction_SPATIALPOINTGEOG_dttemp (location) VALUES ( geography::STPointFromText('Point(1.0 2.0)', 4326) ); +~~ROW COUNT: 1~~ + + +#Tests for Geography type Prepared Statements +prepst#!#INSERT INTO TestSpatialFunction_SPATIALPOINTGEOG_dttemp(location) values(?) #!#GEOGRAPHY|-|location|-|Point(47.65100 -22.34900):4326 +~~ROW COUNT: 1~~ + +prepst#!#exec#!#GEOGRAPHY|-|location|-|Point(1.0 2.0):4326 +~~ROW COUNT: 1~~ + +prepst#!#exec#!#GEOGRAPHY|-|location|-|Point(-91.0 -35.0):4326 +~~ROW COUNT: 1~~ + +prepst#!#exec#!#GEOGRAPHY|-|location|-|Point(290.345 45.1234):4326 +~~ROW COUNT: 1~~ + +prepst#!#exec#!#GEOGRAPHY|-|location|-|Point(-120.345 45.1234):4326 +~~ROW COUNT: 1~~ + +prepst#!#exec#!#GEOGRAPHY|-|location|-|Point(-720.345 45.1234):4326 +~~ROW COUNT: 1~~ + + +CREATE TABLE TestSpatialFunction_SPATIALPOINTGEOM_dttemp (location geometry); +INSERT INTO TestSpatialFunction_SPATIALPOINTGEOM_dttemp (location) VALUES ( geometry::STGeomFromText('Point(47.65100 -22.34900)', 4326) ); +~~ROW COUNT: 1~~ + +INSERT INTO TestSpatialFunction_SPATIALPOINTGEOM_dttemp (location) VALUES ( geometry::STGeomFromText('Point(1.0 2.0)', 4326) ); +~~ROW COUNT: 1~~ + +INSERT INTO TestSpatialFunction_SPATIALPOINTGEOM_dttemp (location) VALUES ( geometry::STGeomFromText('Point(47.65100 -22.34900)', 0) ); +~~ROW COUNT: 1~~ + +INSERT INTO TestSpatialFunction_SPATIALPOINTGEOM_dttemp (location) VALUES ( geometry::STPointFromText('Point(1.0 2.0)', 4326) ); +~~ROW COUNT: 1~~ + +INSERT INTO TestSpatialFunction_SPATIALPOINTGEOM_dttemp (location) VALUES ( geometry::Point(47.65100, -22.34900, 4326) ); +~~ROW COUNT: 1~~ + + +#Tests for Geometry type Prepared Statements +prepst#!#INSERT INTO TestSpatialFunction_SPATIALPOINTGEOM_dttemp(location) values(?) #!#GEOMETRY|-|location|-|Point(47.65100 -22.34900):4326 +~~ROW COUNT: 1~~ + +prepst#!#exec#!#GEOMETRY|-|location|-|Point(1.0 2.0):4326 +~~ROW COUNT: 1~~ + +prepst#!#exec#!#GEOMETRY|-|location|-|Point(47.65100 -22.34900):0 +~~ROW COUNT: 1~~ + +prepst#!#exec#!#GEOMETRY|-|location|-|Point(-91.0 -35.0):4326 +~~ROW COUNT: 1~~ + +prepst#!#exec#!#GEOMETRY|-|location|-|Point(290.345 45.1234):4326 +~~ROW COUNT: 1~~ + + +CREATE VIEW TestSpatialFunction_point_equality1Temp AS SELECT p1.location.STEquals(p2.location) AS equality FROM TestSpatialFunction_SPATIALPOINTGEOM_dttemp p1 CROSS JOIN TestSpatialFunction_SPATIALPOINTGEOM_dttemp p2; + +CREATE VIEW TestSpatialFunction_isInTemp AS SELECT p1.location.STContains(p2.location) AS isIN FROM TestSpatialFunction_SPATIALPOINTGEOM_dttemp p1 CROSS JOIN TestSpatialFunction_SPATIALPOINTGEOM_dttemp p2 ORDER BY p1.location.STX; + +CREATE VIEW TestSpatialFunction_ValFromGeomTemp AS SELECT location.STArea() FROM TestSpatialFunction_SPATIALPOINTGEOM_dttemp ORDER BY location.STX; + +CREATE VIEW TestSpatialFunction_TextFromGeogTemp AS SELECT location.STArea() AS Area FROM TestSpatialFunction_SPATIALPOINTGEOG_dttemp ORDER BY location.Lat; + +CREATE VIEW TestSpatialFunction_point_EqualityTemp AS SELECT p1.location.STEquals(p2.location) AS Equality FROM TestSpatialFunction_SPATIALPOINTGEOG_dttemp p1 CROSS JOIN TestSpatialFunction_SPATIALPOINTGEOG_dttemp p2 ORDER BY p1.location.Lat; + +CREATE VIEW TestSpatialFunction_point_inTemp AS SELECT p1.location.STContains(p2.location) AS isIn FROM TestSpatialFunction_SPATIALPOINTGEOG_dttemp p1 CROSS JOIN TestSpatialFunction_SPATIALPOINTGEOG_dttemp p2; + +CREATE VIEW TestSpatialFunction_SRIDFromGeom AS SELECT PointColumn.STSrid AS SRID FROM TestSpatialFunction_YourTableTemp; + +CREATE VIEW TestSpatialFunction_SRIDFromGeog AS SELECT location.STSrid AS Area FROM TestSpatialFunction_SPATIALPOINTGEOG_dttemp ORDER BY location.Lat; diff --git a/test/JDBC/expected/Test-spatial-functions-vu-verify.out b/test/JDBC/expected/Test-spatial-functions-vu-verify.out new file mode 100644 index 0000000000..3bb3e11e8e --- /dev/null +++ b/test/JDBC/expected/Test-spatial-functions-vu-verify.out @@ -0,0 +1,1419 @@ +DECLARE @point1 geometry, @point2 geometry; +SET @point1 = geometry::STPointFromText('POINT(-122.354657658684900 47.658678768678100)', 4326); +SET @point2 = geometry::STPointFromText('POINT(-122.354657658684900 47.658678768678100)', 4326); +SELECT @point1.STEquals(@point2) AS Equal; +go +~~START~~ +bit +1 +~~END~~ + + +DECLARE @point1 geography, @point2 geography; +SET @point1 = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); +SET @point2 = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); +SELECT @point1.STEquals(@point2) AS Equal; +go +~~START~~ +bit +1 +~~END~~ + + +DECLARE @point1 geography, @point2 geography; +SET @point1 = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); +SET @point2 = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); +SELECT @point1.STContains(@point2) AS isIN; +go +~~START~~ +bit +1 +~~END~~ + + +DECLARE @point1 geometry, @point2 geometry; +SET @point1 = geometry::STPointFromText('POINT(-122.354657658684900 47.658678768678100)', 4326); +SET @point2 = geometry::STPointFromText('POINT(-122.354657658684900 47.658678768678100)', 0); +SELECT @point1.STEquals(@point2) AS Equal; +go +~~START~~ +bit + +~~END~~ + + +DECLARE @point1 geography, @point2 geography; +SET @point1 = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); +SET @point2 = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); +SELECT @point1 . STEquals(@point2) AS Equal; +go +~~START~~ +bit +1 +~~END~~ + + +DECLARE @point1 geography, @point2 geography; +SET @point1 = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); +SET @point2 = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); +SELECT @point1 . STContains(@point2) AS isIN; +go +~~START~~ +bit +1 +~~END~~ + + +DECLARE @point1 geography; +SET @point1 = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); +SELECT @point1.STSrid; +Go +~~START~~ +int +4326 +~~END~~ + + +-- Verifying with precision +DECLARE @point1 geometry, @point2 geometry; +SET @point1 = geometry::STPointFromText('POINT(-122.354657658684900 47.658678768678100)', 4326); +SET @point2 = geometry::STPointFromText('POINT(-122.354657658684900 47.658678768678100)', 4326); +SELECT STEquals(@point1, @point2); +go +~~START~~ +bit +1 +~~END~~ + + +DECLARE @point1 geography, @point2 geography; +SET @point1 = geography::STGeomFromText('POINT(-122.354657658684900 47.658678768678100)', 4326); +SET @point2 = geography::STGeomFromText('POINT(-122.354657658684900 47.658678768678100)', 4326); +SELECT @point1.STEquals(@point2) AS Equal; +go +~~START~~ +bit +1 +~~END~~ + + +DECLARE @point1 geometry, @point2 geometry; +SET @point1 = geometry::STPointFromText('POINT(-122.354657658684900 47.658678768678100)', 4326); +SET @point2 = geometry::STPointFromText('POINT(-122.354657658684000 47.658678768678100)', 4326); +SELECT STEquals(@point1, @point2); +go +~~START~~ +bit +0 +~~END~~ + + +DECLARE @point1 geometry, @point2 geometry; +SET @point1 = geometry::STPointFromText('POINT(-122.354657658684900 47.658678768678100)', 4326); +SET @point2 = geometry::STPointFromText('POINT(-122.354657658684900 47.658678768678100)', 4326); +SELECT @point1 . STEquals ( @point2 ); +go +~~START~~ +bit +1 +~~END~~ + + +SELECT PointColumn1.STEquals(PointColumn2) AS Equals FROM TestSpatialFunction_YourTableTemp2 ORDER BY PointColumn1.STX; +go +~~START~~ +bit +1 +~~END~~ + + +DECLARE @point1 geometry = geometry::Point(1.0, 2.0, 4326); +SELECT PointColumn1.STEquals(@point1) AS Equals FROM TestSpatialFunction_YourTableTemp2 ORDER BY PointColumn1.STX; +go +~~START~~ +bit +0 +~~END~~ + + +DECLARE @point1 geometry = geometry::Point(1.0, 2.0, 4326); +SELECT @point1.STEquals(PointColumn2) AS Equals FROM TestSpatialFunction_YourTableTemp2 ORDER BY PointColumn1.STX; +go +~~START~~ +bit +0 +~~END~~ + + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +DECLARE @isEqual BIT = 0; +SELECT PointColumn.STSrid FROM TestSpatialFunction_YourTableTemp WHERE PointColumn.STEquals(@referencePoint) = @isEqual ORDER BY PointColumn.STSrid; +go +~~START~~ +int +4326 +4326 +~~END~~ + + +SELECT ID, PointColumn1.STEquals(PointColumn2) AS Equal_points FROM TestSpatialFunction_YourTableTemp2 ORDER BY PointColumn1.STX; +go +~~START~~ +int#!#bit +1#!#1 +~~END~~ + + +SELECT PointA.STAsText(),PointB.STAsText() FROM TestSpatialFunction_TableATemp JOIN TestSpatialFunction_TableBTemp ON PointA.STEquals(TestSpatialFunction_TableBTemp.PointB) != 1 ORDER BY PointA.STX; +go +~~START~~ +text#!#text +POINT(1 2)#!#POINT(3 4) +~~END~~ + + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +SELECT PointA.STAsText(),PointB.STAsText() FROM TestSpatialFunction_TableATemp JOIN TestSpatialFunction_TableBTemp ON @referencePoint.STEquals(TestSpatialFunction_TableBTemp.PointB) = 1 ORDER BY PointA.STX; +go +~~START~~ +text#!#text +~~END~~ + + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +SELECT PointA.STAsText(),PointB.STAsText() FROM TestSpatialFunction_TableATemp JOIN TestSpatialFunction_TableBTemp ON PointA.STEquals(@referencePoint) != 1 ORDER BY PointA.STX; +go +~~START~~ +text#!#text +POINT(1 2)#!#POINT(3 4) +~~END~~ + + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +SELECT PointColumn.STSrid FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STSrid; +go +~~START~~ +int +0 +4326 +4326 +~~END~~ + + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +SELECT PointColumn.STSrid FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STSrid; +go +~~START~~ +int +0 +4326 +4326 +~~END~~ + + +SELECT PointColumn1.STAsText() FROM TestSpatialFunction_YourTableTemp2 ORDER BY PointColumn1.STX; +go +~~START~~ +text +POINT(3 4) +~~END~~ + + +DECLARE @isEqual BIT = 1; +SELECT ID, PointColumn1.STEquals(PointColumn2) AS isEqual, +CASE WHEN PointColumn1.STEquals(PointColumn2) = @isEqual THEN 'yes' ELSE 'no' +END AS isEqual +FROM TestSpatialFunction_YourTableTemp2 ORDER BY PointColumn1.STX; +go +~~START~~ +int#!#bit#!#text +1#!#1#!#yes +~~END~~ + + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +WITH EqualCTE AS ( SELECT ID, PointColumn.STEquals(@referencePoint) AS Equality FROM TestSpatialFunction_YourTableTemp) +SELECT * FROM EqualCTE WHERE Equality = 1 ORDER BY Equality; +go +~~START~~ +int#!#bit +~~END~~ + + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +WITH EqualCTE AS ( SELECT ID, PointColumn.STEquals(@referencePoint) AS Equal FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STX) +SELECT * FROM EqualCTE WHERE Equal = 1.0 ORDER BY Equal; +GO +~~START~~ +int#!#bit +~~END~~ + + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +WITH EqualCTE AS ( SELECT ID, @referencePoint.STEquals(PointColumn) AS Equal FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STX) +SELECT * FROM EqualCTE WHERE Equal != 1.0 ORDER BY Equal; +GO +~~START~~ +int#!#bit +1#!#0 +2#!#0 +~~END~~ + + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +DECLARE @isEqual BIT = 1; +SELECT ID, PointColumn.STEquals(@referencePoint) AS EqualityReferencePoint, +CASE WHEN PointColumn.STEquals(@referencePoint) = @isEqual THEN 'Close' +ELSE 'Far' +END AS Proximity +FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STX; +go +~~START~~ +int#!#bit#!#text +1#!#0#!#Far +3#!##!#Far +2#!#0#!#Far +~~END~~ + + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +SELECT ID, @referencePoint.STEquals(PointColumn) AS EqualityReferencePoint, +CASE WHEN @referencePoint.STEquals(PointColumn) = @referencePoint.STY THEN 'Close' +ELSE 'Far' +END AS Proximity +FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STX; +go +~~START~~ +int#!#bit#!#text +1#!#0#!#Close +3#!##!#Far +2#!#0#!#Close +~~END~~ + + +DECLARE @Ranges TABLE (MinDistance float, MaxDistance float); +INSERT INTO @Ranges VALUES (0, 5), (5, 10), (10, 15); +SELECT * FROM ( SELECT ID, +CASE WHEN PointColumn1.STEquals(PointColumn2) BETWEEN 0 AND 1 THEN 'yes' +ELSE 'no' +END AS Range +FROM TestSpatialFunction_YourTableTemp2 ORDER BY PointColumn1.STX +) AS Source +PIVOT ( COUNT(ID) FOR Range IN ([0-5], [5.1-10], [10.1-15], [15.1+])) AS PivotTable; +go +~~ROW COUNT: 3~~ + +~~START~~ +int#!#int#!#int#!#int +0#!#0#!#0#!#0 +~~END~~ + + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +SELECT ID, PointColumn.STEquals(@referencePoint) AS Equality FROM TestSpatialFunction_DB.dbo.TestSpatialFunction_YourTable1Temp ORDER BY PointColumn.STX; +go +~~START~~ +int#!#bit +1#!#0 +3#!# +2#!#0 +~~END~~ + + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +SELECT ID, PointColumn.STEquals(@referencePoint) AS Equal, +JSON_QUERY('{"Equal":' + CAST(PointColumn.STEquals(@referencePoint) AS NVARCHAR(MAX)) + '}') AS Json +FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STX; +go +~~START~~ +int#!#bit#!#nvarchar +1#!#0#!#{"Equal": 0} +3#!##!# +2#!#0#!#{"Equal": 0} +~~END~~ + + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +SELECT ID, @referencePoint.STEquals(PointColumn) AS Equal, +JSON_QUERY('{"Equal":' + CAST(@referencePoint.STEquals(PointColumn) AS NVARCHAR(MAX)) + '}') Json +FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STX; +go +~~START~~ +int#!#bit#!#nvarchar +1#!#0#!#{"Equal": 0} +3#!##!# +2#!#0#!#{"Equal": 0} +~~END~~ + + +SELECT [PointColumn1].STEquals([PointColumn2]) AS Equality FROM [TestSpatialFunction_YourTableTemp2] ORDER BY PointColumn1.STX; +go +~~START~~ +bit +1 +~~END~~ + + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +DECLARE @isEqual BIT = 1; +DECLARE @sql NVARCHAR(MAX); +DECLARE @params NVARCHAR(MAX); +SET @sql = N' +SELECT ID, PointColumn.STEquals(@referencePoint) AS EqualityReferencePoint, +CASE WHEN PointColumn.STEquals(@referencePoint) = @isEqual THEN ''Close'' +ELSE ''Far'' +END AS Proximity +FROM TestSpatialFunction_YourTableTemp +WHERE PointColumn.STEquals(@referencePoint) = @isEqual;'; +SET @params = N'@referencePoint geometry, @isEqual float'; +EXEC sp_executesql @sql, @params, @referencePoint, @isEqual; +go +~~START~~ +int#!#bit#!#text +~~END~~ + + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +SELECT PointColumn.STEquals(@referencePoint) AS Equality FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STX; +SELECT TestSpatialFunction_YourTableTemp.PointColumn.STEquals(@referencePoint) AS Equality FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STX; +SELECT dbo.TestSpatialFunction_YourTableTemp.PointColumn.STEquals(@referencePoint) AS Equality FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STX; +go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Remote procedure/function reference with 4-part object name is not currently supported in Babelfish)~~ + + +DECLARE @pnt geometry; +SET @pnt = geometry::STGeomFromText('POINT(-122.34900 47.65100)', 4326); +select geometry::Point(@pnt.STY, @pnt.STX, 4326).STEquals(@pnt) +go +~~START~~ +bit +0 +~~END~~ + + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +DECLARE @equal BIT = 1; +SELECT ROUND(PointColumn.STEquals(@referencePoint) / @equal, 0) * @equal AS Equalitygroup, +COUNT(*) AS PointCount +FROM TestSpatialFunction_YourTableTemp +GROUP BY ROUND(PointColumn.STEquals(@referencePoint) / @equal, 0) * @equal +ORDER BY Equalitygroup; +GO +~~START~~ +numeric#!#int +#!#1 +0#!#2 +~~END~~ + + +DECLARE @referencePoint geometry = geometry::Point(1.0, 0.0, 4326); +SELECT ROUND(PointColumn.STEquals(@referencePoint) / @referencePoint.STX, 0) * @referencePoint.STX AS Equalitygroup, +COUNT(*) AS PointCount +FROM TestSpatialFunction_YourTableTemp +GROUP BY ROUND(PointColumn.STEquals(@referencePoint) / @referencePoint.STX, 0) * @referencePoint.STX +ORDER BY Equalitygroup; +GO +~~START~~ +float#!#int +#!#1 +0.0#!#2 +~~END~~ + + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +SELECT ID, PointColumn1.STEquals(PointColumn2) AS equal, +cast(PointColumn1.STEquals(@referencePoint) as int) - LAG(PointColumn1.STEquals(PointColumn2)) OVER (ORDER BY ID) AS Equalitygroup +FROM TestSpatialFunction_YourTableTemp2 ORDER BY PointColumn1.STX; +GO +~~START~~ +int#!#bit#!#int +1#!#1#!# +~~END~~ + + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +SELECT ID, PointColumn.STEquals(@referencePoint) AS equal, +cast(@referencePoint.STContains(PointColumn) as int) - LAG(@referencePoint.STX) OVER (ORDER BY ID) AS Equalitygroup +FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STX; +GO +~~START~~ +int#!#bit#!#float +1#!#0#!# +3#!##!# +2#!#0#!#0.0 +~~END~~ + + +-- Verifying with precision +DECLARE @point1 geometry, @point2 geometry; +SET @point1 = geometry::STPointFromText('POINT(-122.354657658684900 47.658678768678100)', 4326); +SET @point2 = geometry::STPointFromText('POINT(-122.354657658684900 47.658678768678100)', 4326); +SELECT STContains(@point1, @point2); +go +~~START~~ +bit +1 +~~END~~ + + +DECLARE @point1 geography, @point2 geography; +SET @point1 = geography::STGeomFromText('POINT(-122.354657658684900 47.658678768678100)', 4326); +SET @point2 = geography::STGeomFromText('POINT(-122.354657658684900 47.658678768678100)', 4326); +SELECT @point1.STContains(@point2) AS isIN; +go +~~START~~ +bit +1 +~~END~~ + + +DECLARE @point1 geometry, @point2 geometry; +SET @point1 = geometry::STPointFromText('POINT(-122.354657658684900 47.658678768678100)', 4326); +SET @point2 = geometry::STPointFromText('POINT(-122.354657658684000 47.658678768678100)', 4326); +SELECT STContains(@point1, @point2); +go +~~START~~ +bit +0 +~~END~~ + + +DECLARE @point1 geometry, @point2 geometry; +SET @point1 = geometry::STPointFromText('POINT(-122.354657658684900 47.658678768678100)', 4326); +SET @point2 = geometry::STPointFromText('POINT(-122.354657658684900 47.658678768678100)', 4326); +SELECT @point1.STContains(@point2); +go +~~START~~ +bit +1 +~~END~~ + + +DECLARE @point1 geometry, @point2 geometry; +SET @point1 = geometry::STPointFromText('POINT(-122.354657658684900 47.658678768678100)', 4326); +SET @point2 = geometry::STPointFromText('POINT(-122.354657658684900 47.658678768678100)', 4326); +SELECT @point1 . STContains ( @point2 ); +Go +~~START~~ +bit +1 +~~END~~ + + +SELECT ID, PointColumn1.STContains(PointColumn2) AS contain FROM TestSpatialFunction_YourTableTemp2 ORDER BY PointColumn1.STX; +GO +~~START~~ +int#!#bit +1#!#1 +~~END~~ + + +DECLARE @point1 geometry = geometry::Point(1.0, 2.0, 4326); +SELECT ID, PointColumn1.STContains(@point1) AS contain FROM TestSpatialFunction_YourTableTemp2 ORDER BY PointColumn1.STX; +GO +~~START~~ +int#!#bit +1#!#0 +~~END~~ + + +DECLARE @point1 geometry = geometry::Point(1.0, 2.0, 4326); +SELECT ID, @point1.STContains(PointColumn2) AS contain FROM TestSpatialFunction_YourTableTemp2 ORDER BY PointColumn1.STX; +GO +~~START~~ +int#!#bit +1#!#0 +~~END~~ + + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +DECLARE @contain BIT = 1; +SELECT PointColumn.STAsText() FROM TestSpatialFunction_YourTableTemp WHERE PointColumn.STContains(@referencePoint) = @contain ORDER BY PointColumn.STX; +GO +~~START~~ +text +~~END~~ + + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +SELECT PointColumn.STAsText() FROM TestSpatialFunction_YourTableTemp WHERE @referencePoint.STContains(PointColumn) = @referencePoint.STX ORDER BY PointColumn.STX; +GO +~~START~~ +text +POINT(3 4) +POINT(5 6) +~~END~~ + + +SELECT ID, PointColumn1.STContains(PointColumn2) AS contain FROM TestSpatialFunction_YourTableTemp2 ORDER BY PointColumn1.STX; +go +~~START~~ +int#!#bit +1#!#1 +~~END~~ + + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +SELECT PointColumn.STAsText() FROM TestSpatialFunction_YourTableTemp WHERE PointColumn.STContains(@referencePoint) != @referencePoint.STX ORDER BY PointColumn.STX; +GO +~~START~~ +text +~~END~~ + + +SELECT PointA.STAsText(),PointB.STAsText() FROM TestSpatialFunction_TableATemp JOIN TestSpatialFunction_TableBTemp ON PointA.STContains(TestSpatialFunction_TableBTemp.PointB) = 1 ORDER BY TestSpatialFunction_TableBTemp.PointB.STX; +GO +~~START~~ +text#!#text +~~END~~ + + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +SELECT PointA.STAsText(),PointB.STAsText() FROM TestSpatialFunction_TableATemp JOIN TestSpatialFunction_TableBTemp ON @referencePoint.STContains(TestSpatialFunction_TableBTemp.PointB) = 1 ORDER BY TestSpatialFunction_TableBTemp.PointB.STX; +GO +~~START~~ +text#!#text +~~END~~ + + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +SELECT PointA.STAsText(),PointB.STAsText() FROM TestSpatialFunction_TableATemp JOIN TestSpatialFunction_TableBTemp ON PointA.STContains(@referencePoint) = 1 ORDER BY TestSpatialFunction_TableBTemp.PointB.STX; +GO +~~START~~ +text#!#text +~~END~~ + + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +SELECT PointA.STAsText(),PointB.STAsText() FROM TestSpatialFunction_TableATemp JOIN TestSpatialFunction_TableBTemp ON TestSpatialFunction_TableBTemp.PointB.STContains(@referencePoint) = 0 ORDER BY TestSpatialFunction_TableBTemp.PointB.STX; +GO +~~START~~ +text#!#text +POINT(1 2)#!#POINT(3 4) +~~END~~ + + +SELECT PointColumn1.STAsText() FROM TestSpatialFunction_YourTableTemp2 ORDER BY PointColumn1.STX; +GO +~~START~~ +text +POINT(3 4) +~~END~~ + + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +SELECT PointColumn.STAsText() FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STX; +GO +~~START~~ +text +POINT(3 4) +POINT(3 4) +POINT(5 6) +~~END~~ + + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +SELECT PointColumn.STAsText() FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STX; +GO +~~START~~ +text +POINT(3 4) +POINT(3 4) +POINT(5 6) +~~END~~ + + +DECLARE @contains BIT = 1 ; +SELECT ID, PointColumn1.STContains(PointColumn2) AS doContain, +CASE WHEN PointColumn1.STContains(PointColumn2) = @contains THEN 'Contains' ELSE 'Do_not_contain' +END AS Proximity +FROM TestSpatialFunction_YourTableTemp2 ORDER BY PointColumn1.STX; +GO +~~START~~ +int#!#bit#!#text +1#!#1#!#Contains +~~END~~ + + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +SELECT ID, PointColumn1.STContains(@referencePoint) AS contain, +CASE WHEN @referencePoint.STContains(PointColumn2) = @referencePoint.STX THEN 'Contains' ELSE 'Do_not_contain' +END AS Proximity +FROM TestSpatialFunction_YourTableTemp2 ORDER BY PointColumn1.STX; +GO +~~START~~ +int#!#bit#!#text +1#!#0#!#Contains +~~END~~ + + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +WITH CTE AS ( SELECT ID, PointColumn.STContains(@referencePoint) AS contain FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STX) +SELECT * FROM CTE WHERE contain = 1 ORDER BY contain; +GO +~~START~~ +int#!#bit +~~END~~ + + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +WITH CTE AS ( SELECT ID, @referencePoint.STContains(PointColumn) AS contain FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STX) +SELECT * FROM CTE WHERE contain = 1 ORDER BY contain; +GO +~~START~~ +int#!#bit +~~END~~ + + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +DECLARE @contains BIT = 1; +SELECT ID, PointColumn.STContains(@referencePoint) AS ReferencePoint, +CASE WHEN PointColumn.STContains(@referencePoint) = @contains THEN 'contain' +ELSE 'do_not_contain' +END AS Proximity +FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STX; +go +~~START~~ +int#!#bit#!#text +1#!#0#!#do_not_contain +3#!##!#do_not_contain +2#!#0#!#do_not_contain +~~END~~ + + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +SELECT ID, @referencePoint.STContains(PointColumn) AS ReferencePoint, +CASE WHEN @referencePoint.STContains(PointColumn) = @referencePoint.STY THEN 'contain' +ELSE 'do_not_contain' +END AS Proximity +FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STX; +go +~~START~~ +int#!#bit#!#text +1#!#0#!#contain +3#!##!#do_not_contain +2#!#0#!#contain +~~END~~ + + +DECLARE @Ranges TABLE (MinDistance float, MaxDistance float); +INSERT INTO @Ranges VALUES (0, 5), (5, 10), (10, 15); +SELECT * FROM ( SELECT ID, +CASE WHEN PointColumn1.STContains(PointColumn2) BETWEEN 0 AND 1 THEN 'contain' +ELSE 'do_not_contain' +END AS Range +FROM TestSpatialFunction_YourTableTemp2 ORDER BY PointColumn1.STX +) AS Source +PIVOT ( COUNT(ID) FOR Range IN ([0-5], [5.1-10], [10.1-15], [15.1+])) AS PivotTable; +go +~~ROW COUNT: 3~~ + +~~START~~ +int#!#int#!#int#!#int +0#!#0#!#0#!#0 +~~END~~ + + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +SELECT ID, PointColumn.STContains(@referencePoint) AS contain FROM TestSpatialFunction_DB.dbo.TestSpatialFunction_YourTable1Temp ORDER BY PointColumn.STX; +go +~~START~~ +int#!#bit +1#!#0 +3#!# +2#!#0 +~~END~~ + + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +SELECT ID, PointColumn.STContains(@referencePoint) AS contain, +JSON_QUERY('{"Contain":' + CAST(PointColumn.STContains(@referencePoint) AS NVARCHAR(MAX)) + '}') AS Json +FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STX; +go +~~START~~ +int#!#bit#!#nvarchar +1#!#0#!#{"Contain": 0} +3#!##!# +2#!#0#!#{"Contain": 0} +~~END~~ + + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +SELECT ID, @referencePoint.STContains(PointColumn) AS contain, +JSON_QUERY('{"Contain":' + CAST(@referencePoint.STContains(PointColumn) AS NVARCHAR(MAX)) + '}') Json +FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STX; +go +~~START~~ +int#!#bit#!#nvarchar +1#!#0#!#{"Contain": 0} +3#!##!# +2#!#0#!#{"Contain": 0} +~~END~~ + + +SELECT [PointColumn1].STContains([PointColumn2]) AS contain FROM [TestSpatialFunction_YourTableTemp2] ORDER BY PointColumn1.STX; +go +~~START~~ +bit +1 +~~END~~ + + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +DECLARE @contains BIT = 1; +DECLARE @sql NVARCHAR(MAX); +DECLARE @params NVARCHAR(MAX); +SET @sql = N' +SELECT ID, PointColumn.STContains(@referencePoint) AS EqualityReferencePoint, +CASE WHEN PointColumn.STContains(@referencePoint) = @contains THEN ''contains'' +ELSE ''do_not_contain'' +END AS Proximity +FROM TestSpatialFunction_YourTableTemp +WHERE PointColumn.STContains(@referencePoint) = @contains;'; +SET @params = N'@referencePoint geometry, @contains float'; +EXEC sp_executesql @sql, @params, @referencePoint, @contains; +go +~~START~~ +int#!#bit#!#text +~~END~~ + + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +SELECT PointColumn.STContains(@referencePoint) AS contain FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STX; +SELECT TestSpatialFunction_YourTableTemp.PointColumn.STContains(@referencePoint) AS contain FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STX; +SELECT dbo.TestSpatialFunction_YourTableTemp.PointColumn.STContains(@referencePoint) AS contain FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STX; +go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: Remote procedure/function reference with 4-part object name is not currently supported in Babelfish)~~ + + + +DECLARE @pnt geometry; +SET @pnt = geometry::STGeomFromText('POINT(-122.34900 47.65100)', 4326); +select geometry::Point(@pnt.STY, @pnt.STX, 4326).STContains(@pnt) +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +DECLARE @contains BIT = 1; +SELECT ROUND(PointColumn.STContains(@referencePoint) / @contains, 0) * @contains AS Grp, +COUNT(*) AS PointCount +FROM TestSpatialFunction_YourTableTemp +GROUP BY ROUND(PointColumn.STContains(@referencePoint) / @contains, 0) * @contains +ORDER BY Grp; +GO +~~START~~ +bit +0 +~~END~~ + +~~START~~ +numeric#!#int +#!#1 +0#!#2 +~~END~~ + + +DECLARE @referencePoint geometry = geometry::Point(1.0, 0.0, 4326); +SELECT ROUND(PointColumn.STContains(@referencePoint) / @referencePoint.STX, 0) * @referencePoint.STX AS GRP, +COUNT(*) AS PointCount +FROM TestSpatialFunction_YourTableTemp +GROUP BY ROUND(PointColumn.STContains(@referencePoint) / @referencePoint.STX, 0) * @referencePoint.STX +ORDER BY Grp; +GO +~~START~~ +float#!#int +#!#1 +0.0#!#2 +~~END~~ + + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +SELECT ID, PointColumn1.STContains(PointColumn2) AS contain, +cast(PointColumn1.STContains(@referencePoint) as int) - LAG(PointColumn1.STContains(PointColumn2)) OVER (ORDER BY ID) AS Difference +FROM TestSpatialFunction_YourTableTemp2 ORDER BY PointColumn1.STX; +GO +~~START~~ +int#!#bit#!#int +1#!#1#!# +~~END~~ + + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +SELECT ID, PointColumn.STContains(@referencePoint) AS contain, +cast(@referencePoint.STContains(PointColumn) as int) - LAG(@referencePoint.STX) OVER (ORDER BY ID) AS Difference +FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STX; +GO +~~START~~ +int#!#bit#!#float +1#!#0#!# +3#!##!# +2#!#0#!#0.0 +~~END~~ + + +DECLARE @point geometry; +SET @point = geometry::STPointFromText('POINT(-122.34900 47.65100)', 4326); +SELECT STArea(@point); +go +~~START~~ +float +0.0 +~~END~~ + + +DECLARE @point geography; +SET @point = geography::STPointFromText('POINT(-122.34900 47.65100)', 4326); +SELECT STArea(@point); +go +~~START~~ +float +0.0 +~~END~~ + + +DECLARE @point geometry; +SET @point = geometry::STPointFromText('POINT(-122.34900 47.65100)', 4326); +SELECT @point.STArea(); +Go +~~START~~ +float +0.0 +~~END~~ + + +DECLARE @point geography; +SET @point = geography::STPointFromText('POINT(-122.34900 47.65100)', 4326); +SELECT @point.STArea(); +Go +~~START~~ +float +0.0 +~~END~~ + + +DECLARE @point geometry; +SET @point = geometry::POINT(22.34900, -47.65100, 4326); +SELECT @point . STArea ( ); +Go +~~START~~ +float +0.0 +~~END~~ + + +DECLARE @point geography; +SET @point = geography::POINT(22.34900, -47.65100, 4326); +SELECT @point . STArea ( ); +Go +~~START~~ +float +0.0 +~~END~~ + + +SELECT location.STArea() from TestSpatialFunction_SPATIALPOINTGEOM_dttemp ORDER BY location.STX; +GO +~~START~~ +float +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +~~END~~ + + +SELECT location.STArea() from TestSpatialFunction_SPATIALPOINTGEOG_dttemp ORDER BY location.Lat; +GO +~~START~~ +float +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +~~END~~ + + +DECLARE @point geography; +SET @point = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); +SELECT STArea(@point); +SELECT @point.STArea(); +Go +~~START~~ +float +0.0 +~~END~~ + +~~START~~ +float +0.0 +~~END~~ + + +DECLARE @point geography; +SET @point = geography::Point(22.34900, -47.65100, 4326); +SELECT STArea(@point); +SELECT @point.STArea(); +Go +~~START~~ +float +0.0 +~~END~~ + +~~START~~ +float +0.0 +~~END~~ + + +DECLARE @point1 geometry, @point2 geometry, @point3 geometry; +SET @point1 = geometry::STPointFromText(null, 4326); +SET @point2 = geometry::STGeomFromText(null, 4326); +SET @point3 = geometry::Point(22.34900, -47.65100, 4326); +SELECT @point1.STEquals(@point2); +SELECT @point3.STEquals(@point2); +SELECT @point1.STEquals(@point3); +SELECT @point1.STContains(@point2); +SELECT @point3.STContains(@point2); +SELECT @point1.STContains(@point3); +go +~~START~~ +bit + +~~END~~ + +~~START~~ +bit + +~~END~~ + +~~START~~ +bit + +~~END~~ + +~~START~~ +bit + +~~END~~ + +~~START~~ +bit + +~~END~~ + +~~START~~ +bit + +~~END~~ + + +-- Negative test for Geospatial functions +DECLARE @point1 geometry, @point2 varchar(50), @point3 int; +SET @point1 = geometry::Point(22.34900, -47.65100, 4326); +SET @point2 = 'Test_String'; +SELECT @point1.STEquals(@point2); +SELECT @point1.STContains(@point2); +go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: parse error - invalid geometry)~~ + + +DECLARE @point1 geography, @point2 varchar(50), @point3 int; +SET @point1 = geography::Point(22.34900, -47.65100, 4326); +SET @point2 = 'Test_String'; +SELECT @point1.STEquals(@point2); +SELECT @point1.STContains(@point2); +go +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: parse error - invalid geometry)~~ + + +-- Null test for Geospatial functions +DECLARE @point1 geography, @point2 geography, @point3 geography; +SET @point1 = geography::STPointFromText(null, 4326); +SET @point2 = geography::STGeomFromText(null, 4326); +SET @point3 = geography::Point(22.34900, -47.65100, 4326); +SELECT @point1.STEquals(@point2); +SELECT @point3.STEquals(@point2); +SELECT @point1.STEquals(@point3); +SELECT @point1.STContains(@point2); +SELECT @point3.STContains(@point2); +SELECT @point1.STContains(@point3); +go +~~START~~ +bit + +~~END~~ + +~~START~~ +bit + +~~END~~ + +~~START~~ +bit + +~~END~~ + +~~START~~ +bit + +~~END~~ + +~~START~~ +bit + +~~END~~ + +~~START~~ +bit + +~~END~~ + + +DECLARE @g geometry; +SELECT @g.STArea(); +go +~~START~~ +float + +~~END~~ + + +SELECT location.STArea() from TestSpatialFunction_SPATIALPOINTGEOG_dttemp ORDER BY location.Lat; +GO +~~START~~ +float +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +0.0 +~~END~~ + + +-- Combining geometry and geography in a single query +DECLARE @point1 geometry, @point2 geography; +SET @point1 = geometry::STPointFromText('POINT(-122.354657658684900 47.658678768678100)', 4326); +SET @point2 = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); +SELECT @point1.STContains(@point2); +go +~~ERROR (Code: 206)~~ + +~~ERROR (Message: The function stcontains is found but cannot be used. Possibly due to datatype mismatch and implicit casting is not allowed.)~~ + + +DECLARE @point1 geometry, @point2 geography; +SET @point1 = geometry::STPointFromText('POINT(-122.354657658684900 47.658678768678100)', 4326); +SET @point2 = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); +SELECT @point2.STContains(@point1); +go +~~ERROR (Code: 206)~~ + +~~ERROR (Message: The function stcontains is found but cannot be used. Possibly due to datatype mismatch and implicit casting is not allowed.)~~ + + +DECLARE @point1 geometry, @point2 geography; +SET @point1 = geometry::STPointFromText('POINT(-122.354657658684900 47.658678768678100)', 4326); +SET @point2 = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); +SELECT @point1.STEquals(@point2); +go +~~ERROR (Code: 206)~~ + +~~ERROR (Message: The function stequals is found but cannot be used. Possibly due to datatype mismatch and implicit casting is not allowed.)~~ + + +DECLARE @point1 geometry, @point2 geography; +SET @point1 = geometry::STPointFromText('POINT(-122.354657658684900 47.658678768678100)', 4326); +SET @point2 = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); +SELECT @point2.STEquals(@point1); +go +~~ERROR (Code: 206)~~ + +~~ERROR (Message: The function stequals is found but cannot be used. Possibly due to datatype mismatch and implicit casting is not allowed.)~~ + + +DECLARE @point1 geometry, @point2 geometry; +SET @point1 = geometry::Point(22.34900, -47.65100, 4326); +SET @point2 = geometry::STGeomFromText('POINT(1 1)', 0); +SELECT @point1.STEquals(@point2); +go +~~START~~ +bit + +~~END~~ + + +DECLARE @point1 geometry, @point2 geometry; +SET @point1 = geometry::Point(22.34900, -47.65100, 4326); +SET @point2 = geometry::STGeomFromText('POINT(1 1)', 0); +SELECT @point1.STContains(@point2); +go +~~START~~ +bit + +~~END~~ + + +DECLARE @point1 geometry; +SET @point1 = geometry::Point(3.0, 4.0, 4326); +SELECT PointColumn.STAsText() from TestSpatialFunction_YourTableTemp where PointColumn <> @point1; +GO +~~START~~ +text +POINT(5 6) +POINT(3 4) +~~END~~ + + +DECLARE @point1 geometry; +SET @point1 = geometry::Point(3.0, 4.0, 4326); +SELECT PointColumn.STAsText() from TestSpatialFunction_YourTableTemp where PointColumn = @point1; +GO +~~START~~ +text +POINT(3 4) +~~END~~ + + +SELECT PointColumn.STSrid from TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STSrid; +GO +~~START~~ +int +0 +4326 +4326 +~~END~~ + + +SELECT [PointColumn].[STSrid] from TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STX; +GO +~~START~~ +int +4326 +0 +4326 +~~END~~ + + +SELECT location.STSrid from TestSpatialFunction_SPATIALPOINTGEOG_dttemp ORDER BY location.STSrid; +GO +~~START~~ +int +4326 +4326 +4326 +4326 +4326 +4326 +4326 +4326 +4326 +4326 +~~END~~ + + +SELECT [location].[STSrid] from TestSpatialFunction_SPATIALPOINTGEOG_dttemp ORDER BY location.Lat; +GO +~~START~~ +int +4326 +4326 +4326 +4326 +4326 +4326 +4326 +4326 +4326 +4326 +~~END~~ + + +DECLARE @point geometry; +SET @point = geometry::Point(1.0, 2.0, 4326); +SELECT @point.STSrid AS Srid; +GO +~~START~~ +int +4326 +~~END~~ + + +DECLARE @point geometry = geometry::Point(1.0, 2.0, 4326); +SELECT PointColumn.STSrid FROM TestSpatialFunction_YourTableTemp WHERE PointColumn.STSrid = @point.STSrid ORDER BY PointColumn.STSrid; +GO +~~START~~ +int +4326 +4326 +~~END~~ + + +DECLARE @point geography = geography::Point(1.0, 2.0, 4326); +SELECT location.STSrid FROM TestSpatialFunction_SPATIALPOINTGEOG_dttemp WHERE location.STSrid = @point.STSrid ORDER BY location.STSrid; +GO +~~START~~ +int +4326 +4326 +4326 +4326 +4326 +4326 +4326 +4326 +4326 +4326 +~~END~~ + + +SELECT * FROM TestSpatialFunction_TableATemp JOIN TestSpatialFunction_TableBTemp ON TestSpatialFunction_TableATemp.PointA.STSrid = TestSpatialFunction_TableBTemp.PointB.STSrid ORDER BY TestSpatialFunction_TableBTemp.PointB.STSrid; +GO +~~START~~ +int#!#geometry#!#int#!#geometry +1#!#E6100000010C000000000000F03F0000000000000040#!#1#!#E6100000010C00000000000008400000000000001040 +~~END~~ + + +DECLARE @point geometry = geometry::Point(1.0, 2.0, 4326); +SELECT * FROM TestSpatialFunction_TableATemp JOIN TestSpatialFunction_TableBTemp ON TestSpatialFunction_TableATemp.PointA.STSrid = @point.STSrid ORDER BY TestSpatialFunction_TableBTemp.PointB.STSrid; +GO +~~START~~ +int#!#geometry#!#int#!#geometry +1#!#E6100000010C000000000000F03F0000000000000040#!#1#!#E6100000010C00000000000008400000000000001040 +~~END~~ + + +SELECT PointColumn.STSrid FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STSrid; +GO +~~START~~ +int +0 +4326 +4326 +~~END~~ + + +DECLARE @point geometry = geometry::Point(1.0, 2.0, 4326); +SELECT PointColumn.STSrid FROM TestSpatialFunction_YourTableTemp ORDER BY @point.STSrid; +GO +~~START~~ +int +4326 +4326 +0 +~~END~~ + + +SELECT PointColumn.STSrid AS SRID FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STSrid; +GO +~~START~~ +int +0 +4326 +4326 +~~END~~ + + +SELECT TestSpatialFunction_YourTableTemp.PointColumn.STSrid AS SRID FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STSrid; +GO +~~START~~ +int +0 +4326 +4326 +~~END~~ + + +SELECT dbo.YourTable.PointColumn.STSrid AS SRID FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STSrid; +GO +~~ERROR (Code: 33557097)~~ + +~~ERROR (Message: The multi-part identifier "dbo.YourTable.PointColumn.STSrid" could not be bound.)~~ + + +SELECT ID, PointColumn.STSrid AS SRID, +JSON_QUERY('{"SRID":' + CAST(PointColumn.STSrid AS NVARCHAR(MAX)) + '}') AS SRIDJson +FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STSrid; +GO +~~START~~ +int#!#int#!#nvarchar +3#!#0#!#{"SRID": 0} +1#!#4326#!#{"SRID": 4326} +2#!#4326#!#{"SRID": 4326} +~~END~~ + + +SELECT TestSpatialFunction_YourTable1Temp.ID, TestSpatialFunction_YourTable1Temp.PointColumn.STSrid AS SRID +FROM TestSpatialFunction_DB.dbo.TestSpatialFunction_YourTable1Temp; +GO +~~START~~ +int#!#int +1#!#4326 +2#!#4326 +3#!#0 +~~END~~ + + +DECLARE @point geometry = geometry::Point(1.0, 2.0, 4326); +SELECT PointColumn.STSrid AS SRID, COUNT(*) AS PointCount +FROM TestSpatialFunction_YourTableTemp GROUP BY PointColumn.STSrid ORDER BY PointCount; +GO +~~START~~ +int#!#int +0#!#1 +4326#!#2 +~~END~~ + + +SELECT ID, PointColumn.STSrid AS XCoordinate, +CASE WHEN PointColumn.STSrid = 0 THEN 'Zero SRID' +ELSE 'Positive SRID' END AS SRID FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STSrid; +GO +~~START~~ +int#!#int#!#text +3#!#0#!#Zero SRID +1#!#4326#!#Positive SRID +2#!#4326#!#Positive SRID +~~END~~ + + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +UPDATE TestSpatialFunction_YourTableTemp SET PointColumn = @referencePoint +WHERE PointColumn.STSrid = @referencePoint.STSrid; +GO +~~ROW COUNT: 2~~ + + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +UPDATE TestSpatialFunction_YourTableTemp SET PointColumn = @referencePoint +WHERE PointColumn.STEquals(@referencePoint) != 1; +go + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +UPDATE TestSpatialFunction_YourTableTemp SET PointColumn = @referencePoint +WHERE @referencePoint.STEquals(PointColumn) = 1; +go +~~ROW COUNT: 2~~ + diff --git a/test/JDBC/expected/TestSpatialPoint-vu-verify.out b/test/JDBC/expected/TestSpatialPoint-vu-verify.out index 5bbfc7274b..7b6341fd07 100644 --- a/test/JDBC/expected/TestSpatialPoint-vu-verify.out +++ b/test/JDBC/expected/TestSpatialPoint-vu-verify.out @@ -85,7 +85,7 @@ float DECLARE @point geometry; -SET @point = geometry::POINT(22.34900, -47.65100, 4326); +SET @point = geometry::Point(22.34900, -47.65100, 4326); SELECT STX(@point); SELECT STY(@point); SELECT @point.STX; @@ -172,7 +172,7 @@ POINT(-122.349 47.651)#!#01010000007593180456965EC017D9CEF753D34740#!#0.0 DECLARE @point1 geometry, @point2 geometry, @point3 geometry; SET @point1 = geometry::STPointFromText(null, 4326); SET @point2 = geometry::STGeomFromText(null, 4326); -SET @point3 = geometry::POINT(22.34900, -47.65100, 4326); +SET @point3 = geometry::Point(22.34900, -47.65100, 4326); SELECT @point1.STX; SELECT @point1.STY; SELECT @point1.STAsText(); @@ -219,7 +219,7 @@ float -- Negative test for Geospatial functions DECLARE @point1 geometry, @point2 varchar(50), @point3 int; -SET @point1 = geometry::POINT(22.34900, -47.65100, 4326);; +SET @point1 = geometry::Point(22.34900, -47.65100, 4326);; SET @point2 = 'Test_String'; SELECT @point1.STDistance(@point2); Go @@ -1874,7 +1874,7 @@ POINT(-122.349 47.651) DECLARE @point geography; -SET @point = geography::POINT(22.34900, -47.65100, 4326); +SET @point = geography::Point(22.34900, -47.65100, 4326); SELECT STAsText(@point); SELECT @point.STAsText(); Go @@ -1918,7 +1918,7 @@ float DECLARE @point geography; -SET @point = geography::POINT(22.34900, -47.65100, 4326); +SET @point = geography::Point(22.34900, -47.65100, 4326); SELECT Long(@point); SELECT Lat(@point); SELECT @point.Long; @@ -2263,7 +2263,7 @@ POINT(-22.349 47.651) DECLARE @point1 geography, @point2 geography, @point3 geography; SET @point1 = geography::STPointFromText(null, 4326); SET @point2 = geography::STGeomFromText(null, 4326); -SET @point3 = geography::POINT(22.34900, -47.65100, 4326); +SET @point3 = geography::Point(22.34900, -47.65100, 4326); SELECT @point1.Long; SELECT @point1.Lat; SELECT @point1.STAsText(); @@ -2310,7 +2310,7 @@ float -- Negative test for Geospatial functions DECLARE @point1 geography, @point2 varchar(50), @point3 int; -SET @point1 = geography::POINT(22.34900, -47.65100, 4326); +SET @point1 = geography::Point(22.34900, -47.65100, 4326); SET @point2 = 'Test_String'; SELECT @point2.STDistance(@point1); Go diff --git a/test/JDBC/input/datatypes/Test-spatial-functions-vu-cleanup.txt b/test/JDBC/input/datatypes/Test-spatial-functions-vu-cleanup.txt new file mode 100644 index 0000000000..458cca9199 --- /dev/null +++ b/test/JDBC/input/datatypes/Test-spatial-functions-vu-cleanup.txt @@ -0,0 +1,35 @@ +USE TestSpatialFunction_DB + +DROP TABLE IF EXISTS TestSpatialFunction_YourTable1Temp + +USE MASTER + +DROP TABLE IF EXISTS TestSpatialFunction_YourTableTemp2 + +DROP TABLE IF EXISTS TestSpatialFunction_TableATemp + +DROP TABLE IF EXISTS TestSpatialFunction_TableBTemp + +DROP VIEW IF EXISTS TestSpatialFunction_ValFromGeomTemp + +DROP VIEW IF EXISTS TestSpatialFunction_TextFromGeogTemp + +DROP VIEW IF EXISTS TestSpatialFunction_point_equality1Temp + +DROP VIEW IF EXISTS TestSpatialFunction_isInTemp + +DROP VIEW IF EXISTS TestSpatialFunction_point_EqualityTemp + +DROP VIEW IF EXISTS TestSpatialFunction_point_inTemp + +DROP VIEW IF EXISTS TestSpatialFunction_SRIDFromGeom + +DROP VIEW IF EXISTS TestSpatialFunction_SRIDFromGeog + +DROP TABLE IF EXISTS TestSpatialFunction_SPATIALPOINTGEOM_dttemp + +DROP TABLE IF EXISTS TestSpatialFunction_SPATIALPOINTGEOG_dttemp + +DROP TABLE IF EXISTS TestSpatialFunction_YourTableTemp + +DROP DATABASE TestSpatialFunction_DB diff --git a/test/JDBC/input/datatypes/Test-spatial-functions-vu-prepare.txt b/test/JDBC/input/datatypes/Test-spatial-functions-vu-prepare.txt new file mode 100644 index 0000000000..be5b0af6f5 --- /dev/null +++ b/test/JDBC/input/datatypes/Test-spatial-functions-vu-prepare.txt @@ -0,0 +1,64 @@ +CREATE DATABASE TestSpatialFunction_DB; + +USE TestSpatialFunction_DB; + +CREATE TABLE TestSpatialFunction_YourTable1Temp ( ID INT PRIMARY KEY, PointColumn geometry ); +INSERT INTO TestSpatialFunction_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)); + +USE MASTER + +CREATE TABLE TestSpatialFunction_YourTableTemp ( ID INT PRIMARY KEY, PointColumn geometry ); + +INSERT INTO TestSpatialFunction_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)); + +CREATE TABLE TestSpatialFunction_YourTableTemp2 ( ID INT PRIMARY KEY, PointColumn1 geometry, PointColumn2 geometry ); +INSERT INTO TestSpatialFunction_YourTableTemp2 (ID, PointColumn1, PointColumn2) VALUES (1, geometry::Point(3.0, 4.0, 4326), geometry::Point(3.0, 4.0, 4326)); + +CREATE TABLE TestSpatialFunction_TableATemp (ID INT PRIMARY KEY, PointA geometry); +CREATE TABLE TestSpatialFunction_TableBTemp (ID INT PRIMARY KEY, PointB geometry); +INSERT INTO TestSpatialFunction_TableATemp (ID, PointA) VALUES (1, geometry::Point(1.0, 2.0, 4326)); +INSERT INTO TestSpatialFunction_TableBTemp (ID, PointB) VALUES (1, geometry::Point(3.0, 4.0, 4326)); + +CREATE TABLE TestSpatialFunction_SPATIALPOINTGEOG_dttemp (location geography); +INSERT INTO TestSpatialFunction_SPATIALPOINTGEOG_dttemp (location) VALUES ( geography::STGeomFromText('Point(47.65100 -22.34900)', 4326) ); +INSERT INTO TestSpatialFunction_SPATIALPOINTGEOG_dttemp (location) VALUES ( geography::STGeomFromText('Point(1.0 2.0)', 4326) ); +INSERT INTO TestSpatialFunction_SPATIALPOINTGEOG_dttemp (location) VALUES ( geography::STGeomFromText('Point(1.0 2.0)', 4326) ); +INSERT INTO TestSpatialFunction_SPATIALPOINTGEOG_dttemp (location) VALUES ( geography::STPointFromText('Point(1.0 2.0)', 4326) ); + +#Tests for Geography type Prepared Statements +prepst#!#INSERT INTO TestSpatialFunction_SPATIALPOINTGEOG_dttemp(location) values(@location) #!#GEOGRAPHY|-|location|-|Point(47.65100 -22.34900):4326 +prepst#!#exec#!#GEOGRAPHY|-|location|-|Point(1.0 2.0):4326 +prepst#!#exec#!#GEOGRAPHY|-|location|-|Point(-91.0 -35.0):4326 +prepst#!#exec#!#GEOGRAPHY|-|location|-|Point(290.345 45.1234):4326 +prepst#!#exec#!#GEOGRAPHY|-|location|-|Point(-120.345 45.1234):4326 +prepst#!#exec#!#GEOGRAPHY|-|location|-|Point(-720.345 45.1234):4326 + +CREATE TABLE TestSpatialFunction_SPATIALPOINTGEOM_dttemp (location geometry); +INSERT INTO TestSpatialFunction_SPATIALPOINTGEOM_dttemp (location) VALUES ( geometry::STGeomFromText('Point(47.65100 -22.34900)', 4326) ); +INSERT INTO TestSpatialFunction_SPATIALPOINTGEOM_dttemp (location) VALUES ( geometry::STGeomFromText('Point(1.0 2.0)', 4326) ); +INSERT INTO TestSpatialFunction_SPATIALPOINTGEOM_dttemp (location) VALUES ( geometry::STGeomFromText('Point(47.65100 -22.34900)', 0) ); +INSERT INTO TestSpatialFunction_SPATIALPOINTGEOM_dttemp (location) VALUES ( geometry::STPointFromText('Point(1.0 2.0)', 4326) ); +INSERT INTO TestSpatialFunction_SPATIALPOINTGEOM_dttemp (location) VALUES ( geometry::Point(47.65100, -22.34900, 4326) ); + +#Tests for Geometry type Prepared Statements +prepst#!#INSERT INTO TestSpatialFunction_SPATIALPOINTGEOM_dttemp(location) values(@location) #!#GEOMETRY|-|location|-|Point(47.65100 -22.34900):4326 +prepst#!#exec#!#GEOMETRY|-|location|-|Point(1.0 2.0):4326 +prepst#!#exec#!#GEOMETRY|-|location|-|Point(47.65100 -22.34900):0 +prepst#!#exec#!#GEOMETRY|-|location|-|Point(-91.0 -35.0):4326 +prepst#!#exec#!#GEOMETRY|-|location|-|Point(290.345 45.1234):4326 + +CREATE VIEW TestSpatialFunction_point_equality1Temp AS SELECT p1.location.STEquals(p2.location) AS equality FROM TestSpatialFunction_SPATIALPOINTGEOM_dttemp p1 CROSS JOIN TestSpatialFunction_SPATIALPOINTGEOM_dttemp p2; + +CREATE VIEW TestSpatialFunction_isInTemp AS SELECT p1.location.STContains(p2.location) AS isIN FROM TestSpatialFunction_SPATIALPOINTGEOM_dttemp p1 CROSS JOIN TestSpatialFunction_SPATIALPOINTGEOM_dttemp p2 ORDER BY p1.location.STX; + +CREATE VIEW TestSpatialFunction_ValFromGeomTemp AS SELECT location.STArea() FROM TestSpatialFunction_SPATIALPOINTGEOM_dttemp ORDER BY location.STX; + +CREATE VIEW TestSpatialFunction_TextFromGeogTemp AS SELECT location.STArea() AS Area FROM TestSpatialFunction_SPATIALPOINTGEOG_dttemp ORDER BY location.Lat; + +CREATE VIEW TestSpatialFunction_point_EqualityTemp AS SELECT p1.location.STEquals(p2.location) AS Equality FROM TestSpatialFunction_SPATIALPOINTGEOG_dttemp p1 CROSS JOIN TestSpatialFunction_SPATIALPOINTGEOG_dttemp p2 ORDER BY p1.location.Lat; + +CREATE VIEW TestSpatialFunction_point_inTemp AS SELECT p1.location.STContains(p2.location) AS isIn FROM TestSpatialFunction_SPATIALPOINTGEOG_dttemp p1 CROSS JOIN TestSpatialFunction_SPATIALPOINTGEOG_dttemp p2; + +CREATE VIEW TestSpatialFunction_SRIDFromGeom AS SELECT PointColumn.STSrid AS SRID FROM TestSpatialFunction_YourTableTemp; + +CREATE VIEW TestSpatialFunction_SRIDFromGeog AS SELECT location.STSrid AS Area FROM TestSpatialFunction_SPATIALPOINTGEOG_dttemp ORDER BY location.Lat; diff --git a/test/JDBC/input/datatypes/Test-spatial-functions-vu-verify.sql b/test/JDBC/input/datatypes/Test-spatial-functions-vu-verify.sql new file mode 100644 index 0000000000..82c9159b5a --- /dev/null +++ b/test/JDBC/input/datatypes/Test-spatial-functions-vu-verify.sql @@ -0,0 +1,663 @@ +DECLARE @point1 geometry, @point2 geometry; +SET @point1 = geometry::STPointFromText('POINT(-122.354657658684900 47.658678768678100)', 4326); +SET @point2 = geometry::STPointFromText('POINT(-122.354657658684900 47.658678768678100)', 4326); +SELECT @point1.STEquals(@point2) AS Equal; +go + +DECLARE @point1 geography, @point2 geography; +SET @point1 = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); +SET @point2 = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); +SELECT @point1.STEquals(@point2) AS Equal; +go + +DECLARE @point1 geography, @point2 geography; +SET @point1 = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); +SET @point2 = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); +SELECT @point1.STContains(@point2) AS isIN; +go + +DECLARE @point1 geometry, @point2 geometry; +SET @point1 = geometry::STPointFromText('POINT(-122.354657658684900 47.658678768678100)', 4326); +SET @point2 = geometry::STPointFromText('POINT(-122.354657658684900 47.658678768678100)', 0); +SELECT @point1.STEquals(@point2) AS Equal; +go + +DECLARE @point1 geography, @point2 geography; +SET @point1 = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); +SET @point2 = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); +SELECT @point1 . STEquals(@point2) AS Equal; +go + +DECLARE @point1 geography, @point2 geography; +SET @point1 = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); +SET @point2 = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); +SELECT @point1 . STContains(@point2) AS isIN; +go + +DECLARE @point1 geography; +SET @point1 = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); +SELECT @point1.STSrid; +Go + +-- Verifying with precision +DECLARE @point1 geometry, @point2 geometry; +SET @point1 = geometry::STPointFromText('POINT(-122.354657658684900 47.658678768678100)', 4326); +SET @point2 = geometry::STPointFromText('POINT(-122.354657658684900 47.658678768678100)', 4326); +SELECT STEquals(@point1, @point2); +go + +DECLARE @point1 geography, @point2 geography; +SET @point1 = geography::STGeomFromText('POINT(-122.354657658684900 47.658678768678100)', 4326); +SET @point2 = geography::STGeomFromText('POINT(-122.354657658684900 47.658678768678100)', 4326); +SELECT @point1.STEquals(@point2) AS Equal; +go + +DECLARE @point1 geometry, @point2 geometry; +SET @point1 = geometry::STPointFromText('POINT(-122.354657658684900 47.658678768678100)', 4326); +SET @point2 = geometry::STPointFromText('POINT(-122.354657658684000 47.658678768678100)', 4326); +SELECT STEquals(@point1, @point2); +go + +DECLARE @point1 geometry, @point2 geometry; +SET @point1 = geometry::STPointFromText('POINT(-122.354657658684900 47.658678768678100)', 4326); +SET @point2 = geometry::STPointFromText('POINT(-122.354657658684900 47.658678768678100)', 4326); +SELECT @point1 . STEquals ( @point2 ); +go + +SELECT PointColumn1.STEquals(PointColumn2) AS Equals FROM TestSpatialFunction_YourTableTemp2 ORDER BY PointColumn1.STX; +go + +DECLARE @point1 geometry = geometry::Point(1.0, 2.0, 4326); +SELECT PointColumn1.STEquals(@point1) AS Equals FROM TestSpatialFunction_YourTableTemp2 ORDER BY PointColumn1.STX; +go + +DECLARE @point1 geometry = geometry::Point(1.0, 2.0, 4326); +SELECT @point1.STEquals(PointColumn2) AS Equals FROM TestSpatialFunction_YourTableTemp2 ORDER BY PointColumn1.STX; +go + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +DECLARE @isEqual BIT = 0; +SELECT PointColumn.STSrid FROM TestSpatialFunction_YourTableTemp WHERE PointColumn.STEquals(@referencePoint) = @isEqual ORDER BY PointColumn.STSrid; +go + +SELECT ID, PointColumn1.STEquals(PointColumn2) AS Equal_points FROM TestSpatialFunction_YourTableTemp2 ORDER BY PointColumn1.STX; +go + +SELECT PointA.STAsText(),PointB.STAsText() FROM TestSpatialFunction_TableATemp JOIN TestSpatialFunction_TableBTemp ON PointA.STEquals(TestSpatialFunction_TableBTemp.PointB) != 1 ORDER BY PointA.STX; +go + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +SELECT PointA.STAsText(),PointB.STAsText() FROM TestSpatialFunction_TableATemp JOIN TestSpatialFunction_TableBTemp ON @referencePoint.STEquals(TestSpatialFunction_TableBTemp.PointB) = 1 ORDER BY PointA.STX; +go + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +SELECT PointA.STAsText(),PointB.STAsText() FROM TestSpatialFunction_TableATemp JOIN TestSpatialFunction_TableBTemp ON PointA.STEquals(@referencePoint) != 1 ORDER BY PointA.STX; +go + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +SELECT PointColumn.STSrid FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STSrid; +go + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +SELECT PointColumn.STSrid FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STSrid; +go + +SELECT PointColumn1.STAsText() FROM TestSpatialFunction_YourTableTemp2 ORDER BY PointColumn1.STX; +go + +DECLARE @isEqual BIT = 1; +SELECT ID, PointColumn1.STEquals(PointColumn2) AS isEqual, +CASE WHEN PointColumn1.STEquals(PointColumn2) = @isEqual THEN 'yes' ELSE 'no' +END AS isEqual +FROM TestSpatialFunction_YourTableTemp2 ORDER BY PointColumn1.STX; +go + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +WITH EqualCTE AS ( SELECT ID, PointColumn.STEquals(@referencePoint) AS Equality FROM TestSpatialFunction_YourTableTemp) +SELECT * FROM EqualCTE WHERE Equality = 1 ORDER BY Equality; +go + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +WITH EqualCTE AS ( SELECT ID, PointColumn.STEquals(@referencePoint) AS Equal FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STX) +SELECT * FROM EqualCTE WHERE Equal = 1.0 ORDER BY Equal; +GO + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +WITH EqualCTE AS ( SELECT ID, @referencePoint.STEquals(PointColumn) AS Equal FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STX) +SELECT * FROM EqualCTE WHERE Equal != 1.0 ORDER BY Equal; +GO + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +DECLARE @isEqual BIT = 1; +SELECT ID, PointColumn.STEquals(@referencePoint) AS EqualityReferencePoint, +CASE WHEN PointColumn.STEquals(@referencePoint) = @isEqual THEN 'Close' +ELSE 'Far' +END AS Proximity +FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STX; +go + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +SELECT ID, @referencePoint.STEquals(PointColumn) AS EqualityReferencePoint, +CASE WHEN @referencePoint.STEquals(PointColumn) = @referencePoint.STY THEN 'Close' +ELSE 'Far' +END AS Proximity +FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STX; +go + +DECLARE @Ranges TABLE (MinDistance float, MaxDistance float); +INSERT INTO @Ranges VALUES (0, 5), (5, 10), (10, 15); +SELECT * FROM ( SELECT ID, +CASE WHEN PointColumn1.STEquals(PointColumn2) BETWEEN 0 AND 1 THEN 'yes' +ELSE 'no' +END AS Range +FROM TestSpatialFunction_YourTableTemp2 ORDER BY PointColumn1.STX +) AS Source +PIVOT ( COUNT(ID) FOR Range IN ([0-5], [5.1-10], [10.1-15], [15.1+])) AS PivotTable; +go + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +SELECT ID, PointColumn.STEquals(@referencePoint) AS Equality FROM TestSpatialFunction_DB.dbo.TestSpatialFunction_YourTable1Temp ORDER BY PointColumn.STX; +go + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +SELECT ID, PointColumn.STEquals(@referencePoint) AS Equal, +JSON_QUERY('{"Equal":' + CAST(PointColumn.STEquals(@referencePoint) AS NVARCHAR(MAX)) + '}') AS Json +FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STX; +go + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +SELECT ID, @referencePoint.STEquals(PointColumn) AS Equal, +JSON_QUERY('{"Equal":' + CAST(@referencePoint.STEquals(PointColumn) AS NVARCHAR(MAX)) + '}') Json +FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STX; +go + +SELECT [PointColumn1].STEquals([PointColumn2]) AS Equality FROM [TestSpatialFunction_YourTableTemp2] ORDER BY PointColumn1.STX; +go + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +DECLARE @isEqual BIT = 1; +DECLARE @sql NVARCHAR(MAX); +DECLARE @params NVARCHAR(MAX); +SET @sql = N' +SELECT ID, PointColumn.STEquals(@referencePoint) AS EqualityReferencePoint, +CASE WHEN PointColumn.STEquals(@referencePoint) = @isEqual THEN ''Close'' +ELSE ''Far'' +END AS Proximity +FROM TestSpatialFunction_YourTableTemp +WHERE PointColumn.STEquals(@referencePoint) = @isEqual;'; +SET @params = N'@referencePoint geometry, @isEqual float'; +EXEC sp_executesql @sql, @params, @referencePoint, @isEqual; +go + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +SELECT PointColumn.STEquals(@referencePoint) AS Equality FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STX; +SELECT TestSpatialFunction_YourTableTemp.PointColumn.STEquals(@referencePoint) AS Equality FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STX; +SELECT dbo.TestSpatialFunction_YourTableTemp.PointColumn.STEquals(@referencePoint) AS Equality FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STX; +go + +DECLARE @pnt geometry; +SET @pnt = geometry::STGeomFromText('POINT(-122.34900 47.65100)', 4326); +select geometry::Point(@pnt.STY, @pnt.STX, 4326).STEquals(@pnt) +go + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +DECLARE @equal BIT = 1; +SELECT ROUND(PointColumn.STEquals(@referencePoint) / @equal, 0) * @equal AS Equalitygroup, +COUNT(*) AS PointCount +FROM TestSpatialFunction_YourTableTemp +GROUP BY ROUND(PointColumn.STEquals(@referencePoint) / @equal, 0) * @equal +ORDER BY Equalitygroup; +GO + +DECLARE @referencePoint geometry = geometry::Point(1.0, 0.0, 4326); +SELECT ROUND(PointColumn.STEquals(@referencePoint) / @referencePoint.STX, 0) * @referencePoint.STX AS Equalitygroup, +COUNT(*) AS PointCount +FROM TestSpatialFunction_YourTableTemp +GROUP BY ROUND(PointColumn.STEquals(@referencePoint) / @referencePoint.STX, 0) * @referencePoint.STX +ORDER BY Equalitygroup; +GO + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +SELECT ID, PointColumn1.STEquals(PointColumn2) AS equal, +cast(PointColumn1.STEquals(@referencePoint) as int) - LAG(PointColumn1.STEquals(PointColumn2)) OVER (ORDER BY ID) AS Equalitygroup +FROM TestSpatialFunction_YourTableTemp2 ORDER BY PointColumn1.STX; +GO + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +SELECT ID, PointColumn.STEquals(@referencePoint) AS equal, +cast(@referencePoint.STContains(PointColumn) as int) - LAG(@referencePoint.STX) OVER (ORDER BY ID) AS Equalitygroup +FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STX; +GO + +-- Verifying with precision +DECLARE @point1 geometry, @point2 geometry; +SET @point1 = geometry::STPointFromText('POINT(-122.354657658684900 47.658678768678100)', 4326); +SET @point2 = geometry::STPointFromText('POINT(-122.354657658684900 47.658678768678100)', 4326); +SELECT STContains(@point1, @point2); +go + +DECLARE @point1 geography, @point2 geography; +SET @point1 = geography::STGeomFromText('POINT(-122.354657658684900 47.658678768678100)', 4326); +SET @point2 = geography::STGeomFromText('POINT(-122.354657658684900 47.658678768678100)', 4326); +SELECT @point1.STContains(@point2) AS isIN; +go + +DECLARE @point1 geometry, @point2 geometry; +SET @point1 = geometry::STPointFromText('POINT(-122.354657658684900 47.658678768678100)', 4326); +SET @point2 = geometry::STPointFromText('POINT(-122.354657658684000 47.658678768678100)', 4326); +SELECT STContains(@point1, @point2); +go + +DECLARE @point1 geometry, @point2 geometry; +SET @point1 = geometry::STPointFromText('POINT(-122.354657658684900 47.658678768678100)', 4326); +SET @point2 = geometry::STPointFromText('POINT(-122.354657658684900 47.658678768678100)', 4326); +SELECT @point1.STContains(@point2); +go + +DECLARE @point1 geometry, @point2 geometry; +SET @point1 = geometry::STPointFromText('POINT(-122.354657658684900 47.658678768678100)', 4326); +SET @point2 = geometry::STPointFromText('POINT(-122.354657658684900 47.658678768678100)', 4326); +SELECT @point1 . STContains ( @point2 ); +Go + +SELECT ID, PointColumn1.STContains(PointColumn2) AS contain FROM TestSpatialFunction_YourTableTemp2 ORDER BY PointColumn1.STX; +GO + +DECLARE @point1 geometry = geometry::Point(1.0, 2.0, 4326); +SELECT ID, PointColumn1.STContains(@point1) AS contain FROM TestSpatialFunction_YourTableTemp2 ORDER BY PointColumn1.STX; +GO + +DECLARE @point1 geometry = geometry::Point(1.0, 2.0, 4326); +SELECT ID, @point1.STContains(PointColumn2) AS contain FROM TestSpatialFunction_YourTableTemp2 ORDER BY PointColumn1.STX; +GO + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +DECLARE @contain BIT = 1; +SELECT PointColumn.STAsText() FROM TestSpatialFunction_YourTableTemp WHERE PointColumn.STContains(@referencePoint) = @contain ORDER BY PointColumn.STX; +GO + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +SELECT PointColumn.STAsText() FROM TestSpatialFunction_YourTableTemp WHERE @referencePoint.STContains(PointColumn) = @referencePoint.STX ORDER BY PointColumn.STX; +GO + +SELECT ID, PointColumn1.STContains(PointColumn2) AS contain FROM TestSpatialFunction_YourTableTemp2 ORDER BY PointColumn1.STX; +go + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +SELECT PointColumn.STAsText() FROM TestSpatialFunction_YourTableTemp WHERE PointColumn.STContains(@referencePoint) != @referencePoint.STX ORDER BY PointColumn.STX; +GO + +SELECT PointA.STAsText(),PointB.STAsText() FROM TestSpatialFunction_TableATemp JOIN TestSpatialFunction_TableBTemp ON PointA.STContains(TestSpatialFunction_TableBTemp.PointB) = 1 ORDER BY TestSpatialFunction_TableBTemp.PointB.STX; +GO + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +SELECT PointA.STAsText(),PointB.STAsText() FROM TestSpatialFunction_TableATemp JOIN TestSpatialFunction_TableBTemp ON @referencePoint.STContains(TestSpatialFunction_TableBTemp.PointB) = 1 ORDER BY TestSpatialFunction_TableBTemp.PointB.STX; +GO + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +SELECT PointA.STAsText(),PointB.STAsText() FROM TestSpatialFunction_TableATemp JOIN TestSpatialFunction_TableBTemp ON PointA.STContains(@referencePoint) = 1 ORDER BY TestSpatialFunction_TableBTemp.PointB.STX; +GO + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +SELECT PointA.STAsText(),PointB.STAsText() FROM TestSpatialFunction_TableATemp JOIN TestSpatialFunction_TableBTemp ON TestSpatialFunction_TableBTemp.PointB.STContains(@referencePoint) = 0 ORDER BY TestSpatialFunction_TableBTemp.PointB.STX; +GO + +SELECT PointColumn1.STAsText() FROM TestSpatialFunction_YourTableTemp2 ORDER BY PointColumn1.STX; +GO + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +SELECT PointColumn.STAsText() FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STX; +GO + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +SELECT PointColumn.STAsText() FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STX; +GO + +DECLARE @contains BIT = 1 ; +SELECT ID, PointColumn1.STContains(PointColumn2) AS doContain, +CASE WHEN PointColumn1.STContains(PointColumn2) = @contains THEN 'Contains' ELSE 'Do_not_contain' +END AS Proximity +FROM TestSpatialFunction_YourTableTemp2 ORDER BY PointColumn1.STX; +GO + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +SELECT ID, PointColumn1.STContains(@referencePoint) AS contain, +CASE WHEN @referencePoint.STContains(PointColumn2) = @referencePoint.STX THEN 'Contains' ELSE 'Do_not_contain' +END AS Proximity +FROM TestSpatialFunction_YourTableTemp2 ORDER BY PointColumn1.STX; +GO + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +WITH CTE AS ( SELECT ID, PointColumn.STContains(@referencePoint) AS contain FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STX) +SELECT * FROM CTE WHERE contain = 1 ORDER BY contain; +GO + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +WITH CTE AS ( SELECT ID, @referencePoint.STContains(PointColumn) AS contain FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STX) +SELECT * FROM CTE WHERE contain = 1 ORDER BY contain; +GO + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +DECLARE @contains BIT = 1; +SELECT ID, PointColumn.STContains(@referencePoint) AS ReferencePoint, +CASE WHEN PointColumn.STContains(@referencePoint) = @contains THEN 'contain' +ELSE 'do_not_contain' +END AS Proximity +FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STX; +go + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +SELECT ID, @referencePoint.STContains(PointColumn) AS ReferencePoint, +CASE WHEN @referencePoint.STContains(PointColumn) = @referencePoint.STY THEN 'contain' +ELSE 'do_not_contain' +END AS Proximity +FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STX; +go + +DECLARE @Ranges TABLE (MinDistance float, MaxDistance float); +INSERT INTO @Ranges VALUES (0, 5), (5, 10), (10, 15); +SELECT * FROM ( SELECT ID, +CASE WHEN PointColumn1.STContains(PointColumn2) BETWEEN 0 AND 1 THEN 'contain' +ELSE 'do_not_contain' +END AS Range +FROM TestSpatialFunction_YourTableTemp2 ORDER BY PointColumn1.STX +) AS Source +PIVOT ( COUNT(ID) FOR Range IN ([0-5], [5.1-10], [10.1-15], [15.1+])) AS PivotTable; +go + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +SELECT ID, PointColumn.STContains(@referencePoint) AS contain FROM TestSpatialFunction_DB.dbo.TestSpatialFunction_YourTable1Temp ORDER BY PointColumn.STX; +go + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +SELECT ID, PointColumn.STContains(@referencePoint) AS contain, +JSON_QUERY('{"Contain":' + CAST(PointColumn.STContains(@referencePoint) AS NVARCHAR(MAX)) + '}') AS Json +FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STX; +go + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +SELECT ID, @referencePoint.STContains(PointColumn) AS contain, +JSON_QUERY('{"Contain":' + CAST(@referencePoint.STContains(PointColumn) AS NVARCHAR(MAX)) + '}') Json +FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STX; +go + +SELECT [PointColumn1].STContains([PointColumn2]) AS contain FROM [TestSpatialFunction_YourTableTemp2] ORDER BY PointColumn1.STX; +go + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +DECLARE @contains BIT = 1; +DECLARE @sql NVARCHAR(MAX); +DECLARE @params NVARCHAR(MAX); +SET @sql = N' +SELECT ID, PointColumn.STContains(@referencePoint) AS EqualityReferencePoint, +CASE WHEN PointColumn.STContains(@referencePoint) = @contains THEN ''contains'' +ELSE ''do_not_contain'' +END AS Proximity +FROM TestSpatialFunction_YourTableTemp +WHERE PointColumn.STContains(@referencePoint) = @contains;'; +SET @params = N'@referencePoint geometry, @contains float'; +EXEC sp_executesql @sql, @params, @referencePoint, @contains; +go + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +SELECT PointColumn.STContains(@referencePoint) AS contain FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STX; +SELECT TestSpatialFunction_YourTableTemp.PointColumn.STContains(@referencePoint) AS contain FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STX; +SELECT dbo.TestSpatialFunction_YourTableTemp.PointColumn.STContains(@referencePoint) AS contain FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STX; +go + +DECLARE @pnt geometry; +SET @pnt = geometry::STGeomFromText('POINT(-122.34900 47.65100)', 4326); +select geometry::Point(@pnt.STY, @pnt.STX, 4326).STContains(@pnt) + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +DECLARE @contains BIT = 1; +SELECT ROUND(PointColumn.STContains(@referencePoint) / @contains, 0) * @contains AS Grp, +COUNT(*) AS PointCount +FROM TestSpatialFunction_YourTableTemp +GROUP BY ROUND(PointColumn.STContains(@referencePoint) / @contains, 0) * @contains +ORDER BY Grp; +GO + +DECLARE @referencePoint geometry = geometry::Point(1.0, 0.0, 4326); +SELECT ROUND(PointColumn.STContains(@referencePoint) / @referencePoint.STX, 0) * @referencePoint.STX AS GRP, +COUNT(*) AS PointCount +FROM TestSpatialFunction_YourTableTemp +GROUP BY ROUND(PointColumn.STContains(@referencePoint) / @referencePoint.STX, 0) * @referencePoint.STX +ORDER BY Grp; +GO + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +SELECT ID, PointColumn1.STContains(PointColumn2) AS contain, +cast(PointColumn1.STContains(@referencePoint) as int) - LAG(PointColumn1.STContains(PointColumn2)) OVER (ORDER BY ID) AS Difference +FROM TestSpatialFunction_YourTableTemp2 ORDER BY PointColumn1.STX; +GO + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +SELECT ID, PointColumn.STContains(@referencePoint) AS contain, +cast(@referencePoint.STContains(PointColumn) as int) - LAG(@referencePoint.STX) OVER (ORDER BY ID) AS Difference +FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STX; +GO + +DECLARE @point geometry; +SET @point = geometry::STPointFromText('POINT(-122.34900 47.65100)', 4326); +SELECT STArea(@point); +go + +DECLARE @point geography; +SET @point = geography::STPointFromText('POINT(-122.34900 47.65100)', 4326); +SELECT STArea(@point); +go + +DECLARE @point geometry; +SET @point = geometry::STPointFromText('POINT(-122.34900 47.65100)', 4326); +SELECT @point.STArea(); +Go + +DECLARE @point geography; +SET @point = geography::STPointFromText('POINT(-122.34900 47.65100)', 4326); +SELECT @point.STArea(); +Go + +DECLARE @point geometry; +SET @point = geometry::POINT(22.34900, -47.65100, 4326); +SELECT @point . STArea ( ); +Go + +DECLARE @point geography; +SET @point = geography::POINT(22.34900, -47.65100, 4326); +SELECT @point . STArea ( ); +Go + +SELECT location.STArea() from TestSpatialFunction_SPATIALPOINTGEOM_dttemp ORDER BY location.STX; +GO + +SELECT location.STArea() from TestSpatialFunction_SPATIALPOINTGEOG_dttemp ORDER BY location.Lat; +GO + +DECLARE @point geography; +SET @point = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); +SELECT STArea(@point); +SELECT @point.STArea(); +Go + +DECLARE @point geography; +SET @point = geography::Point(22.34900, -47.65100, 4326); +SELECT STArea(@point); +SELECT @point.STArea(); +Go + +DECLARE @point1 geometry, @point2 geometry, @point3 geometry; +SET @point1 = geometry::STPointFromText(null, 4326); +SET @point2 = geometry::STGeomFromText(null, 4326); +SET @point3 = geometry::Point(22.34900, -47.65100, 4326); +SELECT @point1.STEquals(@point2); +SELECT @point3.STEquals(@point2); +SELECT @point1.STEquals(@point3); +SELECT @point1.STContains(@point2); +SELECT @point3.STContains(@point2); +SELECT @point1.STContains(@point3); +go + +-- Negative test for Geospatial functions +DECLARE @point1 geometry, @point2 varchar(50), @point3 int; +SET @point1 = geometry::Point(22.34900, -47.65100, 4326); +SET @point2 = 'Test_String'; +SELECT @point1.STEquals(@point2); +SELECT @point1.STContains(@point2); +go + +DECLARE @point1 geography, @point2 varchar(50), @point3 int; +SET @point1 = geography::Point(22.34900, -47.65100, 4326); +SET @point2 = 'Test_String'; +SELECT @point1.STEquals(@point2); +SELECT @point1.STContains(@point2); +go + +-- Null test for Geospatial functions +DECLARE @point1 geography, @point2 geography, @point3 geography; +SET @point1 = geography::STPointFromText(null, 4326); +SET @point2 = geography::STGeomFromText(null, 4326); +SET @point3 = geography::Point(22.34900, -47.65100, 4326); +SELECT @point1.STEquals(@point2); +SELECT @point3.STEquals(@point2); +SELECT @point1.STEquals(@point3); +SELECT @point1.STContains(@point2); +SELECT @point3.STContains(@point2); +SELECT @point1.STContains(@point3); +go + +DECLARE @g geometry; +SELECT @g.STArea(); +go + +SELECT location.STArea() from TestSpatialFunction_SPATIALPOINTGEOG_dttemp ORDER BY location.Lat; +GO + +-- Combining geometry and geography in a single query +DECLARE @point1 geometry, @point2 geography; +SET @point1 = geometry::STPointFromText('POINT(-122.354657658684900 47.658678768678100)', 4326); +SET @point2 = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); +SELECT @point1.STContains(@point2); +go + +DECLARE @point1 geometry, @point2 geography; +SET @point1 = geometry::STPointFromText('POINT(-122.354657658684900 47.658678768678100)', 4326); +SET @point2 = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); +SELECT @point2.STContains(@point1); +go + +DECLARE @point1 geometry, @point2 geography; +SET @point1 = geometry::STPointFromText('POINT(-122.354657658684900 47.658678768678100)', 4326); +SET @point2 = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); +SELECT @point1.STEquals(@point2); +go + +DECLARE @point1 geometry, @point2 geography; +SET @point1 = geometry::STPointFromText('POINT(-122.354657658684900 47.658678768678100)', 4326); +SET @point2 = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); +SELECT @point2.STEquals(@point1); +go + +DECLARE @point1 geometry, @point2 geometry; +SET @point1 = geometry::Point(22.34900, -47.65100, 4326); +SET @point2 = geometry::STGeomFromText('POINT(1 1)', 0); +SELECT @point1.STEquals(@point2); +go + +DECLARE @point1 geometry, @point2 geometry; +SET @point1 = geometry::Point(22.34900, -47.65100, 4326); +SET @point2 = geometry::STGeomFromText('POINT(1 1)', 0); +SELECT @point1.STContains(@point2); +go + +DECLARE @point1 geometry; +SET @point1 = geometry::Point(3.0, 4.0, 4326); +SELECT PointColumn.STAsText() from TestSpatialFunction_YourTableTemp where PointColumn <> @point1; +GO + +DECLARE @point1 geometry; +SET @point1 = geometry::Point(3.0, 4.0, 4326); +SELECT PointColumn.STAsText() from TestSpatialFunction_YourTableTemp where PointColumn = @point1; +GO + +SELECT PointColumn.STSrid from TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STSrid; +GO + +SELECT [PointColumn].[STSrid] from TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STX; +GO + +SELECT location.STSrid from TestSpatialFunction_SPATIALPOINTGEOG_dttemp ORDER BY location.STSrid; +GO + +SELECT [location].[STSrid] from TestSpatialFunction_SPATIALPOINTGEOG_dttemp ORDER BY location.Lat; +GO + +DECLARE @point geometry; +SET @point = geometry::Point(1.0, 2.0, 4326); +SELECT @point.STSrid AS Srid; +GO + +DECLARE @point geometry = geometry::Point(1.0, 2.0, 4326); +SELECT PointColumn.STSrid FROM TestSpatialFunction_YourTableTemp WHERE PointColumn.STSrid = @point.STSrid ORDER BY PointColumn.STSrid; +GO + +DECLARE @point geography = geography::Point(1.0, 2.0, 4326); +SELECT location.STSrid FROM TestSpatialFunction_SPATIALPOINTGEOG_dttemp WHERE location.STSrid = @point.STSrid ORDER BY location.STSrid; +GO + +SELECT * FROM TestSpatialFunction_TableATemp JOIN TestSpatialFunction_TableBTemp ON TestSpatialFunction_TableATemp.PointA.STSrid = TestSpatialFunction_TableBTemp.PointB.STSrid ORDER BY TestSpatialFunction_TableBTemp.PointB.STSrid; +GO + +DECLARE @point geometry = geometry::Point(1.0, 2.0, 4326); +SELECT * FROM TestSpatialFunction_TableATemp JOIN TestSpatialFunction_TableBTemp ON TestSpatialFunction_TableATemp.PointA.STSrid = @point.STSrid ORDER BY TestSpatialFunction_TableBTemp.PointB.STSrid; +GO + +SELECT PointColumn.STSrid FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STSrid; +GO + +DECLARE @point geometry = geometry::Point(1.0, 2.0, 4326); +SELECT PointColumn.STSrid FROM TestSpatialFunction_YourTableTemp ORDER BY @point.STSrid; +GO + +SELECT PointColumn.STSrid AS SRID FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STSrid; +GO + +SELECT TestSpatialFunction_YourTableTemp.PointColumn.STSrid AS SRID FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STSrid; +GO + +SELECT dbo.YourTable.PointColumn.STSrid AS SRID FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STSrid; +GO + +SELECT ID, PointColumn.STSrid AS SRID, +JSON_QUERY('{"SRID":' + CAST(PointColumn.STSrid AS NVARCHAR(MAX)) + '}') AS SRIDJson +FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STSrid; +GO + +SELECT TestSpatialFunction_YourTable1Temp.ID, TestSpatialFunction_YourTable1Temp.PointColumn.STSrid AS SRID +FROM TestSpatialFunction_DB.dbo.TestSpatialFunction_YourTable1Temp; +GO + +DECLARE @point geometry = geometry::Point(1.0, 2.0, 4326); +SELECT PointColumn.STSrid AS SRID, COUNT(*) AS PointCount +FROM TestSpatialFunction_YourTableTemp GROUP BY PointColumn.STSrid ORDER BY PointCount; +GO + +SELECT ID, PointColumn.STSrid AS XCoordinate, +CASE WHEN PointColumn.STSrid = 0 THEN 'Zero SRID' +ELSE 'Positive SRID' END AS SRID FROM TestSpatialFunction_YourTableTemp ORDER BY PointColumn.STSrid; +GO + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +UPDATE TestSpatialFunction_YourTableTemp SET PointColumn = @referencePoint +WHERE PointColumn.STSrid = @referencePoint.STSrid; +GO + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +UPDATE TestSpatialFunction_YourTableTemp SET PointColumn = @referencePoint +WHERE PointColumn.STEquals(@referencePoint) != 1; +go + +DECLARE @referencePoint geometry = geometry::Point(0.0, 0.0, 4326); +UPDATE TestSpatialFunction_YourTableTemp SET PointColumn = @referencePoint +WHERE @referencePoint.STEquals(PointColumn) = 1; +go diff --git a/test/JDBC/input/datatypes/TestSpatialPoint-vu-verify.sql b/test/JDBC/input/datatypes/TestSpatialPoint-vu-verify.sql index 653a2d7434..00f0505c14 100644 --- a/test/JDBC/input/datatypes/TestSpatialPoint-vu-verify.sql +++ b/test/JDBC/input/datatypes/TestSpatialPoint-vu-verify.sql @@ -30,7 +30,7 @@ SELECT @point.STY; Go DECLARE @point geometry; -SET @point = geometry::POINT(22.34900, -47.65100, 4326); +SET @point = geometry::Point(22.34900, -47.65100, 4326); SELECT STX(@point); SELECT STY(@point); SELECT @point.STX; @@ -65,7 +65,7 @@ go DECLARE @point1 geometry, @point2 geometry, @point3 geometry; SET @point1 = geometry::STPointFromText(null, 4326); SET @point2 = geometry::STGeomFromText(null, 4326); -SET @point3 = geometry::POINT(22.34900, -47.65100, 4326); +SET @point3 = geometry::Point(22.34900, -47.65100, 4326); SELECT @point1.STX; SELECT @point1.STY; SELECT @point1.STAsText(); @@ -77,7 +77,7 @@ Go -- Negative test for Geospatial functions DECLARE @point1 geometry, @point2 varchar(50), @point3 int; -SET @point1 = geometry::POINT(22.34900, -47.65100, 4326);; +SET @point1 = geometry::Point(22.34900, -47.65100, 4326);; SET @point2 = 'Test_String'; SELECT @point1.STDistance(@point2); Go @@ -669,7 +669,7 @@ SELECT @point.STAsText(); Go DECLARE @point geography; -SET @point = geography::POINT(22.34900, -47.65100, 4326); +SET @point = geography::Point(22.34900, -47.65100, 4326); SELECT STAsText(@point); SELECT @point.STAsText(); Go @@ -683,7 +683,7 @@ SELECT @point.Lat; Go DECLARE @point geography; -SET @point = geography::POINT(22.34900, -47.65100, 4326); +SET @point = geography::Point(22.34900, -47.65100, 4326); SELECT Long(@point); SELECT Lat(@point); SELECT @point.Long; @@ -759,7 +759,7 @@ go DECLARE @point1 geography, @point2 geography, @point3 geography; SET @point1 = geography::STPointFromText(null, 4326); SET @point2 = geography::STGeomFromText(null, 4326); -SET @point3 = geography::POINT(22.34900, -47.65100, 4326); +SET @point3 = geography::Point(22.34900, -47.65100, 4326); SELECT @point1.Long; SELECT @point1.Lat; SELECT @point1.STAsText(); @@ -771,7 +771,7 @@ Go -- Negative test for Geospatial functions DECLARE @point1 geography, @point2 varchar(50), @point3 int; -SET @point1 = geography::POINT(22.34900, -47.65100, 4326); +SET @point1 = geography::Point(22.34900, -47.65100, 4326); SET @point2 = 'Test_String'; SELECT @point2.STDistance(@point1); Go diff --git a/test/JDBC/upgrade/latest/schedule b/test/JDBC/upgrade/latest/schedule index 5a9099ff31..0d20a517f9 100644 --- a/test/JDBC/upgrade/latest/schedule +++ b/test/JDBC/upgrade/latest/schedule @@ -436,6 +436,7 @@ TestSmallDatetime TestSmallInt TestSmallMoney TestSpatialPoint +Test-spatial-functions Test-sp_addrole Test-sp_addrolemember Test-sp_babelfish_volatility diff --git a/test/python/expected/upgrade_validation/expected_dependency.out b/test/python/expected/upgrade_validation/expected_dependency.out index 6b9f84a1cb..a9484db2d8 100644 --- a/test/python/expected/upgrade_validation/expected_dependency.out +++ b/test/python/expected/upgrade_validation/expected_dependency.out @@ -671,7 +671,11 @@ Function sys.st_zmflag(sys.geography) Function sys.st_zmflag(sys.geometry) Function sys.stasbinary_helper(sys.geography) Function sys.stastext_helper(sys.geography) +Function sys.stcontains_helper(sys.geography,sys.geography) +Function sys.stcontains_helper(sys.geometry,sys.geometry) Function sys.stdistance_helper(sys.geography,sys.geography) +Function sys.stequals_helper(sys.geography,sys.geography) +Function sys.stequals_helper(sys.geometry,sys.geometry) Function sys.stgeogfromtext_helper(text,integer) Function sys.stgeomfromtext_helper(text,integer) Function sys.string_escape(sys.nvarchar,text)