Skip to content

Instantly share code, notes, and snippets.

@zapkub
Created May 1, 2019 05:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zapkub/3af90acb8e6da55db1262d6a8390cbe1 to your computer and use it in GitHub Desktop.
Save zapkub/3af90acb8e6da55db1262d6a8390cbe1 to your computer and use it in GitHub Desktop.
declare @p geography = geography::Point(10.5, 10.5, 4326);
SELECT *
FROM (
select Plant_ID,Plant_GeoLocation.STIsValid() as IsSTValid, Plant_GeoLocation.MakeValid().RingN(1).STDistance(@p) as Distance, Plant_GeoLocation as Geolocation from dbo.tb_opr_Plant
WHERE Plant_GeoLocation IS NOT NULL AND Plant_GeoLocation.STIsValid() = 1
) DistanceMeastureFromPoint
WHERE Distance < 1000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment