Skip to main content

MS SQL Server 2008 - Stored Procedure for Getting X meter radious of spacial data from a point

Stored Procedure to find data for x meter radious from a point using SQL Server geography data.

Create Procedure GetXMeterRadiousData
(
 @RadiousInMeter INT=0,
 @Point GEOGRAPHY=NULL,
 @Mode VARCHAR(10)='DISTANCE'
)
AS
BEGIN
DECLARE @g geography
IF (@Mode='DISTANCE')
  -- Using Distance method
     BEGIN
 -- Get the point
            SELECT @g = geo FROM SpacialDataTable
            WHERE geo = @Point
            -- Get the results, radius @RadiousInMeter
           SELECT * FROM SpacialDataTable
           WHERE @g.STDistance(geo) <= @RadiousInMeter
   
     END
ELSE
  -- Using INTERSECTS method
      BEGIN
 -- Get the center buffer, @RadiousInMeter radius
 SELECT @g = geo.STBuffer(@RadiousInMeter) FROM SpacialDataTable
 WHERE geo = @Point
 -- Get the results within the buffer
 SELECT * FROM SpacialDataTable WHERE @g.STIntersects(geo) = 1
      END
END

Comments

Popular posts from this blog

Mapping .NET Data Types to MySQL Data Types

Mapping .NET Data Types to MySQL Data Types .NET Data Types MySQL Data Types System.Boolean boolean, bit(1) System.Byte tinyint unsigned System.Byte[] binary, varbinary, blob, longblob System.DateTime datetime System.Decimal decimal System.Double double System.Guid char(36) System.Int16 smallint System.Int32 int System.Int64 bigint System.SByte tinyint System.Single float System.String char, varchar, text, longtext System.TimeSpan time DateTimeOffset type is not supported.

C# - How to get Property Name and Value of a dynamic object?

C# - Dynamic Object Use the following code to get Name and Value of a dynamic object's property. dynamic d = new { Property1= "Value1", Property2= "Value2"}; var properties = d.GetType().GetProperties(); foreach (var property in properties) {     var PropertyName= property.Name; //You get "Property1" as a result     var PropetyValue= d.GetType().GetProperty(property.Name).GetValue(d, null); //You get "Value1" as a result // you can use the PropertyName and Value here  }

How to Install redis6 on Amazon Linux 2023?

How to Install Redis6 on Amazon Linux 2023? Redis is an open-source, in-memory data structure store used as a database, cache, and message broker. In this guide, we'll walk you through the steps to install Redis 6 on Amazon Linux 2023. Prerequisites Before you start, make sure you have: An instance of Amazon Linux 2023 running. Sudo or root access on your instance. Step 1: Update Your System First, ensure your system is up to date by running the following commands: sudo dnf update -y sudo dnf upgrade -y Step 2: Install Redis Next, we'll install Redis6 using the Amazon Linux 2023 package repository. Run the following command to install Redis: sudo dnf install redis6 -y Step 3: Start and Enable Redis After installing Redis6, you need to start the Redis6 service and enable it to start on boot: sudo systemctl start redis6 sudo s...