Joining tables using LAT/LONG

As Wim said, you need to first plot your polygon, then see if your other locations fall into that polygon.

using sql server
added the following long,lat for Brogo, New South Wales 2550, Australia
(10999999,'2019-04-01', 149.767249, -36.503551, '149.767249, -36.503551')

and it shows as intersecting. you would need to do some visual and data validations on your own though.

	DECLARE @BuildString NVARCHAR(MAX), @closepolygon NVARCHAR(MAX), @PolygonFromPoints geography ;

	select @BuildString=  COALESCE(@BuildString + ',', '') + CAST(a.Longitude AS NVARCHAR(50)) + ' ' + CAST(a.Latitude AS NVARCHAR(50)) 
	  from [SA3] a	  
	  order by code

	select top 1 @closepolygon = CAST(tak.Longitude AS NVARCHAR(50)) + ' ' + CAST(tak.Latitude AS NVARCHAR(50))
	  from [SA3] tak
	  order by code
	
	SET @BuildString = ' POLYGON((' + @BuildString + ', ' + @closepolygon + '))' 

	SET @PolygonFromPoints = geography::STPolyFromText(@BuildString, 4326);

	select @PolygonFromPoints
	
    ;with src
	as
	(
	 select geography::STGeomFromText('POINT(' + CAST([PLong] AS VARCHAR(20)) + ' ' + CAST(PLat AS VARCHAR(20)) + ')', 4326) as geoPoint, * 
	   from Tab1
    )
	select case geoPoint.STIntersects(@PolygonFromPoints)
	          when 0 then 'Does not Intersect'
			  else 'Intersects' end as Status ,* 
	  From src

Using google maps manually

1 Like