-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGenerateRandomCoordinatesWithinRadius.sql
More file actions
38 lines (30 loc) · 1.06 KB
/
Copy pathGenerateRandomCoordinatesWithinRadius.sql
File metadata and controls
38 lines (30 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
Purpose:
- Generate random latitude and longitude points around a central coordinate.
Customization:
- Replace the sample central coordinates, radius, and number of points before execution.
*/
-- Define the central point and search radius.
DECLARE @central_lat FLOAT = 0.0; -- Replace with the center latitude.
DECLARE @central_lon FLOAT = 0.0; -- Replace with the center longitude.
DECLARE @radius FLOAT = 0.01;
-- Create the table to store the generated points.
CREATE TABLE RandomCoordinates (
ID INT IDENTITY(1,1) PRIMARY KEY,
Latitude FLOAT,
Longitude FLOAT
);
-- Generate random latitude and longitude points within the radius.
DECLARE @i INT = 0;
DECLARE @num_points INT = 8000;
WHILE @i < @num_points
BEGIN
DECLARE @rand_lat FLOAT = (@central_lat + ((RAND() - 0.5) * 2 * @radius));
DECLARE @rand_lon FLOAT = (@central_lon + ((RAND() - 0.5) * 2 * @radius));
INSERT INTO RandomCoordinates (Latitude, Longitude)
VALUES (@rand_lat, @rand_lon);
SET @i = @i + 1;
END;
-- Review the generated coordinates.
SELECT *
FROM RandomCoordinates;