Skip to content

Instantly share code, notes, and snippets.

@caseywatson
Created June 25, 2013 22:25
Show Gist options
  • Select an option

  • Save caseywatson/5863028 to your computer and use it in GitHub Desktop.

Select an option

Save caseywatson/5863028 to your computer and use it in GitHub Desktop.
This code will generate random points given a min and max ID, min and max X coordinate and min and max Y coordinate using SQL geospatial data types.
DECLARE @min BIGINT = 9989
DECLARE @max BIGINT = 21899
DECLARE @minX FLOAT = -118.3876873
DECLARE @maxX FLOAT = -87.55091344
DECLARE @minY FLOAT = 30.195573
DECLARE @maxY FLOAT = 42.010291
WHILE (@min < @max) BEGIN
SET @min = (@min + 1)
INSERT INTO [DRN].[ScanLocation]
(ScanID, ScanGeo)
VALUES (@min, 'POINT(' + cast((((@maxX - @minX) * RAND()) + @minX) as NVARCHAR(15)) + ' ' + cast((((@maxY - @minY) * RAND()) + @minY) as NVARCHAR(15)) + ')')
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment