Max et Min X et Y des objets geo

Ces fonctions retournent la coordonnées max ou min en X ou en Y d’un objet géo composé de multiples points.

CREATE FUNCTION F_SPATIAL_MAX_X (@GEO GEOMETRY)
RETURNS FLOAT
AS
BEGIN
DECLARE @I INT, @MAX_X FLOAT, @P GEOMETRY;
SET @I = 1;
WHILE @I <= @GEO.STNumPoints()
BEGIN
   SET @P = @GEO.STPointN(@I);
   IF @MAX_X IS NULL
      SET @MAX_X = @P.STX
   ELSE    
      SET @MAX_X = CASE WHEN @MAX_X < @P.STX THEN @P.STX ELSE @MAX_X END;
   SET @I = @I + 1;
END;
RETURN @MAX_X;
END;
GO
CREATE FUNCTION F_SPATIAL_MIN_X (@GEO GEOMETRY)
RETURNS FLOAT
AS
BEGIN
DECLARE @I INT, @MAX_X FLOAT, @P GEOMETRY;
SET @I = 1;
WHILE @I <= @GEO.STNumPoints()
BEGIN
SET @P = @GEO.STPointN(@I);
IF @MAX_X IS NULL
SET @MAX_X = @P.STX
ELSE
SET @MAX_X = CASE WHEN @MAX_X > @P.STX THEN @P.STX ELSE @MAX_X END;
SET @I = @I + 1;
END;
RETURN @MAX_X;
END;
GO
CREATE FUNCTION F_SPATIAL_MAX_Y (@GEO GEOMETRY)
RETURNS FLOAT
AS
BEGIN
DECLARE @I INT, @MAX_Y FLOAT, @P GEOMETRY;
SET @I = 1;
WHILE @I <= @GEO.STNumPoints()
BEGIN
   SET @P = @GEO.STPointN(@I);
   IF @MAX_Y IS NULL
      SET @MAX_Y = @P.STY
   ELSE    
      SET @MAX_Y = CASE WHEN @MAX_Y < @P.STX THEN @P.STX ELSE @MAX_Y END;
   SET @I = @I + 1;
END;
RETURN @MAX_Y;
END;
GO
CREATE FUNCTION F_SPATIAL_MIN_Y (@GEO GEOMETRY)
RETURNS FLOAT
AS
BEGIN
DECLARE @I INT, @MAX_Y FLOAT, @P GEOMETRY;
SET @I = 1;
WHILE @I <= @GEO.STNumPoints()
BEGIN
SET @P = @GEO.STPointN(@I);
IF @MAX_Y IS NULL
SET @MAX_Y = @P.STY
ELSE
SET @MAX_Y = CASE WHEN @MAX_Y > @P.STY THEN @P.STX ELSE @MAX_Y END;
SET @I = @I + 1;
END;
RETURN @MAX_Y;
END;
GO

Laisser un commentaire