Has anyone worked how to do geospatial queries in SQL Server? In particular, I'm interested in Geo Joins between point data (addresses). A Geo Polygons. (Counties and the Like)
The idea is to be able to do a join where you can tell by Lat and Lon if a particular address is in a particular county, or school district, or political jurisdiction.
Anyone having info please reach out. I'd like to learn from you. We have a reporting situation that could really benefit from such an approach.
Thanks.
--Tom
Hi Tom -
There's a decent tip here that explains how to find the nearest neighbor, which I hope might get you started: docs.microsoft.com/.../query-spatial-data-for-nearest-neighbor
Here's the query I worked out on our Tessitura system. We don't have much of anything in the 'geo_location' field but if you do, this might get you started as well. It finds the top 7 closest matches - I imagine you'll want to tinker with that.
USE [impresario]GO
DECLARE @g geography = 'POINT(-71.057083 42.361145)'; -- Boston MA coordinates
SELECT TOP(7) geo_location.ToString(), city FROM t_Address WHERE geo_location.STDistance(@g) IS NOT NULL ORDER BY geo_location.STDistance(@g);
Heather Sheridan (Past Member)
Cool! I'm actually interested in working with geography Points for addresses of schools. I can see putting this information in the T_Address.geo_location. Then I want to Join to geography polygons for counties and political districts.
It appears that SQL Server provides a .STWithin() function. I'm trying to figure out:
Thoughts?
Anyone else interested in working on these experiments with me?